Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

mysql upgrade causing C++ code NOT to work

Posted on 2006-07-21
12
Medium Priority
?
399 Views
Last Modified: 2007-12-19
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!!!




0
Comment
Question by:sandeep_th
  • 4
  • 4
  • 2
  • +1
12 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 17156879
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
 
LVL 86

Expert Comment

by:jkr
ID: 17156928
>>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
 

Author Comment

by:sandeep_th
ID: 17157228
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 86

Accepted Solution

by:
jkr earned 1000 total points
ID: 17157344
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
 

Author Comment

by:sandeep_th
ID: 17157544
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
 
LVL 86

Expert Comment

by:jkr
ID: 17157683
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
 
LVL 17

Assisted Solution

by:rstaveley
rstaveley earned 920 total points
ID: 17158431
> 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
 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 80 total points
ID: 17169413
>>>> "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
 

Author Comment

by:sandeep_th
ID: 17169431
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
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 17169566
>>>> 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
 
LVL 17

Assisted Solution

by:rstaveley
rstaveley earned 920 total points
ID: 17169940
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
 

Author Comment

by:sandeep_th
ID: 17174405
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question