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
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 previous message
forlano is currently offline  forlano
Messages: 1185
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

 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: MySql, boolean values and SqlArray
Next Topic: GUID column in DB and SqlArray
Goto Forum:
  


Current Time: Wed May 15 07:31:00 CEST 2024

Total time taken to generate the page: 0.02569 seconds