Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to next message
forlano is currently offline  forlano
Messages: 1189
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 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1189
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 #45203 is a reply to message #45199] Fri, 02 October 2015 21:58 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1189
Registered: March 2006
Location: Italy
Senior Contributor
Hello,

after reading many posts, I tried to remove all instance of SQL in the code and now it seems to work as expected.
Mirek adviced to avoid SQL.Fetch() and I had several although they looked not dangerous. Anyway now they disappeared.

thanks,
luigi
Re: How to close a sqlite session [message #45208 is a reply to message #45203] Mon, 05 October 2015 18:57 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 681
Registered: November 2008
Location: France
Contributor
Hello Forlano,

I'm very far from being a DB expert but I have a quite big app in which I don't have SQLlite problems.

But I never use SQL ==> it's a global instance.
Instead I use a session variable : Sqlite3Session sqlite3;

Everywhere you used SQL use sqlite3 instead
Re: How to close a sqlite session [message #46006 is a reply to message #45191] Tue, 16 February 2016 00:26 Go to previous message
wimpie is currently offline  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
Previous Topic: MySql, boolean values and SqlArray
Next Topic: GUID column in DB and SqlArray
Goto Forum:
  


Current Time: Sat Jun 15 04:02:08 CEST 2024

Total time taken to generate the page: 0.02105 seconds