List:MySQL++« Previous MessageNext Message »
From:Jay Sprenkle Date:July 14 2011 2:45pm
Subject:Re: update fails... any suggestions?
View as plain text  
Since the problem seemed to be that the hex escaping was wrong I tried the
hex io manipulator from c++ streams.
The std::hex iomanip seems to do nothing. I wrote a function to change
binary into ASCII hex myself and used it instead.

The sql I get when I create the query is this:
UPDATE customer SET  Data=0x280DC9163A744885417E6F45CB8B3822,
AccountName='Dev2', Active=0 WHERE CustomerId=23

This sql executes and updates a row in MySql workbench but when I run it in
my program it seg faults. I assumed it was because I had my catch as:
   catch ( mysqlpp::Exception e )
and I should have had:
   catch ( mysqlpp::Exception& e )
but that makes no difference either.


Here's my code:

   mysqlpp::Connection conn( true );
   try
   {
      if ( conn.connect( db_rw.Name, db_rw.Host, db_rw.User, db_rw.Password
) )
      {
          // snip.  setup variables here

         std::string hexData = toHexString( data, sizeof(data) );

         mysqlpp::Query query = conn.query();
         query
            << "UPDATE customer SET "
            << " Data=0x" << hexData //mysqlpp::escape <<
mysqlpp::sql_blob(
data, sizeof(data) )
            << ", AccountName=" <<  mysqlpp::quote <<
widget.AccountName->text().toStdString()
            << ", Active=" << mysqlpp::sql_bool(
widget.ActiveCheckBox->checkState() == Qt::Checked ? 1 : 0 )
            << " WHERE CustomerId=" << mysqlpp::sql_int( CustomerId )
            ;
         std::string sql = query.str();
         widget.StatusLabel->setText( QString( sql.c_str() ) );
         // I checked the sql string here with a breakpoint

         // seg fault is here
         mysqlpp::SimpleResult res = query.execute();
         if ( ! res )
            widget.StatusLabel->setText( QString( res.info() ) );
   }
   catch ( mysqlpp::Exception& e )
   {
      std::string msg( "mysqlpp exception thrown: " );
      msg += e.what();
      widget.StatusLabel->setText( QString( msg.c_str() ) );
   }
   catch ( const mysqlpp::BadQuery& e )
   {
      std::string msg( "BadQuery exception thrown: " );
      msg += e.what();
      widget.StatusLabel->setText( QString( msg.c_str() ) );
   }
   catch ( const mysqlpp::BadConversion& e )
   {
      std::string msg( "Conversion exception thrown: " );
      msg += e.what();
      msg += ", retrieved data size: ";
      msg += toString<size_t>( e.retrieved );
      msg += ", actual data size: ";
      msg += toString<size_t>( e.actual_size );
      widget.StatusLabel->setText( QString( msg.c_str() ) );
   }
   catch( std::runtime_error& e )
   {
      std::string msg( "exception thrown: " );
      msg += e.what();
      widget.StatusLabel->setText( QString( msg.c_str() ) );
   }
   catch(...)
   {
      widget.StatusLabel->setText( QString( "unknown exception thrown" ) );
   }


Does anyone see anything obvious?

I'm using gcc on windows:

C:\>gcc --version
gcc (tdm-1) 4.5.2-dw2
Copyright (C) 2010 Free Software Foundation, Inc.





On Thu, Jul 14, 2011 at 6:38 AM, Jay Sprenkle <jsprenkle@stripped> wrote:

> I looked at the produced sql last night after getting an error that the
> escaped string was too long for the column.
> After looking at the mysql docs on binary escaping I was going to try this
> next:
>
>          std::string str( data, sizeof(data) );
>          std::ostringstream os( str );
>          os << std::hex << std::uppercase << str;
>          std::string hexData( os.str() );
>
>          mysqlpp::Query query = conn.query();
>          query
>             << "UPDATE customer SET "
>             << " Data=0x" << mysqlpp::quote << hexData
> //mysqlpp::escape <<
> mysqlpp::sql_blob( data, sizeof(data) )
>             << ", AccountName=" <<  mysqlpp::quote <<
> widget.AccountName->text().toStdString()
>             << ", Active=" << mysqlpp::sql_bool(
> widget.ActiveCheckBox->checkState() == Qt::Checked ? 1 : 0 )
>             << " WHERE CustomerId=" << mysqlpp::sql_int( CustomerId )
>             ;
>          std::string sql = query.str();
>
> I found last night that the ios::hex manipulator is not compatible with
> mysql++ query streams.
>
>
>
> On Thu, Jul 14, 2011 at 4:23 AM, Warren Young <mysqlpp@stripped> wrote:
>
>> On Jul 14, 2011, at 12:20 AM, Kemet wrote:
>>
>> > Once you have this in place, everything works great !
>>
>> I'm not certain this is the same thing.  The OP isn't using SSQLS and
>> sql_blob already is "NOT NULL".
>> --
>> MySQL++ Mailing List
>> For list archives: http://lists.mysql.com/plusplus
>> To unsubscribe:
>> http://lists.mysql.com/plusplus?unsub=1
>>
>>
>
>
> --
> ---
> "There's a zombie outbreak!  Oh, no, wait a second...  It's just a bunch of
> kids texting."
>



-- 
---
"There's a zombie outbreak!  Oh, no, wait a second...  It's just a bunch of
kids texting."

Thread
update fails... any suggestions?Jay Sprenkle13 Jul
  • Re: update fails... any suggestions?Warren Young13 Jul
    • Re: update fails... any suggestions?Jay Sprenkle13 Jul
      • Re: update fails... any suggestions?Warren Young13 Jul
        • Re: update fails... any suggestions?Warren Young13 Jul
        • Re: update fails... any suggestions?Jay Sprenkle13 Jul
          • Re: update fails... any suggestions?Kemet14 Jul
            • Re: update fails... any suggestions?Warren Young14 Jul
              • Re: update fails... any suggestions?Jay Sprenkle14 Jul
                • Re: update fails... any suggestions?Jay Sprenkle14 Jul
                  • Re: update fails... any suggestions?Jay Sprenkle14 Jul
                    • Re: update fails... any suggestions?Jay Sprenkle14 Jul
                      • Re: update fails... any suggestions?Warren Young15 Jul
                        • Re: update fails... any suggestions?Jay Sprenkle15 Jul