1.1 --- a/gmyth/gmyth/gmyth_query.c Sun Dec 13 21:21:32 2009 +0000
1.2 +++ b/gmyth/gmyth/gmyth_query.c Sun Dec 13 22:42:34 2009 +0000
1.3 @@ -31,7 +31,6 @@
1.4
1.5 #include <stdlib.h>
1.6 #include <stdio.h>
1.7 -#include <assert.h>
1.8
1.9 #include "gmyth_query.h"
1.10 #include "gmyth_debug.h"
1.11 @@ -74,10 +73,6 @@
1.12 {
1.13 GMythQuery *gmyth_query = GMYTH_QUERY(object);
1.14
1.15 - if (gmyth_query->conn != NULL) {
1.16 - gmyth_query_disconnect(gmyth_query);
1.17 - }
1.18 -
1.19 if (gmyth_query->backend_info) {
1.20 g_object_unref(gmyth_query->backend_info);
1.21 gmyth_query->backend_info = NULL;
1.22 @@ -89,7 +84,7 @@
1.23 static void
1.24 gmyth_query_finalize(GObject * object)
1.25 {
1.26 - g_signal_handlers_destroy(object);
1.27 + gmyth_query_disconnect(GMYTH_QUERY(object));
1.28
1.29 G_OBJECT_CLASS(gmyth_query_parent_class)->finalize(object);
1.30 }
1.31 @@ -112,7 +107,7 @@
1.32 GMythBackendInfo * backend_info,
1.33 guint timeout)
1.34 {
1.35 - assert(gmyth_query);
1.36 + g_return_val_if_fail(gmyth_query != NULL, FALSE);
1.37
1.38 if (gmyth_query->conn == NULL)
1.39 gmyth_query->conn = mysql_init(NULL);
1.40 @@ -138,7 +133,7 @@
1.41 gmyth_query_connect(GMythQuery * gmyth_query,
1.42 GMythBackendInfo * backend_info)
1.43 {
1.44 - assert(gmyth_query);
1.45 + g_return_val_if_fail(gmyth_query != NULL, FALSE);
1.46 g_return_val_if_fail(backend_info != NULL, FALSE);
1.47 g_return_val_if_fail(backend_info->hostname != NULL, FALSE);
1.48 g_return_val_if_fail(backend_info->username != NULL, FALSE);
1.49 @@ -186,6 +181,9 @@
1.50 {
1.51 g_return_val_if_fail (gmyth_query != NULL, FALSE);
1.52
1.53 + if (gmyth_query->conn == NULL)
1.54 + return FALSE;
1.55 +
1.56 return (mysql_ping (gmyth_query->conn) == 0);
1.57 }
1.58
1.59 @@ -199,7 +197,9 @@
1.60 gmyth_query_disconnect(GMythQuery * gmyth_query)
1.61 {
1.62 g_return_val_if_fail(gmyth_query != NULL, FALSE);
1.63 - g_return_val_if_fail(gmyth_query->conn != NULL, FALSE);
1.64 +
1.65 + if (gmyth_query->conn == NULL)
1.66 + return TRUE;
1.67
1.68 /*
1.69 * TODO: Check how to return error
1.70 @@ -242,15 +242,13 @@
1.71 MYSQL_RES*
1.72 gmyth_query_process_statement(GMythQuery * gmyth_query, char *stmt_str)
1.73 {
1.74 - assert(gmyth_query);
1.75 + g_return_val_if_fail(gmyth_query != NULL, NULL);
1.76
1.77 gmyth_debug("[%s] Running mysql query %s", __FUNCTION__, stmt_str);
1.78
1.79 - if (gmyth_query == NULL)
1.80 - return NULL;
1.81 -
1.82 //the statement failed
1.83 - if (mysql_query(gmyth_query->conn, stmt_str) != 0) {
1.84 + if (gmyth_query->conn == NULL ||
1.85 + mysql_query(gmyth_query->conn, stmt_str) != 0) {
1.86 gmyth_query_print_error(gmyth_query->conn,
1.87 "Could not execute statement");
1.88 return NULL;
1.89 @@ -264,17 +262,15 @@
1.90 gmyth_query_process_statement_with_increment(GMythQuery * gmyth_query,
1.91 char *stmt_str, gulong * id)
1.92 {
1.93 - assert(gmyth_query);
1.94 + g_return_val_if_fail(gmyth_query != NULL, NULL);
1.95
1.96 gmyth_debug("[%s] Running mysql query %s", __FUNCTION__, stmt_str);
1.97
1.98 - if (gmyth_query == NULL)
1.99 - return NULL;
1.100 -
1.101 /*
1.102 * the statement failed
1.103 */
1.104 - if (mysql_query(gmyth_query->conn, stmt_str) != 0) {
1.105 + if (gmyth_query->conn == NULL ||
1.106 + mysql_query(gmyth_query->conn, stmt_str) != 0) {
1.107 gmyth_query_print_error(gmyth_query->conn,
1.108 "Could not execute statement");
1.109 return NULL;