I am new to this myself and I started reworking my nwnx-based persistency using mysql onto this internal db in nwn ee.
Made a quick script for a testing purpose and it worked. Check this:
Script:
void main()
{
sqlquery sql = SqlPrepareQueryCampaign("arkhdb","CREATE TABLE `accdata` (`account` varchar(45) NOT NULL, `varname` varchar(45) NOT NULL, `value` varchar(45) DEFAULT NULL, PRIMARY KEY (`account`,`varname`));");
int retVal = SqlStep(sql);
WriteTimestampedLogEntry("query1 returned: "+IntToString(retVal));
sql = SqlPrepareQueryCampaign("arkhdb","INSERT INTO `accdata` VALUES (@player,@varname,@val);");
SqlBindString(sql,"@player","Aved");
SqlBindString(sql,"@varname","solditems");
SqlBindInt(sql,"@val",4);
retVal = SqlStep(sql);
WriteTimestampedLogEntry("query2 returned: "+IntToString(retVal));
sql = SqlPrepareQueryCampaign("arkhdb", "select account,value from accdata;");
while (SqlStep(sql))
{
WriteTimestampedLogEntry("print1 Value1: " + SqlGetString(sql, 0)+", Value2: "+ SqlGetString(sql, 1));
}
sql = SqlPrepareQueryCampaign("arkhdb","INSERT INTO `accdata` VALUES ('faxes','solditems','5');");
retVal = SqlStep(sql);
WriteTimestampedLogEntry("query3 returned: "+IntToString(retVal));
sql = SqlPrepareQueryCampaign("arkhdb","INSERT INTO `accdata` VALUES ('Linx','solditems','2'),('miniork2','solditems','2'),('moduka','solditems','1'),('****','solditems','1'),('****','solditems','1'),('****','solditems','5'),('****','solditems','1'),('****','solditems','13'),('****','solditems','5'),('****','solditems','9');");
retVal = SqlStep(sql);
WriteTimestampedLogEntry("query4 returned: "+IntToString(retVal));
sql = SqlPrepareQueryCampaign("arkhdb", "select account,value from accdata;");
while (SqlStep(sql))
{
WriteTimestampedLogEntry("print2 Value1: " + SqlGetString(sql, 0)+", Value2: "+ SqlGetString(sql, 1));
}
}
and result from log:
[Thu Jul 8 21:53:23] query1 returned: 0
[Thu Jul 8 21:53:23] query2 returned: 0
[Thu Jul 8 21:53:23] print1 Value1: Aved, Value2: 4
[Thu Jul 8 21:53:23] query3 returned: 0
[Thu Jul 8 21:53:23] query4 returned: 0
[Thu Jul 8 21:53:23] print2 Value1: Aved, Value2: 4
[Thu Jul 8 21:53:23] print2 Value1: faxes, Value2: 5
[Thu Jul 8 21:53:23] print2 Value1: Linx, Value2: 2
[Thu Jul 8 21:53:23] print2 Value1: miniork2, Value2: 2
[Thu Jul 8 21:53:23] print2 Value1: moduka, Value2: 1
[Thu Jul 8 21:53:23] print2 Value1: ****, Value2: 1
[Thu Jul 8 21:53:23] print2 Value1: ****, Value2: 1
[Thu Jul 8 21:53:23] print2 Value1: ****, Value2: 5
[Thu Jul 8 21:53:23] print2 Value1: ****, Value2: 1
[Thu Jul 8 21:53:23] print2 Value1: ****, Value2: 13
[Thu Jul 8 21:53:23] print2 Value1: ****, Value2: 5
[Thu Jul 8 21:53:23] print2 Value1: ****, Value2: 9
Note that **** were public CD keys of my players. I changed this to **** here for safety reasons. Otherwise that would be invalid query since each pair of account and varname can have only one value.
Anyway, so from this quick test I can tell that.
SqlStep cannot be used as an indicator if the query was executed without error. It will probably return TRUE only when it pulls some data rows.
Difference between SqlPrepareQueryCampaign and SqlPrepareQueryObject is that the object creates database for each object you use it at (verification required). While the campaign allows to manually select database name. In singleplayer the latter can be of a benefit as it allows to store player data thorough various single player modules. For a typical server, either use campaign and input the same value all the time like “mypwdatabase” or use object version on GetModule() as object parameter passed into it. I think I will create a wrappers so I can exclude the first parameter.
And lastly, SqlBind* function are not rreally needed. You can insert values into SQL statement manually. TBH I don’t see why would I want to use these functions at all, seems to be overly complicated compared to manually writing the values into SQL query as we are used to from nwnx. But maybe there is an use case, if I figure out I let you know.