[Qt-interest] Compressing sqlite file with QtIOCompressor results in corrupted db
Tony Rietwyk
tony.rietwyk at rightsoft.com.au
Mon Sep 6 14:46:52 CEST 2010
> -----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.
More information about the Qt-interest-old
mailing list