Results 1 to 2 of 2

Thread: [QT5.4] QtSQL MySql driver fails to write a string with ' to table

  1. #1

    Default [QT5.4] QtSQL MySql driver fails to write a string with ' to table

    Hi!

    I'm trying to write a string with ' to a table but QSqlQuery returns a syntax error near animateur :

    Qt Code:
    1. if (!query.exec("INSERT INTO TEST_DESCRIPTIONS (DESCRIPTION, USER_ID) VALUES('L\'animateur ...',"+QString(id)+");")) {
    2. QSqlError error = query.lastError();
    3. QMessageBox::critical(nullptr, "Write Error", "Failed to save information to database"+error.text());
    4. }
    To copy to clipboard, switch view to plain text mode 

    With MySQL client command line, it insert the row into the table without any problem.

  2. #2

    Default Re: [QT5.4] QtSQL MySql driver fails to write a string with ' to table

    I've found why, the compiler escape the character ' so I had to make a double escapment.

    \\'

Similar Threads

  1. QtSql write results to XML Hierarchy for List
    By prophet0 in forum Qt Programming
    Replies: 6
    Last Post: 15th April 2012, 04:10
  2. source code for odbc driver or MySql driver in arm-embedded-linux
    By sattu in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 24th January 2011, 10:11
  3. export file MySql to QtSql
    By pispipepe in forum Qt Programming
    Replies: 4
    Last Post: 21st December 2010, 02:19
  4. QtSql , how to list all databases on the Mysql-Server
    By luoihoc in forum Qt Programming
    Replies: 1
    Last Post: 7th July 2009, 21:52
  5. QTSql String Quoteing
    By ldsjohn in forum Qt Programming
    Replies: 6
    Last Post: 5th December 2006, 00:12

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.