Page 1 of 1

QVariant DB Persist

PostPosted: Tue Apr 11, 2017 3:35 pm
by Kasuax
I need to switch the internal mechanisms that serialize QVariants to the database from XML to Binary.
We are vary heavy on QVariants and I feel a switch like this might buy us some time savings.

Is there a flag I can set somewhere?

Thanks,
-Stephen

Re: QVariant DB Persist

PostPosted: Tue Apr 18, 2017 7:58 am
by qxorm
Hello,

No there is no runtime flag.
But if you doesn't enable boost XML serialization compilation option, then the binary serialization will be used.

Re: QVariant DB Persist

PostPosted: Thu Apr 20, 2017 3:58 pm
by Kasuax
Excellent I will try this!
Thank you!

Re: QVariant DB Persist

PostPosted: Tue Apr 25, 2017 4:12 am
by Kasuax
I'm having some unexpected difficulty with this.
The only thing I did was disable XML in the QxOrm.pri

I'm trying to write out the following QVariant type and it's failing to generate the sql insert statement correctly.

Let me know what you think. Thanks!

Code: Select all
typedef QPair<QString, QVariant> Option;
typedef QList<Option> OptionsList;


Code: Select all
    QXC::OptionsList samplingRates;
    samplingRates.append(QXC::Option(QString("12.5hz"), 12.5));
    samplingRates.append(QXC::Option(QString("25hz"), 25.0));
    samplingRates.append(QXC::Option(QString("50hz"), 50.0));
    samplingRates.append(QXC::Option(QString("100hz"), 100.0));
    samplingRates.append(QXC::Option(QString("200hz"), 200.0));
    samplingRates.append(QXC::Option(QString("400hz"), 400.0));
    samplingRates.append(QXC::Option(QString("800hz"), 800.0));

    settings->setSamplingRates(samplingRates);


Code: Select all
WARNING:  nonstandard use of \\ in a string literal
LINE 1: SELECT '\\' x
               ^
HINT:  Use the escape string syntax for backslashes, e.g., E'\\'.
WARNING:  nonstandard use of \\ in a string literal
LINE 1: SELECT '\\' x
               ^

Re: QVariant DB Persist

PostPosted: Tue Apr 25, 2017 10:24 am
by qxorm
I don't see the call which generate the SQL query.
How do you build your SQL query ? Could you please share this code ?

Re: QVariant DB Persist

PostPosted: Tue Apr 25, 2017 4:09 pm
by Kasuax
I don't build the query, the entity editor and framework build the query for me. I'm wondering if I'm not correctly mapping types in the entity editor. Since this is ultimately a variable blob of text I set the field as a TEXT in postgres. But if it's encoded as a binary blob should I represent that somehow else via the editor?

Re: QVariant DB Persist

PostPosted: Wed Apr 26, 2017 5:51 pm
by qxorm
I don't understand your issue and I'm not able to reproduce it.
Do you have this error when you call this line : settings->setSamplingRates(samplingRates); ?

Re: QVariant DB Persist

PostPosted: Wed Apr 26, 2017 7:18 pm
by Kasuax
The class that exhibits this structure is failing to insert into my db when i try save it.
I think the problem has something to do with expect types. This "Options" class when broken down into a binary blob might be picking the wrong sql param method when it goes to do the insert. The problem is definitely with the insert sql statement and facilitating parameter. The insert statement looks clean but I'm not sure the value bind is taking the correct approach.

This was just 1 way to do this as per your example.
Code: Select all
qx::QxSqlQuery query("WHERE author.sex = :sex");
query.bind(":sex", author::female);


I'll see what else I can dig up.
Thanks

Re: QVariant DB Persist

PostPosted: Thu Apr 27, 2017 12:41 pm
by qxorm
What is your database ?
Maybe the problem comes from the placeholder type : instead of :sex, maybe it should be '?' ?
You can change it with the function : qx::QxSqlDatabase::getSingleton()->setSqlPlaceHolderStyle()
More details in the manual here : https://www.qxorm.com/qxorm_en/manual.html#manual_3600

Re: QVariant DB Persist

PostPosted: Thu Apr 27, 2017 6:20 pm
by Kasuax
We are using postgres.
I'll look into this thank you!