logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Problems with SQLite and CREATE TABLE

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Database related
View previous topic :: View next topic  
Author Message
lostdreamz



Joined: 19 Nov 2006
Posts: 26

PostPosted: Mon Dec 04, 2006 20:46    Post subject: Problems with SQLite and CREATE TABLE Reply with quote

I am developing my NWN 2 PW based on NWNX4 with the Sqlite plugin while I wait for ODBC plugin. I had a few problems this weekend when trying to create the tables. I am using one table for each one of my campaign databases which works quite nicely. This is about 7 tables that I put into a script to create them.

Surprisingly some of the tables got created and others failed. I changed the order of tables and a few that failed succeeded. I thought it may have something to do with trying to do too many SQL statements all at once so I put a delay of 1 second between each create. Still the same tables failed. In the end I gave up and used SQLite3.exe to grenerate the tables which worked fine with exactly the same SQL which was failing.

Its not actually a problem for me as the tables did get created but it could cause problems for other people sending direct SQL statements via NWNX4.

Thanks

Rebecca Casidy - Owner World Of Desire PW.
Back to top
View user's profile Send private message
lostdreamz



Joined: 19 Nov 2006
Posts: 26

PostPosted: Mon Dec 04, 2006 20:49    Post subject: Reply with quote

Oh here is the script that failed

void CreateAndTest(string name, int exp=0)
{
SendMessageToPC(GetLastUsedBy(), "Creating Table "+name+" for SQLite...");
SQLExecDirect("CREATE TABLE "+name+" (" +
"player varchar(64) NOT NULL default '~'," +
"tag varchar(64) NOT NULL default '~'," +
"name varchar(64) NOT NULL default '~'," +
"val text," +
"expire int(11) default NULL," +
"last timestamp NOT NULL default current_timestamp," +
"PRIMARY KEY (player,tag,name)" +
")");
SetPersistentString(GetModule(),"test","test value",exp,name);
string testRet = GetPersistentString(GetModule(),"test",name);
if (testRet=="test value")
{
SendMessageToPC(GetLastUsedBy(), name+"test passed");
DeletePersistentVariable(GetModule(),"test",name);
}
else
SendMessageToPC(GetLastUsedBy(), name+" test failed");
}

void main()
{
DelayCommand(1.0,CreateAndTest("wod_messages"));
DelayCommand(2.0,CreateAndTest("wod_accounts"));
DelayCommand(3.0,CreateAndTest("wod_bounty"));
DelayCommand(4.0,CreateAndTest("wod_houses"));
DelayCommand(5.0,CreateAndTest("wod_bank"));
DelayCommand(6.0,CreateAndTest("wod_dbclear"));
DelayCommand(7.0,CreateAndTest("wod_mulaccounts"));
DelayCommand(8.0,CreateAndTest("wod_player"));
}
Back to top
View user's profile Send private message
Papillon
x-man


Joined: 28 Dec 2004
Posts: 1060
Location: Germany

PostPosted: Tue Dec 05, 2006 9:40    Post subject: Reply with quote

Thanks for reporting this. I could reproduce the problem... there will likely be a fix on Saturday.
_________________
Papillon
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Papillon
x-man


Joined: 28 Dec 2004
Posts: 1060
Location: Germany

PostPosted: Wed Dec 06, 2006 0:07    Post subject: Reply with quote

Nah, the fix comes today, this annoyed me no end.

So, the problem was three-fold:

1) The logfile did not report the actual error, which was something like "database table locked". The interface of SQLite is goofy at this point, so I had to code around this a little. The real error shows up now.

2) The error above was caused by the automatic transaction feature of the plugin. With SQLite, you can only create tables when there is no open transaction running, so you have to COMMIT before creating the tables.

3) The COMMIT in turn did not work (sigh!), because of a remaining open resultset. Due to the change how resultsets work now, there is always one open and you simply can't commit then. I extended the SQLite sources with a new code to denote this error and the plugin now tries to close the resultset when it sees that error.

Long story short - it works now:

Code:
SQLExecDirect("COMMIT");
CreateAndTestTable("wod_messages");
CreateAndTestTable("wod_accounts");
CreateAndTestTable("wod_bounty");
CreateAndTestTable("wod_houses");
CreateAndTestTable("wod_bank");
CreateAndTestTable("wod_dbclear");
CreateAndTestTable("wod_mulaccounts");
CreateAndTestTable("wod_player");
SQLExecDirect("BEGIN");


I've update the plugin in prototype 1.06 to version 0.0.2.
_________________
Papillon
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
lostdreamz



Joined: 19 Nov 2006
Posts: 26

PostPosted: Wed Dec 06, 2006 0:35    Post subject: Reply with quote

Thank you. You are awesome. I tried the commit as well as I thought it might be that but as I said gave up when it didnt work either. I will download the latest version. I love NWNX4.
Back to top
View user's profile Send private message
Quick_silver



Joined: 29 Dec 2006
Posts: 0

PostPosted: Fri Dec 29, 2006 18:26    Post subject: Reply with quote

This Code:
Code:
   void CreateAndTestTable(string name, int exp=0)
{
   SendMessageToPC(GetLastUsedBy(), "Creating Table "+name+" for SQLite...");
   SQLExecDirect("CREATE TABLE "+name+" (" +
   "player varchar(64) NOT NULL default '~'," +
   "tag varchar(64) NOT NULL default '~'," +
   "name varchar(64) NOT NULL default '~'," +
   "val text," +
   "expire int(11) default NULL," +
   "last timestamp NOT NULL default current_timestamp," +
   "PRIMARY KEY (player,tag,name)" +
   ")");
   SetPersistentString(GetModule(),"test","test value",exp,name);
   string testRet = GetPersistentString(GetModule(),"test",name);
   if (testRet=="test value")
   {
   SendMessageToPC(GetLastUsedBy(), name+"test passed");
   DeletePersistentVariable(GetModule(),"test",name);
   }
   else
   SendMessageToPC(GetLastUsedBy(), name+" test failed");
}

void main() {
   DelayCommand(1.0,CreateAndTestTable("wod_messages"));
   DelayCommand(2.0,CreateAndTestTable("wod_accounts"));
}

The first "CreateAndTestTable" works fine, the it generates this error:
Code:

(built using SQLite 3.3.8)

* SQLite database file is D:\Neverwinter Nights 2\servertest\nwnx4\data\sqlite.db
* Plugin initialized.
* Registering under function class SQL
! SQL Error: database table is locked (6)
! SQL Error: no such table: wod_accounts
! SQL Error: no such table: wod_accounts
! SQL Error: no such table: wod_accounts


I played arround with COMMIT and BEGIN but the error is still there.

Can someone help? How to unlock the database? Or why it is locked?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Database related All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group