Parameterised SQL Insert fails; plain text Insert works
-
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! -
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!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
-
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!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. -
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
That was it - it supports the
?
syntax but fell over on the:name
syntax, but only the:name
syntax is in their documentation. :doh: