[Qt-interest] Compressing sqlite file with QtIOCompressor results in corrupted db

Jan janusius at gmx.net
Mon Sep 6 15:26:05 CEST 2010


That's it.

Thank you, Tony

Am 06.09.2010 14:46, schrieb Tony Rietwyk:
>> -----Original Message-----
>> Sent: Monday, 6 September 2010 21:26
>> Hi all,
>>
>> I am compressing/uncompressing a sqlite db file with QtIOCompressor.
>>
>> The file size seems to be ok after uncompressing and I am
>> able to open
>> the database but any query will fail with: "File is encrypted
>> or not a
>> database".
>> Do I need to set any other options?
>>
>> This is the code:
>>
>> //compressing
>> QFile fileIn("in");
>> fileIn.open(QIODevice::ReadOnly);
>> QByteArray ba = fileIn.readAll();
>>
>> QFile outFile("out");
>> QtIOCompressor compressor(&outFile);
>> compressor.open(QIODevice::WriteOnly);
>> compressor.write(ba);
>> compressor.close();
>>
>> //uncompressing
>> QFile compsqlite("out");
>> QFile sqlite("sqlite");
>>
>> QtIOCompressor compressor(compsqlite);
>> compressor.open(QIODevice::ReadOnly);
>> const QByteArray ba = compressor.readAll();
>>
>> sqlite.open(QIODevice::WriteOnly);
>> QDataStream out(&sqlite);
>>
>> compressor.close();
>> out<<  ba;
>>
>>
>> Jan
>
>
> Hi Jan,
>
> QDataStream is a file format private to Qt applications.  So sqlite won't
> know about it.
>
> I suggest to use sqlite.write(ba) to mirror the readAll that you did on the
> "in" file.
>
> Tony.
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>



More information about the Qt-interest-old mailing list