Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to deal with comma and apostrophe chars when inserting into SQLight

How to deal with comma and apostrophe chars when inserting into SQLight

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 7.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    umen242
    wrote on last edited by
    #1

    i have string that contains apostrophe and comma's and when i excute insert into SQLight it gives me error for example with string like this :
    @...., 'The Smiths - I Know It's Over', .....
    "Over": syntax error Unable to execute statement@

    how can i or what can i do to keep the apostrophe's in the string but preform valid insert? .
    im using simple :
    @QString InsertSqlStst =" INSERT ......"
    QSqlQuery query;
    ret = query.exec(InsertSqlStst);@

    1 Reply Last reply
    0
    • L Offline
      L Offline
      leon.anavi
      wrote on last edited by
      #2

      You are talking about SQLite, aren't you?

      Please have a look at "SQLite documentation":http://www.sqlite.org/lang_expr.html:

      bq. A single quote within the string can be encoded by putting two single quotes in a row - as in Pascal.

      http://anavi.org/

      1 Reply Last reply
      0
      • U Offline
        U Offline
        umen242
        wrote on last edited by
        #3

        yeah SQLite , using the Qt tools to connect
        @m_db = QSqlDatabase::addDatabase("QSQLITE");@
        that means i need to run over each string to check ?
        isn't there some build in solution ?

        1 Reply Last reply
        0
        • L Offline
          L Offline
          leon.anavi
          wrote on last edited by
          #4

          [quote author="umen242" date="1328098068"]
          that means i need to run over each string to check ?
          isn't there some build in solution ?[/quote]

          Use "QSqlDriver::formatValue":http://developer.qt.nokia.com/doc/qt-4.8/qsqldriver.html#formatValue According to Qt documentation it will do the job:

          bq. Any embedded single-quote characters are escaped (replaced with two single-quote characters).

          http://anavi.org/

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            Use placeholders and bind them instead of handcrafting things. [[Doc:QSqlQuery]] docs have the gory details.

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • U Offline
              U Offline
              umen242
              wrote on last edited by
              #6

              i just looked the :formatValue source code , its using simple replace
              (: and this is what i did.
              Thanks for helping guys

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved