1

I'm a new user of mysql++ looking for some pointers (pun intended).

The problem: my update statement fails.

The connection is open. The previous statement that uses the connection works.

I'm sure the record I'm trying to update exists. I can see it with the mysql query tools. I'm sure CustomerId is correct.

     // declaration of the customer id
     uint32_t CustomerId;

Why does this fail to update?

   mysqlpp::Connection conn( true );
   try
   {
      if ( conn.connect( db_rw.Name, db_rw.Host, db_rw.User, db_rw.Password ) )
      {

         // *snip*  insert code here works fine.

         // this query fails
         mysqlpp::Query query = conn.query( "UPDATE customer SET AccountName=%2q, Active=%3, Password=%1 WHERE CustomerId=%0" );
         query.parse();
         mysqlpp::SQLQueryParms parms;
         parms.push_back( mysqlpp::sql_int( CustomerId ) );
         parms.push_back( mysqlpp::sql_blob( data, sizeof(data) ) ); //<- 16 byte binary blob
         parms.push_back( mysqlpp::sql_varchar( widget.AccountName->text().toAscii().data() ) );  // string
         parms.push_back( mysqlpp::sql_bool( widget.ActiveCheckBox->checkState() == Qt::Checked ? 1 : 0 ) );  // 
         mysqlpp::SimpleResult res = query.execute( parms );
      }
   }

If I turn off exceptions for the connection it fails silently (the result.info() method returns nothing).

if I turn exceptions on it seg faults when trying to convert to a string:

std::string Query::str(SQLQueryParms& p)
{
    if (!parse_elems_.empty()) {
        proc(p);
    }

    return sbuffer_.str();
}
1
  • The problem seems to be the binary blob. Is there a ssqls modifier to hex encode binary data? Commented Jul 14, 2011 at 0:14

2 Answers 2

1

Warren beat me to the answer on the mailing list, but for posterity:

BLOB data (Password) needs to be quoted and escaped.

Using an SSQLS instead of templated queries handles this automatically.

http://tangentsoft.net/mysql++/doc/html/userman/tutorial.html#id2776204

Sign up to request clarification or add additional context in comments.

1 Comment

Tut tut cross-posting. Thanks for mirroring the answer here, Chris.
1

There were several issues.

The library doesn't escape binary data correctly.

If the user associated with the connection does not have update permission then the library will crash instead of throwing an exception.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.