Results 1 to 3 of 3

Thread: Storing QStringList to a MySQL table field

  1. #1
    Join Date
    May 2010
    Location
    Rousse, Bulgaria
    Posts
    25
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Storing QStringList to a MySQL table field

    Greetings!
    I am trying to store a QStringList into MySQL, but it always executes the query without the string list itself.
    Qt Code:
    1. query.clear(); // make sure the query is empty
    2. QStringList ports;
    3. ports << "first" << "second" << "third";
    4. query.prepare("INSERT INTO switches(model,address,location,nas_ip,voltage,notes,ports) "
    5. "VALUES ('1','3','test',INET_ATON('10.0.0.3'),220,'test',?)");
    6. query.addBindValue(ports);
    7. qDebug() << query.boundValue(0); // this returns the qstringlist as it should
    8. query.exec();
    9. qDebug() << query.executedQuery(); // this displays "INSERT INTO switches(model,address,location,nas_ip,voltage,notes,ports) VALUES ('1','3','test',INET_ATON('10.0.0.3'),220,'test',?)"
    To copy to clipboard, switch view to plain text mode 
    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!

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Storing QStringList to a MySQL table field

    what happens if you try

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

    ?
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. The following user says thank you to amleto for this useful post:

    Axtroz (17th July 2012)

  4. #3
    Join Date
    May 2010
    Location
    Rousse, Bulgaria
    Posts
    25
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Storing QStringList to a MySQL table field

    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!

Similar Threads

  1. QDataWidgetMapper doesn't always update field in table
    By marcvanriet in forum Qt Programming
    Replies: 4
    Last Post: 14th December 2011, 11:57
  2. Replies: 4
    Last Post: 16th June 2011, 14:49
  3. SQL JOIN queries & QSqlRecord objects not storing table names
    By SweetieCakes in forum Qt Programming
    Replies: 5
    Last Post: 25th July 2010, 10:47
  4. MYSQL 5 Table qt model as small Mysql admin
    By patrik08 in forum Qt-based Software
    Replies: 0
    Last Post: 1st May 2007, 09:43
  5. Figure - field for MySQL record
    By Dmitry in forum Qt Programming
    Replies: 1
    Last Post: 28th October 2006, 20:00

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.