Overview
Features
Download
Documentation
Community
Add-Ons & Services

SQLite and exceptions weirdness

Please post support and help requests here.

SQLite and exceptions weirdness

Postby wouter » 20 Oct 2012, 20:00

Hello, I'm having some trouble with SQLite and with Poco exceptions in general. I'm using visual studio 2012 express.

I'm trying to read from an sqlite db. The relevant code is (really think I did not omit anything):
Code: Select all
      SQLite::Connector::registerConnector();
      Session session(SQLite::Connector::KEY, "db");

      int id;
      string password;
      string username = "john";
      try {
        session << "SELECT id, password FROM skypeuser WHERE username=:name", into(id), into(password), use(username), now;
      } catch (Poco::Exception& e) {
        cout << "Exception " << e.displayText() << endl;
      }
      cout << password << endl;


When I run this by executing the produced executable it seems to work fine, I retrieve the correct password. When I run this from the debugger it actually throws an Poco::Data::SQLite::InvalidSQLStatementException - SQL Statement invalid or database missing and it enters the catch block. Weird.

Alternatively, when I specify a non-existent user (i.e., not "john"), then when I run it outside of the debugger *nothing* happens. It does not enter the catch block. In the debugger the same exception appears.

Two questions:
1. If a record is not found, what should be the expected behaviour? I can't find anything on that in the documentation.
2. Why isn't it entering catch blocks outside of the debugger? Did I compile the Poco libraries in a wrong way? I don't want to switch to release mode just for this.

Please help. Thanks.
wouter
 
Posts: 9
Joined: 18 Oct 2012, 13:05

Re: SQLite and exceptions weirdness

Postby alex » 20 Oct 2012, 22:17

My guess would be that your database "db" is not found during debugging. Most likely, the executable is in another directory and db is also there so it finds it ok but when you run the debugger, the current directory is the one where VS project is located. Nothing to do with compilation. No exception is thrown on no data found condition.
alex
 
Posts: 1086
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: SQLite and exceptions weirdness

Postby wouter » 21 Oct 2012, 00:37

Well, it actually does find the right data from that file, so I don't think that's it. I'm trying to recompile the libraries as static now to see if it's a c++ runtime mismatch or something. Thanks Alex
wouter
 
Posts: 9
Joined: 18 Oct 2012, 13:05

Re: SQLite and exceptions weirdness

Postby wouter » 21 Oct 2012, 01:38

No luck.. I'm really stumped.
wouter
 
Posts: 9
Joined: 18 Oct 2012, 13:05

Re: SQLite and exceptions weirdness

Postby wouter » 21 Oct 2012, 03:28

Wait.. I see what you mean now.. Sigh. (ITts 3:28 Am now, sorry).

What should be the result of data not found then?
wouter
 
Posts: 9
Joined: 18 Oct 2012, 13:05

Re: SQLite and exceptions weirdness

Postby alex » 21 Oct 2012, 03:52

wouter wrote:What should be the result of data not found then?

Obviously - nothing. If you pass in, say, std::vector's (make it std::vector<Tuple<..> > if you want only one), it'll be empty after select. Or you can "select count(*) where ..." first. Or you can let Poco::Data take care of storage and you'll get back an empty Poco::Data::RecordSet. Many ways to skin that cat ...
alex
 
Posts: 1086
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: SQLite and exceptions weirdness

Postby wouter » 21 Oct 2012, 11:57

Thanks for all your help Alex. I got thrown off by this nothing behaviour a bit. In my experience frameworks usually throw an exception or set some error flag, this threw me off. I'll probably go with the RecordSet approach. I really liked the other form though :) Thanks!
wouter
 
Posts: 9
Joined: 18 Oct 2012, 13:05

Re: SQLite and exceptions weirdness

Postby wouter » 21 Oct 2012, 12:05

Actually, the one with vector and tuple is rather elegant too :) Why didn't I try that earlier? I keep learning the same lesson: no coding after midnight.. :)
wouter
 
Posts: 9
Joined: 18 Oct 2012, 13:05

Re: SQLite and exceptions weirdness

Postby alex » 21 Oct 2012, 17:15

wouter wrote:Actually, the one with vector and tuple is rather elegant too

FWIW, that will perform better than RecordSet because types are known upfront and there's no data types discovery overhead. But, in my experience, it matters only if you have very large datasets. For smaller (~few thousand) ones, there should be no noticeable difference.
As for no data found being an error, that's somewhat of a philosophical question. If 0 rows is error, why not 10 rows be error in case where you expect 11?
alex
 
Posts: 1086
Joined: 11 Jul 2006, 16:27
Location: United_States


Return to Support

Who is online

Users browsing this forum: No registered users and 2 guests