[Interest] Qt Sql BLOB data converting
Yauheni Pervenenka
yauheni.pervenenka at viber.com
Mon Nov 28 10:00:01 CET 2022
Hello, Henry, thanks for the reply, seems like no, there is simple code
QSqlQuery query("SELECT value from table");
while (query.next()) {
const auto value = query.value(0);
qDebug() << value.toByteArray().size(); // size 52
qDebug() << value.toString().size(); // size 30
qDebug() << value.toByteArray().toHex(); // size 104
}
On Mon, Nov 28, 2022 at 11:49 AM Henry Skoglund <henry at tungware.se> wrote:
> On 2022-11-28 09:32, Yauheni Pervenenka via Interest wrote:
>
> Hi, Tony, thanks for your reply,
> OS: win 11
> DB: SQLite
>
> Unfortunately, QVariant::toByteArray returns size 52(hex 104),
> QVariant::toString returns size 30
>
> There is data returned by QVariant::toByteArray::toHex
> Qt data in hex(size 104):
>
> 763130492d46c2ab4cc29c7bc2b0efbfbd78c29b29c3ab1e4723dea6efbfbdefbfbdefbfbdefbfbd66c2a275efbfbdefbfbdc4a6
>
> Original value in hex
> size(68): 763130492d46ab4c9c7bb0e9789b29c3ab1e4723dea6c8e5d2f9b266a275e1fbe4a6
>
> there are some data that is parsed correct but time to time it is broken
>
>
>
> On Mon, Nov 28, 2022 at 11:17 AM Tony Rietwyk <tony at rightsoft.com.au>
> wrote:
>
>> Hi Yauheni,
>>
>> You don't say which type of database you are using? There may be issues
>> with the database client library altering the blob to UTF8. Though I
>> would expect the python code using the same client to have the same
>> problem.
>>
>> Assuming that QVariant has the byte array unaltered, then
>> QVariant.toByteArray().length() should give 34. Using qstrlen, suggests
>> that you are using QVariant.toString instead. To print the hex you
>> should just use QVariant.toByteArray().toHex().
>>
>> Hope that helps,
>>
>> Tony
>>
>>
>> On 28/11/2022 6:46 pm, Yauheni Pervenenka via Interest wrote:
>> > Hello, community
>> > I have faced with issue that qvariant using qstrlen for getting data
>> > size, but sometimes it returns wrong size especially for BLOB data(if
>> > there are some special symbols), are there any way to get data correct?
>> >
>> > Note:
>> > Database value 34, python returns correct data size, but
>> > qvariant::toByteArray returns 52
>> >
>> > Python data and Database data in hex(size
>> >
>> 68): 763130492d46ab4c9c7bb0e9789b29c3ab1e4723dea6c8e5d2f9b266a275e1fbe4a6
>> >
>> > Qt data in hex(size 104):
>> >
>> 763130492d46c2ab4cc29c7bc2b0efbfbd78c29b29c3ab1e4723dea6efbfbdefbfbdefbfbdefbfbd66c2a275efbfbdefbfbdc4a6
>> >
>>
>
> Hi, most of the data is preserved in Qt but some other data is injected
> midstream.
> Just a guess, but maybe the Qt version has a multithreading issue, like
> two threads are settings values in the same array at the same time.
>
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> https://lists.qt-project.org/listinfo/interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20221128/c3636a6f/attachment.htm>
More information about the Interest
mailing list