Re: [Cppcms-users] Bizarre prepared statement problem
Brought to you by:
artyom-beilis
From: Artyom B. <art...@ya...> - 2012-05-23 08:29:46
|
----- Original Message ----- > From: "ele...@ex..." <ele...@ex...> > >> Fixed in svn trunk in chageneset 2178. >> >> Please take it and see if it solve the problem (it should) >> >> I switched from using SQLITE_STATIC to full copy. >> >> I think I'm going to release a hot fix release for cppdb >> because some assumptions on the scope of the statement >> were incorrect. >> > > Thanks Artyom, > > I will test the patch ASAP, (although Im not at home right now), so I will > report back tomorrow. > > Can you tell me what you changed? Is returning cppdb::result without > calling next() expected to work now? Yes, the change is not in the behavior of the next but rather copying the value (see mo other mail) > > I did also want to ask you why did you not design cppdb::result as an > STL-like container with iterators? > Because using an iterator would require something like: for(cppdb::result::iterator p=res.begin();p!=res.end();++p) { cppdb::row r = *p; r >> .... } There are several problems with it: What is row, is it copied? Is it a reference? Where it is stored what "r >> val" changes? I agree that is is not "STL-complient" but iterator semantics was not working well there, so I took more JDBC like approach and it works well. > The way it is now I find it a little strange. For example if I run a query > and terminate with cppdb::row, calling next() will return false even if a > row exists. The semantics between cppdb::result::row and cppdb::result::query is very different. Calling cppdb::result::row() calls next and checks if the next row exists. If for example you call cppdb::result r = sql << "SELECT name from users " << cppdb::row; Instead of cppdb::result r = sql << "SELECT name from users where id=?" << id << cppdb::row; It would throw if the result is multi-row result (if backend supports such checks) The behavior with row is to do something like cppdb::result r = sql << "SELECT name from users where id=?" << id << cppdb::row; if(!r.empty()) { // we got user r >> name; } You can even run sql << "SELECT name from users where id=?" << id << cppdb::row >> name; (Of course the last one would throw if there is no such user) It has different semantics If you call next() on row result you are expected to get false as it is a single row. Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ |