fixed several memory leaks caused by missing table_free calls
[NeonServV5.git] / src / mysqlConn.c
index 3c3a5a802e62d29b9c97415ad572cf7003de2128..529e8a4347f6ca26a824c4a551be937c2e68ac11 100644 (file)
  */
 
 #include "mysqlConn.h"
-#define DATABASE_VERSION "14"
+#define DATABASE_VERSION "15"
 
 struct mysql_conn_struct {
-    unsigned long tid;
+    unsigned int tid;
     MYSQL *mysql_conn;
     struct used_result *used_results;
     struct escaped_string *escaped_strings;
@@ -204,7 +204,7 @@ void free_mysql() {
 void show_mysql_error() {
     MYSQL *mysql_conn = get_mysql_conn();
     //show mysql_error()
-    printf("MySQL Error: %s\n", mysql_error(mysql_conn));
+    putlog(LOGLEVEL_ERROR, "MySQL Error: %s\n", mysql_error(mysql_conn));
 }
 
 void printf_mysql_query(const char *text, ...) {
@@ -218,7 +218,7 @@ void printf_mysql_query(const char *text, ...) {
     va_end(arg_list);
     if (pos < 0 || pos > (MYSQLMAXLEN - 2)) pos = MYSQLMAXLEN - 2;
     queryBuf[pos] = '\0';
-    printf("MySQL: %s\n", queryBuf);
+    putlog(LOGLEVEL_MYSQL, "MySQL: %s\n", queryBuf);
     if(mysql_query(mysql_conn, queryBuf)) {
         check_mysql();
         if(mysql_query(mysql_conn, queryBuf)) {
@@ -238,7 +238,7 @@ void printf_long_mysql_query(int len, const char *text, ...) {
     va_end(arg_list);
     if (pos < 0 || pos > (len - 2)) pos = len - 2;
     queryBuf[pos] = '\0';
-    printf("MySQL: %s\n", queryBuf);
+    putlog(LOGLEVEL_MYSQL, "MySQL: %s\n", queryBuf);
     if(mysql_query(mysql_conn, queryBuf)) {
         check_mysql();
         if(mysql_query(mysql_conn, queryBuf)) {
@@ -264,7 +264,12 @@ char* escape_string(const char *str) {
 struct mysql_conn_struct *get_mysql_conn_struct() {
     SYNCHRONIZE(synchronized);
     struct mysql_conn_struct *mysql_conn;
-    unsigned long tid = syscall(SYS_gettid);
+    unsigned int tid;
+    #ifdef HAVE_THREADS
+    tid = (unsigned int) pthread_self_tid();
+    #else
+    tid = 1;
+    #endif
     for(mysql_conn = mysql_conns; mysql_conn; mysql_conn = mysql_conn->next) {
         if(mysql_conn->tid == tid) {
             DESYNCHRONIZE(synchronized);