PDA

View Full Version : Storing QStringList to a MySQL table field



Axtroz
16th July 2012, 12:44
Greetings!
I am trying to store a QStringList into MySQL, but it always executes the query without the string list itself.


query.clear(); // make sure the query is empty
QStringList ports;
ports << "first" << "second" << "third";
query.prepare("INSERT INTO switches(model,address,location,nas_ip,voltage,not es,ports) "
"VALUES ('1','3','test',INET_ATON('10.0.0.3'),220,'test',? )");
query.addBindValue(ports);
qDebug() << query.boundValue(0); // this returns the qstringlist as it should
query.exec();
qDebug() << query.executedQuery(); // this displays "INSERT INTO switches(model,address,location,nas_ip,voltage,not es,ports) VALUES ('1','3','test',INET_ATON('10.0.0.3'),220,'test',? )"


I tried using a placeholder and bindValue but the result is almost the same, instead of "?" the executed query contains the placeholder
the ports field is a BLOB field. Any thoughts? Thanks in advance!

amleto
16th July 2012, 17:24
what happens if you try

QString ports;
ports.append("first, ").append("second, ").append("third");

?

Axtroz
17th July 2012, 08:54
Using a QString instead of a QStringList works. I still don't understand why the list isn't getting in... I'll use QString::split to get a QStringList. Thanks!