Problem with prepared statement

Please post support and help requests here.
crashtua
Posts: 8
Joined: 16 Aug 2012, 14:24

Problem with prepared statement

Postby crashtua » 17 Aug 2012, 19:07

I have following code:

Code: Select all

Statement stmt(*_pSession);
stmt << "INSERT INTO admins (botid,name,server) VALUES(:botid, :name, :server)", use(0), use("crashtua"), use("war3.alkar.net");

But it gives me
[Comment]: mysql_stmt_prepare error [mysql_stmt_error]: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':botid, :name, :server)' at line 1 [mysql_stmt_errno]: 1064 [mysql_stmt_sqlstate]: 42000 [statemnt]: INSERT INTO admins (botid,name,server) VALUES(:botid, :name, :server)

What is wrong with statement?

crashtua
Posts: 8
Joined: 16 Aug 2012, 14:24

Re: Problem with prepared statement

Postby crashtua » 17 Aug 2012, 19:33

Changed
VALUES(:botid, :name, :server)

on
VALUES(?, ?, ?)

But it gives unhandled exception on

Code: Select all

void StatementImpl::bind()
{
   if (_state == ST_COMPILED)
   {
      bindImpl();

alex
Posts: 1282
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: Problem with prepared statement

Postby alex » 17 Aug 2012, 21:41

Hard to tell without knowing more about what exactly are you doing, which POCO version you are using and where exactly is the exception thrown. Try this:

Code: Select all

Statement stmt(*_pSession);
std::string s1("crashtua"), s2("war3.alkar.net");
stmt << "INSERT INTO admins (botid,name,server) VALUES(:botid, :name, :server)", use(0), use(s1), use(s2);

and make sure s1 and s2 are available at the point where you are executing it.

crashtua
Posts: 8
Joined: 16 Aug 2012, 14:24

Re: Problem with prepared statement

Postby crashtua » 18 Aug 2012, 10:48

alex wrote:

Code: Select all

std::string s1("crashtua"), s2("war3.alkar.net");

and make sure s1 and s2 are available at the point where you are executing it.

Thats was the reason... use() with char array does not work... That's all right, but it cost me a lot of time... Thanks a lot!
how c++ is difficult after years of java:)


Return to “Support”

Who is online

Users browsing this forum: No registered users and 2 guests

cron