Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, September 2007
QSqlQuery


Message 1 in thread

Hi

I use QSQLITE and want to reuse the Sql Statements(so that they are not
compiled again and again). This is working some times but not anytime. Here
some pseudo code:

query = createQueryAndCache(String select);

query.bindValue( .. )

query.exec();

while(query.next()) ... /// get some usefull return values

...


query = createQueryAndCache(String select); // this time I use the cached
version


query.bindValue( .. )

query.exec();

while(query.next()) ... // get null values


Is this not possible or is there a  error in reasoning.

thanks and regards

Marco


<http://dict.leo.org/ende?lp=ende&p=eL4jZr&search=reasoning>

Message 2 in thread

Hi Marco,

see very similar problem of myself
http://lists.trolltech.com/qt-interest/2007-04/thread00099-0.html

For reliable QSQLITE operation, you apparently need to do
QSqlQuery::clear() after each exec(). Which effectively prohibits
prepared statements, which is what you are aiming for if understand
your pseudocode right. The Qt documentation as of 4.3 still says "You
should rarely if ever need to call this function." on
QSqlQuery::clear(), but it seems to be absolutely necessary for
QSQLITE driver.

Best regards,

Pavel Zdenek

2007/9/3, marco bubke <marco@xxxxxxxx>:
> Hi
>
> I use QSQLITE and want to reuse the Sql Statements(so that they are not
> compiled again and again). This is working some times but not anytime. Here
> some pseudo code:
>
> query = createQueryAndCache(String select);
>
> query.bindValue( .. )
>
> query.exec();
>
> while(query.next()) ... /// get some usefull return values
>
> ...
>
>
> query = createQueryAndCache(String select); // this time I use the cached
> version
>
>
>  query.bindValue( .. )
>
>  query.exec();
>
>  while(query.next()) ... // get null values
>
>
> Is this not possible or is there a  error in reasoning.
>
> thanks and regards
>
> Marco
>
>
>
>

--
 [ signature omitted ] 

Message 3 in thread

Yes, this is my problem. clear() is removing the state of the query and I
want reuse the state. If I do prepare() again its working but this is
useless too.

On 9/4/07, Pavel Zdenek <pavel.zdenek@xxxxxxxxx> wrote:
>
> Hi Marco,
>
> see very similar problem of myself
> http://lists.trolltech.com/qt-interest/2007-04/thread00099-0.html
>
> For reliable QSQLITE operation, you apparently need to do
> QSqlQuery::clear() after each exec(). Which effectively prohibits
> prepared statements, which is what you are aiming for if understand
> your pseudocode right. The Qt documentation as of 4.3 still says "You
> should rarely if ever need to call this function." on
> QSqlQuery::clear(), but it seems to be absolutely necessary for
> QSQLITE driver.
>
> Best regards,
>
> Pavel Zdenek
>
> 2007/9/3, marco bubke <marco@xxxxxxxx>:
> > Hi
> >
> > I use QSQLITE and want to reuse the Sql Statements(so that they are not
> > compiled again and again). This is working some times but not anytime.
> Here
> > some pseudo code:
> >
> > query = createQueryAndCache(String select);
> >
> > query.bindValue( .. )
> >
> > query.exec();
> >
> > while(query.next()) ... /// get some usefull return values
> >
> > ...
> >
> >
> > query = createQueryAndCache(String select); // this time I use the
> cached
> > version
> >
> >
> >  query.bindValue( .. )
> >
> >  query.exec();
> >
> >  while(query.next()) ... // get null values
> >
> >
> > Is this not possible or is there a  error in reasoning.
> >
> > thanks and regards
> >
> > Marco
> >
> >
> >
> >
>

Message 4 in thread

Pavel Zdenek wrote:

> Hi Marco,
> 
> see very similar problem of myself
> http://lists.trolltech.com/qt-interest/2007-04/thread00099-0.html
> 

I believe these are separate issues. In the thread you refer to the call 
to exec() returns false and an error complaining that the database is 
locked is set. In Marco's case next() returns true, which it shouldn't 
if the exec() had failed.


> For reliable QSQLITE operation, you apparently need to do
> QSqlQuery::clear() after each exec(). Which effectively prohibits
> prepared statements, which is what you are aiming for if understand
> your pseudocode right. The Qt documentation as of 4.3 still says "You
> should rarely if ever need to call this function." on
> QSqlQuery::clear(), but it seems to be absolutely necessary for
> QSQLITE driver.
>

When a query is executed SQLite locks the database. If it's a select 
statement the lock will be held until the end of the result set is 
reached, clear() is called or the query is destroyed.

Qt 4.3.2 will introduce a finish() function which can be used to 
instruct the driver that no more data will be fetched from the result 
set until the query is re-executed, thus the lock can be released.

http://doc.trolltech.com/4.3-snapshot/qsqlquery.html#finish


--
 [ signature omitted ] 

Message 5 in thread

marco bubke wrote:

> I use QSQLITE and want to reuse the Sql Statements(so that they are not 
> compiled again and again). This is working some times but not anytime. 
> Here some pseudo code:

[...]

> query = createQueryAndCache(String select); // this time I use the 
> cached version
> 
> query.bindValue( .. )
> query.exec();
> while(query.next()) ... // get null values
> 
> Is this not possible or is there a  error in reasoning.
> 

This should be possible.

Is this failing only for select statements when forwardOnly is set? If 
so it's a bug that has been fixed for Qt 4.3.2.


--
 [ signature omitted ]