List:MySQL++« Previous MessageNext Message »
From:Andrew Sayers Date:May 17 2007 5:14pm
Subject:Bug: program dies with untrue error message for template query
View as plain text  
Apologies if this is the wrong place to send bug reports - I couldn't
find any hints about where to post this on the mysql++ web page or
README file.

When running the program below, mysql++ throws an exception to the
specified query if the query parameter is set as %0, but not if it's set
as %1.  The output of the program looks like this:

$ g++ -I/usr/include/mysql/ -I/usr/local/include/mysql++/ -lmysqlpp breaks_mysqlpp.cpp
&& ./a.out ; echo $?
Running query with item=%1... SELECT * FROM stock where item = "Pickle Relish"...OK
Running query with item=%0... SELECT * FROM stock where item = "Pickle Relish"...terminate
called after throwing an instance of 'mysqlpp::BadQuery'
  what():  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 'SELECT * FROM stock where item =
"Pickle Relish"' at line 1

The contents of breaks_mysqlpp.cpp is:

#include <mysql++.h>
#include "mysql_password.hpp"

void run_query(int item) {
  mysqlpp::Connection con("mysql_cpp_data", "localhost", mysql_username, mysql_password);
  mysqlpp::Query query = con.query();
  query << "SELECT * FROM stock where item = %" << item << ":item";
  query.def["item"] = mysqlpp::SQLString("\"Pickle Relish\"");
  std::cout << query.str() << "..." << std::flush;

int main() {
  std::cout << "Running query with item=%1... " << std::flush;
  std::cout << "OK" << std::endl;

  std::cout << "Running query with item=%0... " << std::flush;
  std::cout << "OK" << std::endl;

  return 0;

mysql_password.hpp defines mysql_username and mysql_password, which I'd
rather not post to a public mailing list :)

I realise this is quite a contrived example - the actual program I'm
working on needs to do queries where the number of parameters
isn't known until run-time, and every way of doing that which I can
think of runs into a version of this bug.

Obviously, the program should do the same thing for both calls to the
program.  The workaround is to skip %0 in queries that trigger this bug.

	- Andrew Sayers
Bug: program dies with untrue error message for template queryAndrew Sayers17 May
  • Re: Bug: program dies with untrue error message for template queryWarren Young17 May
Re: Bug: program dies with untrue error message for template queryAndrew Sayers18 May