mysql upgrade causing C++ code NOT to work

I have C++ code(on a SuSE 9.0 machine, machine A) which talks to a mysql database using mysql++ libraries. The following is used:

mysql server version 4.0.15
mysql++-1.7.12

Now I needed to migrate this code to a machine B(running SuSE 10.0) with the following installed:
mysql server version 5.0.18

First of all the executable didn't work straightaway 'cause it couldn't find some requisite runtime libraries. Then I tried to recompile the code with mysql++-2.1.1 on machine B thinking it would solve the problem, but it gave me compiling errors like:

error: ambiguous overload for operator[] in row[0]
/usr/local/include/mysql++/row.h:119: note: candidates are: const mysqlpp::ColData mysqlpp::Row::operator[](const char*) const

...and this for identical code that was compiling perfectly on the earlier version on mysql++. Anyway, disgusted with this, I thought it was best to statically link the mysql++ libraries while recompiling the code on machine A, and then transfer the (bigger) executable to machine B. All seemed ok, until I got the following runtime error:

Bad Query Error: Client does not support authentication protocol requested by server; consider upgrading MySQL client

This error is thrown each time a query is executed within the code!!

Could anyone tell me 2 things:
1.) Why doesn't the code compile correctly with the newer version of mysql++ and
2.) How do I fix the last error

Any other idea to get the code migration to work would be welcome!!!




sandeep_thAsked:
Who is Participating?
 
jkrCommented:
Actually, the recompile shouldn't be necessary if you follow the instructions in http://dev.mysql.com/doc/refman/5.0/en/old-client.html
0
 
jkrCommented:
Check out http://dev.mysql.com/doc/refman/5.0/en/old-client.html ("A.2.3. Client does not support authentication protocol") on this issue, that might help to remedy this problem.
0
 
jkrCommented:
>>1.) Why doesn't the code compile correctly with the newer version of mysql++

They must have changed not only the version number, but also the source code ;o)

Seriously, without any code, it is hard to tell what exactly is going wrong, but "ambiguous overload for operator[]" is a bang on error description.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
sandeep_thAuthor Commented:
They seemed to changed the code indeed!!! There used to be a member function error() in the class BadQuery, but suddenly it doesn't exist any more!!!

The following is the code which threw the above error:
    331                         Row row;
    332                         Result::iterator i;
    333
    334                         i=res.begin();
    335                         row= *i;
    336                         cust_id = row[0].c_str();
    337                         cust_company = row[1].c_str();
    338                         cust_title = row[2].c_str();

It worked perfectly well before; but now when I compile, it says:
cont.cpp:336: error: ambiguous overload for operator[] in row[0]
/usr/local/include/mysql++/row.h:119: note: candidates are: const mysqlpp::ColData mysqlpp::Row::operator[](const char*) const

0
 
sandeep_thAuthor Commented:
Bingo!!!! Using the

mysql>SET PASSWORD FOR
    -> 'some_user'@'some_host' = OLD_PASSWORD('newpwd')

on machine B worked!! That was the problem!!

Why the old code won't recompile with the new version of mysql++, only tangentsoft (the guys who coded it) can answer.

Thanks for your inputs!! I wish other sections of the site worked as efficiently as the C++ area. I get my C++ queries answered(mostly) in a matter of minutes...whereas when I post a query on say the linux area, I can almost rest assured it won't be answered at all, let alone solved!!!

 
0
 
jkrCommented:
Well, the compiler cannot resolve the overload properly. Since it explicitly mentions 'const mysqlpp::ColData mysqlpp::Row::operator[](const char*) const', check out the discussion at http://www.mysqltalk.org/image-vp448838.html with the relevant part being

"you're passing 0. so the compiler has to decide: "hmm, passing a null-pointer to const char* or a
0 to unsigned int ??". perhaps this problem could be solved by creating an additional operator[] which
takes just a "const int", so that the compiler chooses that operator[] which could in turn call
operator[](unsigned int); how about this idea?"

Try to use

cust_id = row[(const int)0].c_str();
0
 
rstaveleyCommented:
> cust_id = row[(const int)0].c_str();

Eh? I use row[0U] with the Tangentsoft library with MySQL 5 to get the first row - i.e. I make it an unsigned int.

That (const int)0 cast would surely not work.
0
 
itsmeandnobodyelseCommented:
>>>> "hmm, passing a null-pointer to const char* or a 0 to unsigned int ??".

jkr was right though row[(const int)0] won't solve the problem but rstaveley's row[0u].

There eare two operator[] defined in class Row:

MYSQLPP_EXPORT const ColData  operator[] (const char *field) const
//  Get the value of a field given its name.

 
const ColData  operator[] (size_type i) const
//  Get the value of a field given its index.

and these were ambiguous if passing a constant int.

Seems like a poor class design ...

Regards, Alex


 
0
 
sandeep_thAuthor Commented:
Brilliant!! The unsigned int solution worked.

I think I got all my problems solved. Except one. There are no compile-time errors now. But when I run the program, it gives the following error:

An Exception Occured: end of results

I know it is a bit unfair asking this ('cause it is a separate mysql++ error), but since it might be related, I thought i should probably put it down here itself. Any ideas?

0
 
itsmeandnobodyelseCommented:
>>>> An Exception Occured: end of results

That's not much you give us ...

exceptions were thrown for example if some indices were wrong, e. g. if you say Row[2] but the table has only 2 columns.

You will need to debug the prog to see where and when the exception was thrown.

You can put the body of the function where it most likelely happens into a try - catch - block. In the catch branch you should set the break point. If you come there you either could evaluate the exception object or - maybe easier - narrow the try block till you found the wrong statement.

Regards, Alex
0
 
rstaveleyCommented:
Try this snippet from some of my code:
--------8<--------
      query       << "SELECT ....";
      mysqlpp::ResUse ru = query.use();
      try {
            while (mysqlpp::Row row = ru.fetch_row()) {
                  if ((businessId = atol(row[0U])) != 0)
                        break;
            }
      }
      catch (mysqlpp::EndOfResults) {            // End of matching domains
      }
      catch (mysqlpp::BadQuery& e) {
std::cerr << stamp << "Error: Bad query: " << e.what() << ": " << query.str() << std::endl;
            string err(e.what());
            if (err.find("MySQL server has gone away") != string::npos || err.find("Lost connection to MySQL server during query") != string::npos) {
                  /* ... reconnect to the database */
                  throw;
            }
      }
      catch (const std::exception&) {
            /* ... reconnect to the database */
            throw;
      }
--------8<--------

mysqlpp::EndOfResults gets thrown and you catch it. It isn't very elegant, but that's how you see the end of your results with this library.
0
 
sandeep_thAuthor Commented:
I went ahead with the statically linked libraries solution, 'cause it looked like I'd have to port a lot of code otherwise; but I know what you are getting at. You guys are fantastic!!

I can't help being peeved though at the fact  that old code doesn't work with a mysql++ upgrade. It isn't exactly a good advertisement for open source.

Thanks for all your help!!

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.