# HG changeset patch # User melunko # Date 1168465644 0 # Node ID 86e15690a1048dd81b6bfa7faf2393337784d85b # Parent 7776e35d59d4d4c23e973202665dbeae33ef44b7 [svn r258] Added gmyth_query and gmyth_scheduler connection methods with timeout. Besides, configura.ac now checks libmysqlclient in the right way diff -r 7776e35d59d4 -r 86e15690a104 gmyth/configure.ac --- a/gmyth/configure.ac Wed Jan 10 20:52:55 2007 +0000 +++ b/gmyth/configure.ac Wed Jan 10 21:47:24 2007 +0000 @@ -196,42 +196,17 @@ # # mysql libraries # -MYSQL_CFLAGS="$CFLAGS -DBIG_JOINS=1" -MYSQL_LIBS="$LIBS -L/usr/lib" +AC_CHECK_PROG(MYSQL_CFLAGS,mysql_config,`mysql_config --cflags`) +if test -z "$MYSQL_CFLAGS"; then + AC_MSG_ERROR([Could not find mysql_config script. Make sure the mysql client libraries are installed]) +fi +AC_SUBST(MYSQL_CFLAGS) -AC_CHECK_LIB( mysqlclient, mysql_init, - [ - MYSQL_CFLAGS="$MYSQL_CFLAGS -DBIG_JOINS=1" - MYSQL_LIBS="$MYSQL_LIBS -lmysqlclient" - ], AC_MSG_ERROR([Could not find mysqlclient library. Make sure the mysql client libraries are installed] ) ) -AC_CHECK_LIB( z, deflate, - [ - MYSQL_LIBS="$MYSQL_LIBS -lz" - ], AC_MSG_WARN([Could not find a mysqlclient library dependency - Z. Make sure the mysql client libraries are installed]) ) - -AC_CHECK_LIB( crypt, encrypt, - [ - MYSQL_LIBS="$MYSQL_LIBS -lcrypt" - ], AC_MSG_WARN([Could not find a mysqlclient library dependency - Crypt library. Make sure the mysql client libraries are installed]) ) - -AC_CHECK_LIB( nsl, yp_all, - [ - MYSQL_LIBS="$MYSQL_LIBS -lnsl" - ], AC_MSG_WARN([Could not find a mysqlclient library dependency - NSL library. Make sure the mysql client libraries are installed]) ) - -AC_CHECK_LIB( m, ccos, - [ - MYSQL_LIBS="$MYSQL_LIBS -lm" - ], AC_MSG_WARN([Could not find a mysqlclient library dependency - M library. Make sure the mysql client libraries are installed]) ) - -AC_CHECK_HEADERS( [mysql/mysql.h mysql/mysql_version.h], [ AC_MSG_NOTICE([Found MySQL headers!]) ], - [ AC_MSG_WARN([Could not find mysqlclient headers, but it will work fine instead of this...]) ], - [ - #include - ]) - -AC_SUBST(MYSQL_CFLAGS) +AC_CHECK_PROG(MYSQL_LIBS,mysql_config,`mysql_config --libs`) +if test -z "$MYSQL_LIBS"; then + AC_MSG_ERROR([Could not find mysql_config script. Make sure the mysql client libraries are installed]) +fi AC_SUBST(MYSQL_LIBS) #dnl Enable gtk-doc diff -r 7776e35d59d4 -r 86e15690a104 gmyth/src/gmyth_query.c --- a/gmyth/src/gmyth_query.c Wed Jan 10 20:52:55 2007 +0000 +++ b/gmyth/src/gmyth_query.c Wed Jan 10 21:47:24 2007 +0000 @@ -65,6 +65,7 @@ /* initialize connection handler */ gmyth_query->conn = mysql_init (NULL); + if (!(gmyth_query->conn)) g_warning ("[%s] MSQL structure not initialized", __FUNCTION__); @@ -104,6 +105,21 @@ return sql_query; } +gboolean +gmyth_query_connect_with_timeout (GMythQuery *gmyth_query, + GMythBackendInfo *backend_info, guint timeout) +{ + assert(gmyth_query); + g_return_val_if_fail (gmyth_query->conn != NULL, FALSE); +printf ("XXXXXXXXX timeout %d\n", timeout); + if (timeout != 0) { + /* sets connection timeout */ + mysql_options (gmyth_query->conn, MYSQL_OPT_CONNECT_TIMEOUT, (gchar*) &timeout); + } + + return gmyth_query_connect (gmyth_query, backend_info); +} + /** Connects to the Mysql database in the backend. The backend address * is loaded from the GMythBackendInfo instance. * diff -r 7776e35d59d4 -r 86e15690a104 gmyth/src/gmyth_query.h --- a/gmyth/src/gmyth_query.h Wed Jan 10 20:52:55 2007 +0000 +++ b/gmyth/src/gmyth_query.h Wed Jan 10 21:47:24 2007 +0000 @@ -77,6 +77,8 @@ (GMythQuery *gmyth_query, gchar *stmt_str); gboolean gmyth_query_connect (GMythQuery *gmyth_query, GMythBackendInfo *backend_info); +gboolean gmyth_query_connect_with_timeout (GMythQuery *gmyth_query, + GMythBackendInfo *backend_info, guint timeout); gboolean gmyth_query_disconnect (GMythQuery *gmyth_query); G_END_DECLS diff -r 7776e35d59d4 -r 86e15690a104 gmyth/src/gmyth_scheduler.c --- a/gmyth/src/gmyth_scheduler.c Wed Jan 10 20:52:55 2007 +0000 +++ b/gmyth/src/gmyth_scheduler.c Wed Jan 10 21:47:24 2007 +0000 @@ -134,6 +134,12 @@ return scheduler; } +gboolean +gmyth_scheduler_connect (GMythScheduler *scheduler, GMythBackendInfo *backend_info) +{ + return gmyth_scheduler_connect_with_timeout (scheduler, backend_info, 0); +} + /** Connects to the Mysql database in the backend. The backend address * is loaded from the GMythSettings instance. * @@ -141,7 +147,8 @@ * @return true if connection was success, false if failed. */ gboolean -gmyth_scheduler_connect (GMythScheduler *scheduler, GMythBackendInfo *backend_info) +gmyth_scheduler_connect_with_timeout (GMythScheduler *scheduler, + GMythBackendInfo *backend_info, guint timeout) { assert(scheduler); g_return_val_if_fail (backend_info != NULL, FALSE); @@ -154,7 +161,8 @@ scheduler->msqlquery = gmyth_query_new (); } - if (!gmyth_query_connect(scheduler->msqlquery, scheduler->backend_info)) { + if (!gmyth_query_connect_with_timeout (scheduler->msqlquery, + scheduler->backend_info, timeout)) { g_warning ("[%s] Error while connecting to db", __FUNCTION__); return FALSE; } diff -r 7776e35d59d4 -r 86e15690a104 gmyth/src/gmyth_scheduler.h --- a/gmyth/src/gmyth_scheduler.h Wed Jan 10 20:52:55 2007 +0000 +++ b/gmyth/src/gmyth_scheduler.h Wed Jan 10 21:47:24 2007 +0000 @@ -136,6 +136,8 @@ GMythScheduler* gmyth_scheduler_new (); gboolean gmyth_scheduler_connect (GMythScheduler *scheduler, GMythBackendInfo *backend_info); +gboolean gmyth_scheduler_connect_with_timeout (GMythScheduler *scheduler, + GMythBackendInfo *backend_info, guint timeout); gboolean gmyth_scheduler_disconnect (GMythScheduler *scheduler); gint gmyth_scheduler_get_schedule_list (GMythScheduler *scheduler, diff -r 7776e35d59d4 -r 86e15690a104 gmyth/tests/gmyth_test_connection.c --- a/gmyth/tests/gmyth_test_connection.c Wed Jan 10 20:52:55 2007 +0000 +++ b/gmyth/tests/gmyth_test_connection.c Wed Jan 10 21:47:24 2007 +0000 @@ -25,7 +25,7 @@ { GMythQuery *query = gmyth_query_new (); - if (gmyth_query_connect (query, backend_info) == TRUE) { + if (gmyth_query_connect_with_timeout (query, backend_info, 3) == TRUE) { g_debug ("Mysql connection success"); return TRUE; } else { @@ -47,9 +47,8 @@ backend_info = gmyth_backend_info_new_with_uri (argv[1]); + test_mysql_connection1 (backend_info); test_backend_connection1 (backend_info); - - test_mysql_connection1 (backend_info); }