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 » Fix to Sqlite3Session::Open
Fix to Sqlite3Session::Open [message #19915] Sun, 01 February 2009 19:18 Go to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
Explanation.

sqlite3_open initializes database argument even if it cannot open database. So, it is incorrect to use NULL == db to check whether database was opened or not.
  • Attachment: sqlite3.diff
    (Size: 1.27KB, Downloaded 285 times)


Regards,
Novo
Re: Fix to Sqlite3Session::Open [message #19919 is a reply to message #19915] Mon, 02 February 2009 10:56 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Thanks!

Should not be the handle closed in Close and opened set to false again?

What about this fix:

bool Sqlite3Session::Open(const char* filename) {
	// Only open db once.
	ASSERT(NULL == db);
	current_filename = filename;
	// By default, sqlite3 associates the opened db with "main.*"
	// However, using the ATTACH sql command, it can connect to more databases.
	// I don't know how to get the list of attached databases from the API
	current_dbname = "main";
	if(SQLITE_OK == sqlite3_open(filename, &db))
		return true;
	if(db) {
		sqlite3_close(db);
		db = NULL;
	}
	return false;
}


Mirek
Re: Fix to Sqlite3Session::Open [message #19926 is a reply to message #19919] Tue, 03 February 2009 05:23 Go to previous message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
luzr wrote on Mon, 02 February 2009 04:56


Should not be the handle closed in Close and opened set to false again?



That will work too. It is just less efficient. sqlite3_open allocates a bunch of internal structures, which will be freed and allocated again in case sqlite3_close.


Regards,
Novo
Previous Topic: Conditional jump or move depends on uninitialised value(s)
Next Topic: few questions from a newbie
Goto Forum:
  


Current Time: Mon Apr 29 00:21:11 CEST 2024

Total time taken to generate the page: 0.05631 seconds