On Classic I have it so that account data is added to an SQLite database on a player's first login, and if they have already logged in it is then updating the existing data.
For example:
PHP Code:
//Called within onActionPlayerOnline from Control-NPC
public function playerLoggedIn(temp.pl){
if(temp.pl.communityname == NULL){
temp.cn = temp.pl.account;
}
else{
temp.cn = temp.pl.communityname;
}
//The player does not have a flag for being added to the database
if(!temp.pl.stat_sqlsetup){
temp.query = "INSERT INTO tPlayer (account, subscription, lastlogin, gelats, communityname) VALUES ('" @ temp.pl.account @ "', '" @ temp.pl.getSubcription() @ "', " @ temp.pl.getLoginTime() @ ", " @ temp.pl.getGelat() @ ", '" @ temp.cn @ "')";
this.trigger("SQLCommit", temp.query, "PlayerStored", temp.pl);
}
else{
//The player does have a flag for being added to the database
temp.query = "UPDATE tPlayer SET subscription = '" @ temp.pl.getSubcription() @ "', lastlogin = " @ temp.pl.getLoginTime() @ ", gelats = " @ temp.pl.getGelat() @ ", communityname = '" @ temp.cn @ "' WHERE account = '" @ temp.pl.account @ "'";
this.trigger("SQLCommit", temp.query);
}
}
The class script containing "SQLCommit" is as follows:
PHP Code:
function onSQLCommit(temp.query, temp.triggername, temp.param1, temp.param2, temp.param3){
temp.request = requestsql(temp.query, true);
if(!temp.request.completed){
waitfor(temp.request, "onReceiveData", 5);
}
//If something goes wrong, such as a failed constraint, the query is logged and no function is triggered
if(temp.request.error != NULL){
savelog2("log_sql.txt", temp.request.error @ " : " @ temp.query);
echo(temp.request.error);
return;
}
if(temp.triggername != NULL){
this.trigger(temp.triggername, temp.request, temp.param1, temp.param2, temp.param3);
}
}
So in this case, assuming all goes well, this function would be triggered:
PHP Code:
function onPlayerStored(temp.r, temp.pl){
temp.pl.stat_sqlsetup = true;
}
The problem I am having is that a small portion of trial accounts are producing an error of "constraint failed", sometimes the problem is that they are added to the database but somehow the flag has not set. Other times the flag is set but they have not been added to the database, and so it fails whenever they are added to a different table containing their primary key of the first table.
As far as I can tell this seems to co-inside with Observer Mode.