Hi all,
* Warren Young <mysqlpp@stripped> [080724 16:44]:
>
>> However now I want to use mysql procedures in my queries so I added
>> c.set_option(new mysqlpp::MultiResultsOption( true ) );
>> before tue c.connect() call. However, after doing this I found
>> that I am unable to connect to the database unless I explicitly define
>> all of server, user, password (and maybe port).
>
> I don't see why that would be the case. Options are processed
> immediately in set_option(), and they don't affect the connect() call's
> behavior.
Hmm strange.
> I suggest that you enable (and catch) exceptions, since they can
> indicate problems better, and get the problem distilled down to a single
> line's difference: a program that connects fine with the default options
> when the MultiResultsOption line is commented out, and fails with it
> enabled. You may want to do this to one of the examples, rather than to
> your own program, because they're known to be correct.
Actually, except for the exceptions, I'd already done this.
> If it still fails in that case, post the text of any exceptions you get.
Here it is with exception handling.
#include "mysql++.h"
int main(int argc, char *argv[])
{
const char* db = "connectfail";
const char* server = 0;
const char* user = 0;
const char* password = 0;
unsigned int port = 0;
if ( argc > 2 ) {
std::cout << "Explicitly setting varaiables." << std::endl;
server = "localhost";
user = "hastings";
password = "foobar";
port = 3306;
}
try {
mysqlpp::Connection c(true);
if ( argc > 1 ) {
std::cout << "Setting MultiResultsOption" <<
std::endl;
c.set_option(new mysqlpp::MultiResultsOption(true));
}
c.connect( db, server, user, password, port );
}
catch (const mysqlpp::Exception& er) {
std::cerr << "Error: " << er.what() << std::endl;
exit(0);
}
std::cout << "Connected ok." << std::endl;
}
Here is a transcript from my shell:
% mysqladmin create connectfail
% g++ -o connectfail connectfail.cc -I/usr/include/mysql++ -I/usr/include/mysql -lmysqlpp
$ ./connectfail
Connected ok.
$ ./connectfail foo
Setting MultiResultsOption
Error: Access denied for user 'hastings'@'localhost' (using password: NO)
$ ./connectfail foo bar
Explicitly setting varaiables.
Setting MultiResultsOption
Connected ok.
I also ran the above under strace, and it seems that .my.cnf is never
read when MultiResultsOption is not set.
I wonder if anyone can reproduce this?
Thanks again,
Nick.