Results 1 to 4 of 4

Thread: how to insert an ' in a database

  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    84
    Thanks
    7
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default how to insert an ' in a database

    hi,

    i have an application which stores string that contain the character <'>.
    this is also the delimiter of an value in a insert statement. so how can
    i add a string which contains a ' in a access database?

    example:
    insert <R'w>:
    INSERT INTO table1 (header1, header2) VALUES ('abc', 'R'w')

    any hint?

    best regards,
    jh

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to insert an ' in a database

    It might depend on database, but in PostgreSQL you can use '' or \'.

    BTW. In Qt there is QSqlQuery::bindValue() which handles this automatically.

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    84
    Thanks
    7
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to insert an ' in a database

    it is an MS Access database using ODBC.

    bindValue has some problems adding strings to a column of type memo
    which are longer than 128 characters.

    jh

  4. #4
    Join Date
    Jan 2006
    Posts
    75
    Thanks
    3
    Thanked 5 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to insert an ' in a database

    In SQL, use an extra ['][\] to escape your ['] char, that is:

    I 'm a boy. => I ''m a boy.

    or

    I 'm a boy. => I \'m a boy.

Similar Threads

  1. Replies: 7
    Last Post: 12th August 2006, 15:11
  2. Issues regarding QMySql drivers and mysql database
    By bera82 in forum Qt Programming
    Replies: 2
    Last Post: 10th August 2006, 17:50
  3. Filling combobox from database
    By Philip_Anselmo in forum Qt Programming
    Replies: 3
    Last Post: 11th May 2006, 17:53
  4. Save images to database
    By jnk5y in forum Qt Programming
    Replies: 4
    Last Post: 8th May 2006, 19:56
  5. Replies: 8
    Last Post: 7th March 2006, 13:40

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.