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 » SQLite crashes
SQLite crashes [message #16426] Sat, 14 June 2008 01:04 Go to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

Recently I tried to use SQLite U++ plugin and met strange yet unavoidable error: after calling Open(), in the end of scope, sqlite library throws an exception. Let`s consider minimal U++/sqlite console application:
#include <Core/Core.h>
#include <plugin/sqlite3/Sqlite3.h>
using namespace Upp;

CONSOLE_APP_MAIN
{
	Sqlite3Session session;
	session.LogErrors(true);
	if (!session.Open("data"))
		Cout() << "Error opening SQL";
}//crash here!

Actual crash seems to happen in file /uppsrc/Sql/Sqls.h, line 219

Conditions: WinXP, latest SVN (rev. 297).

Unfortunately I`m not good at databases, so I can`t propose adequate solution on that problem. But I think any plugins should work "from the box" without resulting any crashes.

Any ideas on solving this?
Re: SQLite crashes [message #16428 is a reply to message #16426] Sat, 14 June 2008 09:42 Go to previous messageGo to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

My investigation continues.
Somehow it seems that this code works without exception:
#include <Core/Core.h>
#include <plugin/sqlite3/Sqlite3.h>
using namespace Upp;

CONSOLE_APP_MAIN
{
	Sqlite3Session session;
	session.LogErrors(true);
	if (!session.Open("data"))
		Cout() << "Error opening SQL";
	
	SQL = session;
}

[Updated on: Sat, 14 June 2008 09:50]

Report message to a moderator

Re: SQLite crashes [message #16469 is a reply to message #16428] Tue, 17 June 2008 08:10 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
A bug. QuickFix:

void Sqlite3Session::Close() {
	if (NULL != db) {
		int retval;
#ifndef flagNOAPPSQL
		if(SQL.IsOpen() && &SQL.GetSession() == this)
			SQL.Cancel();
#endif


Note that it is typical to assign SQL or use NOAPPSQL, that is why this bug was left unnoticed until now (thanks!).

Mirek
Re: SQLite crashes [message #16516 is a reply to message #16469] Thu, 19 June 2008 22:04 Go to previous messageGo to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

Thanx for the fix!

Also I`ve discovered something that could be a problem. It may be SQLite specific - I don`t know for shure at the moment.
When I try to Fetch() after Execute() of some SQL statement which contained error, an exception is thrown. And it seems like it doesn`t caught even with catch(...). Maybe it is C-style exception or something like that. This makes application potentially risky and unstable.
I had no free time to analyze this feature excessively but that certainly could be a problem.
Re: SQLite crashes [message #16517 is a reply to message #16516] Thu, 19 June 2008 23:01 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

The best would be if you post here a testcase.
Re: SQLite crashes [message #16965 is a reply to message #16517] Wed, 23 July 2008 18:31 Go to previous messageGo to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

OK, I switched to MySQL from SQLite and have the same error.

Usually one checks Execute() before doing Fetch:
MySqlSession session;
String q = ".....";
if (!session.Connect(...))
	return;
Sql sql(session);
if (sql.Execute(q))
	while(sql.Fetch())
	{
		for (int i=0; i<sql.GetColumns(); ++i)
			ShowDBMessage(sql.GetColumnInfo(i).name + " : " + (String)sql[i]);
	}

But if you forget to check Execute() and start fetching, the Fetch() call will throw an exception:
sql.Execute(q);
while(sql.Fetch()) //<-- throws an exception if Execute() failed
{
	for (int i=0; i<sql.GetColumns(); ++i)
		ShowDBMessage(sql.GetColumnInfo(i).name + " : " + (String)sql[i]);
}


I think Fetch() should not throw an exception, instead it should return no results if latest Execute() failed.
Re: SQLite crashes [message #16966 is a reply to message #16965] Wed, 23 July 2008 19:04 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Mindtraveller wrote on Wed, 23 July 2008 12:31

OK, I switched to MySQL from SQLite and have the same error.

Usually one checks Execute() before doing Fetch:
MySqlSession session;
String q = ".....";
if (!session.Connect(...))
	return;
Sql sql(session);
if (sql.Execute(q))
	while(sql.Fetch())
	{
		for (int i=0; i<sql.GetColumns(); ++i)
			ShowDBMessage(sql.GetColumnInfo(i).name + " : " + (String)sql[i]);
	}

But if you forget to check Execute() and start fetching, the Fetch() call will throw an exception:
sql.Execute(q);
while(sql.Fetch()) //<-- throws an exception if Execute() failed
{
	for (int i=0; i<sql.GetColumns(); ++i)
		ShowDBMessage(sql.GetColumnInfo(i).name + " : " + (String)sql[i]);
}


I think Fetch() should not throw an exception, instead it should return no results if latest Execute() failed.


Ah, this one. It is there since beginning and U++ being started as database interface library, it is perhaps the right thing to do.

Imagine impact if Fetch would actually return false. In that case, a lot of code would do wrong things and pretend everything is OK....

Mirek
Previous Topic: Difference between INT_ and INT?
Next Topic: underflow in bool Sql::fetch()
Goto Forum:
  


Current Time: Thu Mar 28 12:54:09 CET 2024

Total time taken to generate the page: 0.01459 seconds