Solved

mysql upgrade causing C++ code NOT to work

Posted on 2006-07-21
12
387 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 86

Accepted Solution

by:
jkr earned 250 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 230 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 20 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 230 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

808 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