Solved

mysql upgrade causing C++ code NOT to work

Posted on 2006-07-21
12
385 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
Comment Utility
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
Comment Utility
>>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
Comment Utility
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
 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 17

Assisted Solution

by:rstaveley
rstaveley earned 230 total points
Comment Utility
> 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
Comment Utility
>>>> "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
Comment Utility
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
Comment Utility
>>>> 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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now