Hello, I am experiencing seg faults in seemingly innocent code with MySQL version 4.0.0 and the embedded library, libmysqld. The fault only happens when calling particular functions, specifically mysql_ping() and mysql_query(). There might be others, but these are the only ones I've found so far.
Following is the code: /* * A simple example client, using the embedded MySQL server library */ #include <mysql.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> MYSQL * db_connect(); void db_disconnect(MYSQL *db); void db_query(MYSQL *db, const char *SQL); static char *server_groups[] = { "test_client_SERVER", "server", NULL }; int main( int argc, char **argv) { MYSQL *mysqldb; mysql_server_init(argc, argv, server_groups); mysqldb = db_connect(); /* grab some server information */ fprintf ( stderr, "host info: %s\n", mysql_get_host_info(mysqldb) ); fprintf ( stderr, "server info: %s\n", mysql_get_server_info(mysqldb) ); fprintf ( stderr, "protocol info: %d\n", mysql_get_proto_info(mysqldb) ); /* SEGFAULT HAPPENS HERE */ mysql_ping(mysqldb); /* IF I TAKE OUT THE MYSQL_PING, SEGFAULT HAPPENS HERE */ mysql_query ( mysqldb, "SHOW TABLE STATUS" ); mysql_close( mysqldb ); mysql_server_end(); exit (0); } MYSQL * db_connect() { MYSQL *db = mysql_init(NULL); if (!db) fprintf ( stderr, "mysql_init failed: no memory.\n" ); fprintf ( stderr, "calling mysql_real_connect(): " ); if ( ! mysql_real_connect(db, NULL, NULL, NULL, NULL, 0, NULL, 0) ) fprintf ( stderr, "FAILURE: %s\n", mysql_error(db) ); else fprintf ( stderr, "SUCCESS\n" ); return db; } void db_query(MYSQL *db, const char *SQL) { int result; fprintf ( stderr, "calling mysql_query(): " ); result = mysql_query (db, SQL ); if ( result == 0 ) fprintf ( stderr, "SUCCESS\n" ); else fprintf ( stderr, "FAILURE: %s\n", mysql_error(db) ); fprintf ( stderr, "result code: %d\n", result ); } void db_disconnect(MYSQL *db) { mysql_close(db); } The client seems to init the database okay, and it seems to connect okay, and it even gathers information with the mysql_get_server_info, mysql_get_proto_info and mysql_get_host info calls, but then mysteriously seg faults at the mysql_ping or the mysql_query. If anyone can spot any glaring mistakes in the code that might be the cause of this, please let me know. I compile the code with the following command: gcc -g -W -Wall -D_THREAD_SAFE -D_REENTRANT -I/usr/include/mysql mysql.c -L/usr/lib/mysql -static -lmysqld -lpthread -lz -lcrypt -lnsl -lm -lrt -o mysql Greg Kurzawa [EMAIL PROTECTED] [EMAIL PROTECTED] --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php