Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Parameterised SQL Insert fails; plain text Insert works

Parameterised SQL Insert fails; plain text Insert works

Scheduled Pinned Locked Moved Database
databasesql-serversysadminhelp
4 Posts 3 Posters 0 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.
  • H Offline
    H Offline
    hairy_hats
    wrote on last edited by
    #1

    Hi all, I'm using POCO[^] ODBC libraries to access SQL Server 2005, and have hit a problem. If I enter a plain text statement:

    session << "INSERT INTO TableName VALUES(44)", now;

    it works fine. If I use a parameterised query:

    int size=44;

    session << "INSERT INTO TableName VALUES(:size)", use(size), now;

    it throws an exception. The table contains a single int column. Any suggestions gratefully received!

    M D 2 Replies Last reply
    0
    • H hairy_hats

      Hi all, I'm using POCO[^] ODBC libraries to access SQL Server 2005, and have hit a problem. If I enter a plain text statement:

      session << "INSERT INTO TableName VALUES(44)", now;

      it works fine. If I use a parameterised query:

      int size=44;

      session << "INSERT INTO TableName VALUES(:size)", use(size), now;

      it throws an exception. The table contains a single int column. Any suggestions gratefully received!

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      viaducting wrote:

      session << "INSERT INTO TableName VALUES(:size)", use(size), now;

      Read up on parameterised queries, I don't recognise this syntax, it look like you are trying to insert the text "size" into the int field. Sorry, just realised the POCO thingy may support that syntax. I suggest you chase this down using their support, this is not a problem with sql server but the POCO library.

      Never underestimate the power of human stupidity RAH

      H 1 Reply Last reply
      0
      • H hairy_hats

        Hi all, I'm using POCO[^] ODBC libraries to access SQL Server 2005, and have hit a problem. If I enter a plain text statement:

        session << "INSERT INTO TableName VALUES(44)", now;

        it works fine. If I use a parameterised query:

        int size=44;

        session << "INSERT INTO TableName VALUES(:size)", use(size), now;

        it throws an exception. The table contains a single int column. Any suggestions gratefully received!

        D Offline
        D Offline
        dasblinkenlight
        wrote on last edited by
        #3

        Could you give more details on the exception that you are getting? Is it coming from POCO or from the DB? The code appears lifted straight from the POCO example book - the only difference is that you use an int, while they use a string. Assuming that their example works, and that you also use SQLite, there's only a small number of places where you could get an error. First thing I would try is specifying the list of column names: INSERT INTO TableName (myIntColumn) VALUES(:size): the single-column syntax looks suspicious. Then I'd look at the error coming back, and try to decipher it.

        1 Reply Last reply
        0
        • M Mycroft Holmes

          viaducting wrote:

          session << "INSERT INTO TableName VALUES(:size)", use(size), now;

          Read up on parameterised queries, I don't recognise this syntax, it look like you are trying to insert the text "size" into the int field. Sorry, just realised the POCO thingy may support that syntax. I suggest you chase this down using their support, this is not a problem with sql server but the POCO library.

          Never underestimate the power of human stupidity RAH

          H Offline
          H Offline
          hairy_hats
          wrote on last edited by
          #4

          That was it - it supports the ? syntax but fell over on the :name syntax, but only the :name syntax is in their documentation. :doh:

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups