|
|
Home » U++ Library support » U++ SQL » How to close a sqlite session
How to close a sqlite session [message #45191] |
Sun, 27 September 2015 16:32  |
 |
forlano
Messages: 1207 Registered: March 2006 Location: Italy
|
Senior Contributor |
|
|
Hello,
after opening a sqlite db i need to close it and open a new one.
How to properly close the first db session?
I see the .Close() and .SessionClose() method.
Which one should I use? Are they different?
Thanks,
Luigi
EDIT: SessionClose() although visible is private. So remain Close().
However it seems my app does not close properly the session and after opening a new db it does not work as due.
[Updated on: Wed, 30 September 2015 20:47] Report message to a moderator
|
|
|
Re: How to close a sqlite session [message #45199 is a reply to message #45191] |
Wed, 30 September 2015 21:16   |
 |
forlano
Messages: 1207 Registered: March 2006 Location: Italy
|
Senior Contributor |
|
|
Hello,
sorry to bother you again with this topic.
Unfortunately I do not master Sql+sqlite and my application is experiencing a very weird behaviour. By sure it is my mistake and not a bug... but I do not know where to look.
Below is the code where the database is:
a) created if it does not exists;
b) read if it exists;
c) closed before to read a new database.
I am afraid it contains some logical error.
extern Sqlite3Session sqliteVT; // sqliteVT is defined as a global variable
void vegadb::SetDatabase(String dbname)
{ //close a database already opened
if (sqliteVT.IsOpen()) sqliteVT.Close();
if (!FileExists(dbname)) {
//create database
if(!sqliteVT.Open( dbname )) {
Exclamation("Can't create or open database file");
return;
}
SQL = sqliteVT;
sqliteVT.SetTrace();
SqlSchema sch(SQLITE3);
All_Tables(sch);
Sqlite3PerformScript(sch.Upgrade());
Sqlite3PerformScript(sch.Attributes());
}
else {
//read database
if(!sqliteVT.Open( dbname )) {
Exclamation("Can't open database file");
return;
}
SQL = sqliteVT;
sqliteVT.SetTrace();
}
SQL.ClearError();
}
This code (I just copied from other reference program) works perfectly as far as I read a database and continue to work with it until I close the program. If I close the program and start it again to work with a new database it continue to work fine.
The problem arise when I want to abandon the current database and read a new one.
Once I try to open the new database some table is read correctly but other tables seems not read properly. In fact the log file show, for example, the line
Preparing: SELECT * FROM PLAYERS WHERE TEAM_ID=? SQL* SELECT * FROM PLAYERS WHERE TEAM_ID=6 ERROR library routine called out of sequence(0)
Just for completeness I show how the PLAYERS table is read:
void vegadb::GetPlayersDBData()
{ VPlayer.Clear();
SQL.Execute("SELECT * FROM PLAYERS ORDER BY ID ASC, BOARD ASC");
while(SQL.Fetch()) {
Player& p = VPlayer.Add( (int) SQL[ID] );
p.player_id = (int) SQL[ID];
p.team_id = (int) SQL[TEAM_ID];
p.board = (int) SQL[BOARD];
p.name = (String) SQL[NAME];
p.codetitle = (String) SQL[CAT];
p.title = p.TitleToCode(); //convert string to number
p.federation = (String) SQL[FED];
p.data = (String) SQL[BDAY];
p.sex = (String) SQL[SEX];
p.idfide = (int) SQL[IDFIDE];
p.ratingfide = (int) SQL[RTGFIDE];
p.idnat = (String) SQL[IDNAT];
p.ratingnat = (int) SQL[RTGNAT];
p.kcoeff = (int) SQL[K];
}
}
I do not know where to look because the error appear only when I try to open the second database.
Thanks you very much for any suggestion.
Luigi
[Updated on: Wed, 30 September 2015 21:17] Report message to a moderator
|
|
|
|
|
Re: How to close a sqlite session [message #46006 is a reply to message #45191] |
Tue, 16 February 2016 00:26  |
wimpie
Messages: 46 Registered: March 2013 Location: holland
|
Member |
|
|
I've had the same problems. I'm curious why using global SQL would cause this.
For me it happened only on windows, VC9 if I remember correctly. compiling on Linux didn't seem to have the problem
|
|
|
Goto Forum:
Current Time: Sat Apr 26 14:27:28 CEST 2025
Total time taken to generate the page: 0.02843 seconds
|
|
|