[Qt-interest] [SOLVED] QSqlQuery caching INSERT data?

Israel Brewster israel at frontierflying.com
Mon Nov 23 23:35:43 CET 2009


On Nov 22, 2009, at 3:19 PM, Bill King wrote:

> Yeah, again this is an sqlite issue. Sqlite if I remember correctly  
> won't close the transaction until you release the read lock (ie  
> close the select query). Its locking semantics are frustrating at  
> the best of times... ;)

You're telling me. At least I have everything working right now :-) So  
is Qt using transactions behind the scenes then? Or is it that SQLite  
considers each query a "transaction", even if you haven't explicitly  
started one?

Out of curiosity, why didn't calling close on the database properly  
close out the select? The behavior I was seeing implied that until I  
either a) explicitly called finish() or b) the query went out of  
scope, the read lock remained open, preventing new data from being  
written to disk. I would have thought that calling close() on the  
database would have finish()'d any active SELECTS as well, but that  
doesn't appear to be the case. Thanks for putting up with me as I  
struggled through this stuff :)

>
> On 11/21/2009 04:06 AM, ext Israel Brewster wrote:
>>
>> On Nov 20, 2009, at 8:44 AM, Israel Brewster wrote:
>>
>>>
>>> On Nov 20, 2009, at 7:57 AM, Israel Brewster wrote:
>>>
>>>>
>>>> On Nov 19, 2009, at 2:59 PM, Jason H wrote:
>>>>
>>>>> I haven't seen this for some time...
>>>>>
>>>>> I wonder what Qt version / QSqlDriver version you have.  
>>>>> Autocommit I think is on by default these days...
>>>>>
>>>>
>>>> Yeah, I probably should have mentioned that. Qt 4.5.3, with  
>>>> whatever version of the QSqlite driver comes with that. Now that  
>>>> you mention it, I don't recall seeing this behavior until I  
>>>> upgraded from 4.5.2 to 4.5.3. Maybe I should try with 4.5.2  
>>>> again, and see what happens.
>>>
>>> Nope, I was wrong, this happens with 4.5.2 as well. I must just  
>>> have not noticed it due to the way my code worked before. Guess  
>>> I'll have to look elsewhere.
>>
>> Figured it out: the problem was with my code. As stated here: http://doc.trolltech.com/4.5/qsqldatabase.html#commit 
>> , "For some databases, the commit will fail and return false if  
>> there is an active query using the database for a SELECT". Which is  
>> exactly what was happening for me - I had a select statement in the  
>> main function that wasn't being set inactive until main returned -  
>> i.e. when I quit the application. It is a little confusing, as the  
>> commit() function appears to only apply when you are using  
>> transactions (which I wasn't), but apparently behind the scenes Qt  
>> does, even when just doing an insert from a QSqlQuery. Or  
>> something. Dunno. Either way, it's working now. Thanks for the  
>> feedback.
>>
>>>
>>>>
>>>>>
>>>>> From: Israel Brewster <israel at frontierflying.com>
>>>>> To: Jason H <scorp1us at yahoo.com>
>>>>> Cc: QT Mailing LIST <qt-interest at trolltech.com>
>>>>> Sent: Thu, November 19, 2009 6:47:52 PM
>>>>> Subject: Re: [Qt-interest] QSqlQuery caching INSERT data?
>>>>>
>>>>>
>>>>> On Nov 19, 2009, at 2:44 PM, Jason H wrote:
>>>>>
>>>>>> Make sure that you are auto committing transactions, or are  
>>>>>> manually committing them.
>>>>>>
>>>>>> No it does not cache them, but your DB might. I've seen this  
>>>>>> before, wher SQLite will make a .journal file with the insert  
>>>>>> content, but won;t be committed because you never commited the  
>>>>>> transaction. Then, when you run your program again,  
>>>>>> the .journal is deleted because it doesn't have a completed  
>>>>>> transaction.
>>>>>
>>>>> Thanks. That sounds like exactly what is happening (I am seeing  
>>>>> the journal file), except that I am not using transactions. I  
>>>>> did try calling commit(), just for kicks, but it returned false  
>>>>> as expected.
>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> From: Israel Brewster <israel at frontierflying.com>
>>>>>> To: QT Mailing LIST <qt-interest at trolltech.com>
>>>>>> Sent: Thu, November 19, 2009 4:04:48 PM
>>>>>> Subject: [Qt-interest] QSqlQuery caching INSERT data?
>>>>>>
>>>>>> Does QSqlQuery do any caching of INSERT statements? If so, is  
>>>>>> there a way to force the cache to be flushed to the database? I  
>>>>>> have a program that executes a number of INSERT statements  
>>>>>> using QSqlQuery, but they don't seem to be written to disk  
>>>>>> until the app quits. Usually this isn't a problem, and is  
>>>>>> probably a good thing, but there are a couple of places where  
>>>>>> this doesn't work for me. I tried using a QSqlDatbase::close()  
>>>>>> command, but this doesn't seem to produce the desired result. I  
>>>>>> didn't think QSqlQuery did any caching aside from results,  
>>>>>> which makes me think this is a SQLite process that doing the  
>>>>>> caching, but I wanted to ask here anyway. Even if it is SQLite,  
>>>>>> is there some Qt command I could run to make SQLite think I am  
>>>>>> done and write the data out? Thanks for any advice!
>>>>>>
>>>>>> -----------------------------------------------
>>>>>> Israel Brewster
>>>>>> Computer Support Technician II
>>>>>> Frontier Flying Service Inc.
>>>>>> 5245 Airport Industrial Rd
>>>>>> Fairbanks, AK 99709
>>>>>> (907) 450-7250 x293
>>>>>> -----------------------------------------------
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>> -----------------------------------------------
>>>>> Israel Brewster
>>>>> Computer Support Technician II
>>>>> Frontier Flying Service Inc.
>>>>> 5245 Airport Industrial Rd
>>>>> Fairbanks, AK 99709
>>>>> (907) 450-7250 x293
>>>>> -----------------------------------------------
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>> -----------------------------------------------
>>>> Israel Brewster
>>>> Computer Support Technician II
>>>> Frontier Flying Service Inc.
>>>> 5245 Airport Industrial Rd
>>>> Fairbanks, AK 99709
>>>> (907) 450-7250 x293
>>>> -----------------------------------------------
>>>>
>>>> <Israel Brewster.vcf>
>>>>
>>>> _______________________________________________
>>>> Qt-interest mailing list
>>>> Qt-interest at trolltech.com
>>>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>>
>>> -----------------------------------------------
>>> Israel Brewster
>>> Computer Support Technician II
>>> Frontier Flying Service Inc.
>>> 5245 Airport Industrial Rd
>>> Fairbanks, AK 99709
>>> (907) 450-7250 x293
>>> -----------------------------------------------
>>>
>>> <Israel Brewster.vcf>
>>>
>>> _______________________________________________
>>> Qt-interest mailing list
>>> Qt-interest at trolltech.com
>>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>
>> -----------------------------------------------
>> Israel Brewster
>> Computer Support Technician II
>> Frontier Flying Service Inc.
>> 5245 Airport Industrial Rd
>> Fairbanks, AK 99709
>> (907) 450-7250 x293
>> -----------------------------------------------
>>
>
>
> -- 
> Bill King, Software Engineer
> Qt Development Frameworks, Nokia Pty Ltd
> Brisbane Office

-----------------------------------------------
Israel Brewster
Computer Support Technician II
Frontier Flying Service Inc.
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7250 x293
-----------------------------------------------



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091123/fdaa947c/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Israel Brewster.vcf
Type: text/directory
Size: 417 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091123/fdaa947c/attachment.bin 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091123/fdaa947c/attachment-0001.html 


More information about the Qt-interest-old mailing list