[PATCH] Re: [PATCH] MySQL Escape String (another one)

Alexander Malysh <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
and there is a patch that adds handling of bind vars for mysql but  
require mysql version >= 4.1

Thanks,
Alex




Am 07.08.2009 um 14:13 schrieb Alexander Malysh:

> Hi,
>
> escpaing have to be done with DB connection otherwise it's just  
> impossible ro escape (think about different charsets).
>
> But if we drop support for mysql < 4.1 then I'm -1 for this patch  
> because we can use prepared statements that don't require
> escaping.
>
> If we decide to drop mysql support < 4.1 then I can provide patch  
> for prepared statements.
>
> Thanks,
> Alex
>
> Am 07.08.2009 um 13:42 schrieb Alejandro Guerrieri:
>
>> I don't particularly like the idea of loading the DB for something  
>> as simple as escaping a few special chars. Adding a bool variable  
>> would only add complexity.
>>
>> Regards,
>> --
>> Alejandro Guerrieri
>> [email protected]
>>
>>
>>
>> On 07/08/2009, at 13:30, Vincent CHAVANIS wrote:
>>
>>>
>>> I'm +0 for this patch as it.
>>>
>>> There will be a compatibility breaker with Mysql < 4
>>> as the mysql_real_escape_string as been implemented in mysql 4.
>>> We already had this discussion 4 years back with the stipe's patch.
>>> (http://www.mail-archive.com/[email protected]/msg05072.html)
>>> This was mainly reject by this, but we are now in 2009 :-)
>>> hopping everyone have updated their mysql version.
>>>
>>> IMO, The idea would be to implement a new bool config variable
>>> to use or not the mysql_real_escape_string() function.
>>>
>>> BTW, we may all know that this function will use a connection to  
>>> the DB
>>> and by consequences will load the Mysql server.
>>>
>>> Vincent.
>>>
>>>
>>> Donald Jackson a écrit :
>>>> Hi everyone,
>>>> Just posting this patch in case anyone wants to use it. It  
>>>> escapes the source address string to make it MySQL safe on the  
>>>> connection.
>>>> In hindsight possibly not perfect implementation but it does the  
>>>> job.
>>>> Thanks,
>>>> -- 
>>>> Donald Jackson
>>>> http://www.ddj.co.za/
>>>> donaldjster(a)gmail.com <http://gmail.com>
>>>
>>>
>>
>>
>
mysql-prepared.patch (application/octet-stream, 41.2 KB)
diff --git a/aclocal.m4 b/aclocal.m4
index 14f6054..5a35f95 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -1,7 +1,7 @@
-# generated automatically by aclocal 1.9.6 -*- Autoconf -*-
+# generated automatically by aclocal 1.10.2 -*- Autoconf -*-
 
 # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-# 2005  Free Software Foundation, Inc.
+# 2005, 2006, 2007, 2008  Free Software Foundation, Inc.
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
@@ -224,8 +224,8 @@ test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH])
 AC_LIB_PROG_LD_GNU
 ])
 
-# lib-link.m4 serial 8 (gettext-0.15)
-dnl Copyright (C) 2001-2006 Free Software Foundation, Inc.
+# lib-link.m4 serial 6 (gettext-0.14.3)
+dnl Copyright (C) 2001-2005 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
@@ -352,7 +352,6 @@ dnl the libraries corresponding to explicit and implicit dependencies.
 dnl Sets the LIB${NAME}, LTLIB${NAME} and INC${NAME} variables.
 AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
 [
-  AC_REQUIRE([AC_LIB_PREPARE_MULTILIB])
   define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
                                [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
   dnl By default, look in $includedir and $libdir.
@@ -375,7 +374,7 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
         ])
       else
         additional_includedir="$withval/include"
-        additional_libdir="$withval/$acl_libdirstem"
+        additional_libdir="$withval/lib"
       fi
     fi
 ])
@@ -475,7 +474,7 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
               dnl Linking with a shared library. We attempt to hardcode its
               dnl directory into the executable's runpath, unless it's the
               dnl standard /usr/lib.
-              if test "$enable_rpath" = no || test "X$found_dir" = "X/usr/$acl_libdirstem"; then
+              if test "$enable_rpath" = no || test "X$found_dir" = "X/usr/lib"; then
                 dnl No hardcoding is needed.
                 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
               else
@@ -561,8 +560,8 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
             dnl Assume the include files are nearby.
             additional_includedir=
             case "$found_dir" in
-              */$acl_libdirstem | */$acl_libdirstem/)
-                basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem/"'*$,,'`
+              */lib | */lib/)
+                basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e 's,/lib/*$,,'`
                 additional_includedir="$basedir/include"
                 ;;
             esac
@@ -623,9 +622,9 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
                     dnl   3. if it's already present in $LDFLAGS or the already
                     dnl      constructed $LIBNAME,
                     dnl   4. if it doesn't exist as a directory.
-                    if test "X$additional_libdir" != "X/usr/$acl_libdirstem"; then
+                    if test "X$additional_libdir" != "X/usr/lib"; then
                       haveit=
-                      if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem"; then
+                      if test "X$additional_libdir" = "X/usr/local/lib"; then
                         if test -n "$GCC"; then
                           case $host_os in
                             linux* | gnu* | k*bsd*-gnu) haveit=yes;;
@@ -779,83 +778,7 @@ AC_DEFUN([AC_LIB_APPENDTOVAR],
   done
 ])
 
-dnl For those cases where a variable contains several -L and -l options
-dnl referring to unknown libraries and directories, this macro determines the
-dnl necessary additional linker options for the runtime path.
-dnl AC_LIB_LINKFLAGS_FROM_LIBS([LDADDVAR], [LIBSVALUE], [USE-LIBTOOL])
-dnl sets LDADDVAR to linker options needed together with LIBSVALUE.
-dnl If USE-LIBTOOL evaluates to non-empty, linking with libtool is assumed,
-dnl otherwise linking without libtool is assumed.
-AC_DEFUN([AC_LIB_LINKFLAGS_FROM_LIBS],
-[
-  AC_REQUIRE([AC_LIB_RPATH])
-  AC_REQUIRE([AC_LIB_PREPARE_MULTILIB])
-  $1=
-  if test "$enable_rpath" != no; then
-    if test -n "$hardcode_libdir_flag_spec" && test "$hardcode_minus_L" = no; then
-      dnl Use an explicit option to hardcode directories into the resulting
-      dnl binary.
-      rpathdirs=
-      next=
-      for opt in $2; do
-        if test -n "$next"; then
-          dir="$next"
-          dnl No need to hardcode the standard /usr/lib.
-          if test "X$dir" != "X/usr/$acl_libdirstem"; then
-            rpathdirs="$rpathdirs $dir"
-          fi
-          next=
-        else
-          case $opt in
-            -L) next=yes ;;
-            -L*) dir=`echo "X$opt" | sed -e 's,^X-L,,'`
-                 dnl No need to hardcode the standard /usr/lib.
-                 if test "X$dir" != "X/usr/$acl_libdirstem"; then
-                   rpathdirs="$rpathdirs $dir"
-                 fi
-                 next= ;;
-            *) next= ;;
-          esac
-        fi
-      done
-      if test "X$rpathdirs" != "X"; then
-        if test -n ""$3""; then
-          dnl libtool is used for linking. Use -R options.
-          for dir in $rpathdirs; do
-            $1="${$1}${$1:+ }-R$dir"
-          done
-        else
-          dnl The linker is used for linking directly.
-          if test -n "$hardcode_libdir_separator"; then
-            dnl Weird platform: only the last -rpath option counts, the user
-            dnl must pass all path elements in one option.
-            alldirs=
-            for dir in $rpathdirs; do
-              alldirs="${alldirs}${alldirs:+$hardcode_libdir_separator}$dir"
-            done
-            acl_save_libdir="$libdir"
-            libdir="$alldirs"
-            eval flag=\"$hardcode_libdir_flag_spec\"
-            libdir="$acl_save_libdir"
-            $1="$flag"
-          else
-            dnl The -rpath options are cumulative.
-            for dir in $rpathdirs; do
-              acl_save_libdir="$libdir"
-              libdir="$dir"
-              eval flag=\"$hardcode_libdir_flag_spec\"
-              libdir="$acl_save_libdir"
-              $1="${$1}${$1:+ }$flag"
-            done
-          fi
-        fi
-      fi
-    fi
-  fi
-  AC_SUBST([$1])
-])
-
-# lib-prefix.m4 serial 5 (gettext-0.15)
+# lib-prefix.m4 serial 4 (gettext-0.14.2)
 dnl Copyright (C) 2001-2005 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -881,7 +804,6 @@ AC_DEFUN([AC_LIB_PREFIX],
   AC_BEFORE([$0], [AC_LIB_LINKFLAGS])
   AC_REQUIRE([AC_PROG_CC])
   AC_REQUIRE([AC_CANONICAL_HOST])
-  AC_REQUIRE([AC_LIB_PREPARE_MULTILIB])
   AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
   dnl By default, look in $includedir and $libdir.
   use_additional=yes
@@ -903,7 +825,7 @@ AC_DEFUN([AC_LIB_PREFIX],
         ])
       else
         additional_includedir="$withval/include"
-        additional_libdir="$withval/$acl_libdirstem"
+        additional_libdir="$withval/lib"
       fi
     fi
 ])
@@ -945,7 +867,7 @@ AC_DEFUN([AC_LIB_PREFIX],
     dnl   2. if it's already present in $LDFLAGS,
     dnl   3. if it's /usr/local/lib and we are using GCC on Linux,
     dnl   4. if it doesn't exist as a directory.
-    if test "X$additional_libdir" != "X/usr/$acl_libdirstem"; then
+    if test "X$additional_libdir" != "X/usr/lib"; then
       haveit=
       for x in $LDFLAGS; do
         AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
@@ -955,7 +877,7 @@ AC_DEFUN([AC_LIB_PREFIX],
         fi
       done
       if test -z "$haveit"; then
-        if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem"; then
+        if test "X$additional_libdir" = "X/usr/local/lib"; then
           if test -n "$GCC"; then
             case $host_os in
               linux*) haveit=yes;;
@@ -1010,35 +932,4 @@ AC_DEFUN([AC_LIB_WITH_FINAL_PREFIX],
   prefix="$acl_save_prefix"
 ])
 
-dnl AC_LIB_PREPARE_MULTILIB creates a variable acl_libdirstem, containing
-dnl the basename of the libdir, either "lib" or "lib64".
-AC_DEFUN([AC_LIB_PREPARE_MULTILIB],
-[
-  dnl There is no formal standard regarding lib and lib64. The current
-  dnl practice is that on a system supporting 32-bit and 64-bit instruction
-  dnl sets or ABIs, 64-bit libraries go under $prefix/lib64 and 32-bit
-  dnl libraries go under $prefix/lib. We determine the compiler's default
-  dnl mode by looking at the compiler's library search path. If at least
-  dnl of its elements ends in /lib64 or points to a directory whose absolute
-  dnl pathname ends in /lib64, we assume a 64-bit ABI. Otherwise we use the
-  dnl default, namely "lib".
-  acl_libdirstem=lib
-  searchpath=`(LC_ALL=C $CC -print-search-dirs) 2>/dev/null | sed -n -e 's,^libraries: ,,p' | sed -e 's,^=,,'`
-  if test -n "$searchpath"; then
-    acl_save_IFS="${IFS= 	}"; IFS=":"
-    for searchdir in $searchpath; do
-      if test -d "$searchdir"; then
-        case "$searchdir" in
-          */lib64/ | */lib64 ) acl_libdirstem=lib64 ;;
-          *) searchdir=`cd "$searchdir" && pwd`
-             case "$searchdir" in
-               */lib64 ) acl_libdirstem=lib64 ;;
-             esac ;;
-        esac
-      fi
-    done
-    IFS="$acl_save_IFS"
-  fi
-])
-
 m4_include([acinclude.m4])
diff --git a/configure b/configure
index ba67e8e..9a7ca62 100755
--- a/configure
+++ b/configure
@@ -8008,26 +8008,6 @@ fi
 
 
 
-                  acl_libdirstem=lib
-  searchpath=`(LC_ALL=C $CC -print-search-dirs) 2>/dev/null | sed -n -e 's,^libraries: ,,p' | sed -e 's,^=,,'`
-  if test -n "$searchpath"; then
-    acl_save_IFS="${IFS= 	}"; IFS=":"
-    for searchdir in $searchpath; do
-      if test -d "$searchdir"; then
-        case "$searchdir" in
-          */lib64/ | */lib64 ) acl_libdirstem=lib64 ;;
-          *) searchdir=`cd "$searchdir" && pwd`
-             case "$searchdir" in
-               */lib64 ) acl_libdirstem=lib64 ;;
-             esac ;;
-        esac
-      fi
-    done
-    IFS="$acl_save_IFS"
-  fi
-
-
-
 
 
 
@@ -8068,7 +8048,7 @@ if test "${with_libiconv_prefix+set}" = set; then
 
       else
         additional_includedir="$withval/include"
-        additional_libdir="$withval/$acl_libdirstem"
+        additional_libdir="$withval/lib"
       fi
     fi
 
@@ -8166,7 +8146,7 @@ fi
           if test "X$found_dir" != "X"; then
                         LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }-L$found_dir -l$name"
             if test "X$found_so" != "X"; then
-                                                        if test "$enable_rpath" = no || test "X$found_dir" = "X/usr/$acl_libdirstem"; then
+                                                        if test "$enable_rpath" = no || test "X$found_dir" = "X/usr/lib"; then
                                 LIBICONV="${LIBICONV}${LIBICONV:+ }$found_so"
               else
                                                                                 haveit=
@@ -8231,8 +8211,8 @@ fi
             fi
                         additional_includedir=
             case "$found_dir" in
-              */$acl_libdirstem | */$acl_libdirstem/)
-                basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem/"'*$,,'`
+              */lib | */lib/)
+                basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e 's,/lib/*$,,'`
                 additional_includedir="$basedir/include"
                 ;;
             esac
@@ -8281,9 +8261,9 @@ fi
                 case "$dep" in
                   -L*)
                     additional_libdir=`echo "X$dep" | sed -e 's/^X-L//'`
-                                                                                                                                                                if test "X$additional_libdir" != "X/usr/$acl_libdirstem"; then
+                                                                                                                                                                if test "X$additional_libdir" != "X/usr/lib"; then
                       haveit=
-                      if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem"; then
+                      if test "X$additional_libdir" = "X/usr/local/lib"; then
                         if test -n "$GCC"; then
                           case $host_os in
                             linux* | gnu* | k*bsd*-gnu) haveit=yes;;
@@ -12749,6 +12729,162 @@ fi
 
 done
 
+
+{ $as_echo "$as_me:$LINENO: checking for mysql_stmt_init in -lmysqlclient_r" >&5
+$as_echo_n "checking for mysql_stmt_init in -lmysqlclient_r... " >&6; }
+if test "${ac_cv_lib_mysqlclient_r_mysql_stmt_init+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lmysqlclient_r  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char mysql_stmt_init ();
+int
+main ()
+{
+return mysql_stmt_init ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
+  ac_cv_lib_mysqlclient_r_mysql_stmt_init=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_lib_mysqlclient_r_mysql_stmt_init=no
+fi
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_lib_mysqlclient_r_mysql_stmt_init" >&5
+$as_echo "$ac_cv_lib_mysqlclient_r_mysql_stmt_init" >&6; }
+if test "x$ac_cv_lib_mysqlclient_r_mysql_stmt_init" = x""yes; then
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_LIBMYSQLCLIENT_R 1
+_ACEOF
+
+  LIBS="-lmysqlclient_r $LIBS"
+
+else
+
+{ $as_echo "$as_me:$LINENO: checking for mysql_stmt_init in -lmysqlclient" >&5
+$as_echo_n "checking for mysql_stmt_init in -lmysqlclient... " >&6; }
+if test "${ac_cv_lib_mysqlclient_mysql_stmt_init+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lmysqlclient  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char mysql_stmt_init ();
+int
+main ()
+{
+return mysql_stmt_init ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
+  ac_cv_lib_mysqlclient_mysql_stmt_init=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_lib_mysqlclient_mysql_stmt_init=no
+fi
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_lib_mysqlclient_mysql_stmt_init" >&5
+$as_echo "$ac_cv_lib_mysqlclient_mysql_stmt_init" >&6; }
+if test "x$ac_cv_lib_mysqlclient_mysql_stmt_init" = x""yes; then
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_LIBMYSQLCLIENT 1
+_ACEOF
+
+  LIBS="-lmysqlclient $LIBS"
+
+else
+  { { $as_echo "$as_me:$LINENO: error: Unable to find MySQL client libraries version >= 4.1" >&5
+$as_echo "$as_me: error: Unable to find MySQL client libraries version >= 4.1" >&2;}
+   { (exit 1); exit 1; }; }
+fi
+
+
+fi
+
     cat >>confdefs.h <<\_ACEOF
 #define HAVE_MYSQL 1
 _ACEOF
diff --git a/configure.in b/configure.in
index 0e3950a..592e74d 100644
--- a/configure.in
+++ b/configure.in
@@ -966,6 +966,9 @@ else
         AC_MSG_RESULT([$MYSQL_CFLAGS])
     fi
     AC_CHECK_HEADERS(mysql/mysql.h mysql/mysql_version.h)
+    AC_CHECK_LIB(mysqlclient_r, mysql_stmt_init, [],
+		AC_CHECK_LIB(mysqlclient, mysql_stmt_init, [], [AC_MSG_ERROR([Unable to find MySQL client libraries version >= 4.1])])
+    )
     AC_DEFINE(HAVE_MYSQL)
     AC_MSG_CHECKING([whether to compile with MySQL support])
     AC_MSG_RESULT(yes)
diff --git a/gw/dlr_mysql.c b/gw/dlr_mysql.c
index e2bd3f0..4799191 100644
--- a/gw/dlr_mysql.c
+++ b/gw/dlr_mysql.c
@@ -71,7 +71,6 @@
 
 
 #ifdef HAVE_MYSQL
-#include <mysql/mysql.h>
 
 /*
  * Our connection pool to mysql.
@@ -84,56 +83,6 @@ static DBPool *pool = NULL;
 static struct dlr_db_fields *fields = NULL;
 
 
-static void mysql_update(const Octstr *sql)
-{
-    int	state;
-    DBPoolConn *pc;
-
-#if defined(DLR_TRACE)
-     debug("dlr.mysql", 0, "sql: %s", octstr_get_cstr(sql));
-#endif
-
-    pc = dbpool_conn_consume(pool);
-    if (pc == NULL) {
-        error(0, "MYSQL: Database pool got no connection! DB update failed!");
-        return;
-    }
-
-    state = mysql_query(pc->conn, octstr_get_cstr(sql));
-    if (state != 0)
-        error(0, "MYSQL: %s", mysql_error(pc->conn));
-
-    dbpool_conn_produce(pc);
-}
-
-static MYSQL_RES* mysql_select(const Octstr *sql)
-{
-    int	state;
-    MYSQL_RES *result = NULL;
-    DBPoolConn *pc;
-
-#if defined(DLR_TRACE)
-    debug("dlr.mysql", 0, "sql: %s", octstr_get_cstr(sql));
-#endif
-
-    pc = dbpool_conn_consume(pool);
-    if (pc == NULL) {
-        error(0, "MYSQL: Database pool got no connection! DB update failed!");
-        return NULL;
-    }
-
-    state = mysql_query(pc->conn, octstr_get_cstr(sql));
-    if (state != 0) {
-        error(0, "MYSQL: %s", mysql_error(pc->conn));
-    } else {
-        result = mysql_store_result(pc->conn);
-    }
-
-    dbpool_conn_produce(pc);
-
-    return result;
-}
-
 static void dlr_mysql_shutdown()
 {
     dbpool_destroy(pool);
@@ -142,74 +91,100 @@ static void dlr_mysql_shutdown()
 
 static void dlr_mysql_add(struct dlr_entry *entry)
 {
-    Octstr *sql;
-
-    sql = octstr_format("INSERT INTO %s (%s, %s, %s, %s, %s, %s, %s, %s, %s) VALUES "
-                        "('%s', '%s', '%s', '%s', '%s', '%s', '%d', '%s', '%d');",
-                        octstr_get_cstr(fields->table), octstr_get_cstr(fields->field_smsc),
-                        octstr_get_cstr(fields->field_ts),
-                        octstr_get_cstr(fields->field_src), octstr_get_cstr(fields->field_dst),
-                        octstr_get_cstr(fields->field_serv), octstr_get_cstr(fields->field_url),
-                        octstr_get_cstr(fields->field_mask), octstr_get_cstr(fields->field_boxc),
-                        octstr_get_cstr(fields->field_status),
-                        octstr_get_cstr(entry->smsc), octstr_get_cstr(entry->timestamp), octstr_get_cstr(entry->source),
-                        octstr_get_cstr(entry->destination), octstr_get_cstr(entry->service), octstr_get_cstr(entry->url),
-                        entry->mask, octstr_get_cstr(entry->boxc_id), 0);
+    Octstr *sql, *os_mask;
+    DBPoolConn *pconn;
+    List *binds = gwlist_create();
+    debug("dlr.mysql", 0, "adding DLR entry into database");
+
+    pconn = dbpool_conn_consume(pool);
+    /* just for sure */
+    if (pconn == NULL) {
+        dlr_entry_destroy(entry);
+        return;
+    }
 
+    sql = octstr_format("INSERT INTO %S (%S, %S, %S, %S, %S, %S, %S, %S, %S) VALUES "
+                        "(?, ?, ?, ?, ?, ?, ?, ?, 0)",
+                        fields->table, fields->field_smsc, fields->field_ts,
+                        fields->field_src, fields->field_dst, fields->field_serv,
+                        fields->field_url, fields->field_mask, fields->field_boxc,
+                        fields->field_status);
+    os_mask = octstr_format("%d", entry->mask);
+    gwlist_append(binds, entry->smsc);
+    gwlist_append(binds, entry->timestamp);
+    gwlist_append(binds, entry->source);
+    gwlist_append(binds, entry->destination);
+    gwlist_append(binds, entry->service);
+    gwlist_append(binds, entry->url);
+    gwlist_append(binds, os_mask);
+    gwlist_append(binds, entry->boxc_id);
 
-    mysql_update(sql);
+#if defined(DLR_TRACE)
+    debug("dlr.mysql", 0, "sql: %s", octstr_get_cstr(sql));
+#endif
+    if (dbpool_conn_update(pconn, sql, binds) == -1)
+        error(0, "DLR: MYSQL: Error while adding dlr entry for DST<%s>", octstr_get_cstr(entry->destination));
 
+    dbpool_conn_produce(pconn);
     octstr_destroy(sql);
+    gwlist_destroy(binds, NULL);
+    octstr_destroy(os_mask);
     dlr_entry_destroy(entry);
 }
 
 static struct dlr_entry* dlr_mysql_get(const Octstr *smsc, const Octstr *ts, const Octstr *dst)
 {
-    struct dlr_entry *res = NULL;
     Octstr *sql;
-    MYSQL_RES *result;
-    MYSQL_ROW row;
+    DBPoolConn *pconn;
+    List *result = NULL, *row;
+    struct dlr_entry *res = NULL;
+    List *binds = gwlist_create();
 
-    sql = octstr_format("SELECT %s, %s, %s, %s, %s, %s FROM %s WHERE %s='%s' AND %s='%s';",
-                        octstr_get_cstr(fields->field_mask), octstr_get_cstr(fields->field_serv),
-                        octstr_get_cstr(fields->field_url), octstr_get_cstr(fields->field_src),
-                        octstr_get_cstr(fields->field_dst), octstr_get_cstr(fields->field_boxc),
-                        octstr_get_cstr(fields->table), octstr_get_cstr(fields->field_smsc),
-                        octstr_get_cstr(smsc), octstr_get_cstr(fields->field_ts), octstr_get_cstr(ts));
+    pconn = dbpool_conn_consume(pool);
+    if (pconn == NULL) /* should not happens, but sure is sure */
+        return NULL;
 
+    sql = octstr_format("SELECT %S, %S, %S, %S, %S, %S FROM %S WHERE %S=? AND %S=? LIMIT 1",
+                        fields->field_mask, fields->field_serv,
+                        fields->field_url, fields->field_src,
+                        fields->field_dst, fields->field_boxc,
+                        fields->table, fields->field_smsc,
+                        fields->field_ts);
 
-    result = mysql_select(sql);
-    octstr_destroy(sql);
+    gwlist_append(binds, (Octstr *)smsc);
+    gwlist_append(binds, (Octstr *)ts);
 
-    if (result == NULL) {
-        return NULL;
-    }
-    if (mysql_num_rows(result) < 1) {
-        debug("dlr.mysql", 0, "no rows found");
-        mysql_free_result(result);
+#if defined(DLR_TRACE)
+    debug("dlr.mysql", 0, "sql: %s", octstr_get_cstr(sql));
+#endif
+
+    if (dbpool_conn_select(pconn, sql, binds, &result) != 0) {
+        octstr_destroy(sql);
+        dbpool_conn_produce(pconn);
         return NULL;
     }
-    row = mysql_fetch_row(result);
-    if (!row) {
-        debug("dlr.mysql", 0, "rows found but could not load them");
-        mysql_free_result(result);
-        return NULL;
+    octstr_destroy(sql);
+    gwlist_destroy(binds, NULL);
+    dbpool_conn_produce(pconn);
+
+#define LO2CSTR(r, i) octstr_get_cstr(gwlist_get(r, i))
+
+    if (gwlist_len(result) > 0) {
+        row = gwlist_extract_first(result);
+        res = dlr_entry_create();
+        gw_assert(res != NULL);
+        res->mask = atoi(LO2CSTR(row,0));
+        res->service = octstr_create(LO2CSTR(row, 1));
+        res->url = octstr_create(LO2CSTR(row,2));
+        res->source = octstr_create(LO2CSTR(row, 3));
+        res->destination = octstr_create(LO2CSTR(row, 4));
+        res->boxc_id = octstr_create(LO2CSTR(row, 5));
+        gwlist_destroy(row, octstr_destroy_item);
+        res->smsc = octstr_duplicate(smsc);
     }
+    gwlist_destroy(result, NULL);
 
-    debug("dlr.mysql", 0, "Found entry, row[0]=%s, row[1]=%s, row[2]=%s, row[3]=%s, row[4]=%s row[5]=%s",
-          row[0], row[1], row[2], (row[3] ? row[3] : "NULL"), (row[4] ? row[4] : "NULL"), (row[5] ? row[5] : "NULL"));
-
-    res = dlr_entry_create();
-    gw_assert(res != NULL);
-    res->mask = atoi(row[0]);
-    res->service = octstr_create(row[1]);
-    res->url = octstr_create(row[2]);
-    res->source = row[3] ? octstr_create(row[3]) : octstr_create("");
-    res->destination = row[4] ? octstr_create(row[4]) : octstr_create("");
-    res->boxc_id = row[5] ? octstr_create(row[5]) : octstr_create("");
-    res->smsc = octstr_duplicate(smsc);
-
-    mysql_free_result(result);
+#undef LO2CSTR
 
     return res;
 }
@@ -217,74 +192,125 @@ static struct dlr_entry* dlr_mysql_get(const Octstr *smsc, const Octstr *ts, con
 static void dlr_mysql_remove(const Octstr *smsc, const Octstr *ts, const Octstr *dst)
 {
     Octstr *sql;
+    DBPoolConn *pconn;
+    List *binds = gwlist_create();
 
     debug("dlr.mysql", 0, "removing DLR from database");
-    sql = octstr_format("DELETE FROM %s WHERE %s='%s' AND %s='%s' LIMIT 1;",
-                        octstr_get_cstr(fields->table), octstr_get_cstr(fields->field_smsc),
-                        octstr_get_cstr(smsc), octstr_get_cstr(fields->field_ts), octstr_get_cstr(ts));
 
+    pconn = dbpool_conn_consume(pool);
+    /* just for sure */
+    if (pconn == NULL)
+        return;
 
-    mysql_update(sql);
+    sql = octstr_format("DELETE FROM %S WHERE %S=? AND %S=? LIMIT 1",
+                        fields->table, fields->field_smsc,
+                        fields->field_ts);
 
+    gwlist_append(binds, (Octstr *)smsc);
+    gwlist_append(binds, (Octstr *)ts);
+
+#if defined(DLR_TRACE)
+    debug("dlr.mysql", 0, "sql: %s", octstr_get_cstr(sql));
+#endif
+
+    if (dbpool_conn_update(pconn, sql, binds) == -1)
+        error(0, "DLR: MYSQL: Error while removing dlr entry for DST<%s>", octstr_get_cstr(dst));
+
+    dbpool_conn_produce(pconn);
+    gwlist_destroy(binds, NULL);
     octstr_destroy(sql);
 }
 
 static void dlr_mysql_update(const Octstr *smsc, const Octstr *ts, const Octstr *dst, int status)
 {
-    Octstr *sql;
+    Octstr *sql, *os_status;
+    DBPoolConn *pconn;
+    List *binds = gwlist_create();
 
     debug("dlr.mysql", 0, "updating DLR status in database");
-    sql = octstr_format("UPDATE %s SET %s=%d WHERE %s='%s' AND %s='%s' LIMIT 1;",
-                        octstr_get_cstr(fields->table),
-                        octstr_get_cstr(fields->field_status), status,
-                        octstr_get_cstr(fields->field_smsc), octstr_get_cstr(smsc),
-                        octstr_get_cstr(fields->field_ts), octstr_get_cstr(ts));
 
-    mysql_update(sql);
+    pconn = dbpool_conn_consume(pool);
+    /* just for sure */
+    if (pconn == NULL)
+        return;
+
+    sql = octstr_format("UPDATE %S SET %S=:1 WHERE %S=:2 AND %S=:3 LIMIT 1",
+                        fields->table, fields->field_status,
+                        fields->field_smsc, fields->field_ts);
 
+    os_status = octstr_format("%d", status);
+    gwlist_append(binds, (Octstr *)os_status);
+    gwlist_append(binds, (Octstr *)smsc);
+    gwlist_append(binds, (Octstr *)ts);
+
+#if defined(DLR_TRACE)
+    debug("dlr.mysql", 0, "sql: %s", octstr_get_cstr(sql));
+#endif
+    if (dbpool_conn_update(pconn, sql, binds) == -1)
+        error(0, "DLR: MYSQL: Error while updating dlr entry for DST<%s>", octstr_get_cstr(dst));
+
+    dbpool_conn_produce(pconn);
+    gwlist_destroy(binds, NULL);
+    octstr_destroy(os_status);
     octstr_destroy(sql);
 }
 
 
 static long dlr_mysql_messages(void)
 {
+    List *result, *row;
     Octstr *sql;
-    long res;
-    MYSQL_RES *result;
-    MYSQL_ROW row;
+    DBPoolConn *conn;
+    long msgs = -1;
 
-    sql = octstr_format("SELECT count(*) FROM %s;", octstr_get_cstr(fields->table));
+    conn = dbpool_conn_consume(pool);
+    if (conn == NULL)
+        return -1;
 
-    result = mysql_select(sql);
-    octstr_destroy(sql);
+    sql = octstr_format("SELECT count(*) FROM %S", fields->table);
+#if defined(DLR_TRACE)
+    debug("dlr.mysql", 0, "sql: %s", octstr_get_cstr(sql));
+#endif
 
-    if (result == NULL) {
+    if (dbpool_conn_select(conn, sql, NULL, &result) != 0) {
+        octstr_destroy(sql);
+        dbpool_conn_produce(conn);
         return -1;
     }
-    if (mysql_num_rows(result) < 1) {
-        debug("dlr.mysql", 0, "Could not get count of DLR table");
-        mysql_free_result(result);
-        return 0;
-    }
-    row = mysql_fetch_row(result);
-    if (row == NULL) {
-        debug("dlr.mysql", 0, "rows found but could not load them");
-        mysql_free_result(result);
-        return 0;
+    dbpool_conn_produce(conn);
+    octstr_destroy(sql);
+
+    if (gwlist_len(result) > 0) {
+        row = gwlist_extract_first(result);
+        msgs = strtol(octstr_get_cstr(gwlist_get(row,0)), NULL, 10);
+        gwlist_destroy(row, octstr_destroy_item);
     }
-    res = atol(row[0]);
-    mysql_free_result(result);
+    gwlist_destroy(result, NULL);
 
-    return res;
+    return msgs;
 }
 
 static void dlr_mysql_flush(void)
 {
     Octstr *sql;
+    DBPoolConn *pconn;
+    int rows;
 
-    sql = octstr_format("DELETE FROM %s;", octstr_get_cstr(fields->table));
+    pconn = dbpool_conn_consume(pool);
+    /* just for sure */
+    if (pconn == NULL)
+        return;
 
-    mysql_update(sql);
+    sql = octstr_format("DELETE FROM %S", fields->table);
+#if defined(DLR_TRACE)
+    debug("dlr.mysql", 0, "sql: %s", octstr_get_cstr(sql));
+#endif
+    rows = dbpool_conn_update(pconn, sql, NULL);
+    if (rows == -1)
+        error(0, "DLR: MYSQL: Error while flushing dlr entries from database");
+    else
+        debug("dlr.mysql", 0, "Flushing %d DLR entries from database", rows);
+    dbpool_conn_produce(pconn);
     octstr_destroy(sql);
 }
 
diff --git a/gwlib/dbpool_mysql.c b/gwlib/dbpool_mysql.c
index 7dd1a31..70fc057 100644
--- a/gwlib/dbpool_mysql.c
+++ b/gwlib/dbpool_mysql.c
@@ -135,6 +135,223 @@ static int mysql_check_conn(void *conn)
 }
 
 
+static int mysql_select(void *conn, const Octstr *sql, List *binds, List **res)
+{
+    MYSQL_STMT *stmt;
+    MYSQL_RES *result;
+    MYSQL_BIND *bind = NULL;
+    long i, binds_len;
+    int ret;
+
+    *res = NULL;
+
+    /* allocate statement handle */
+    stmt = mysql_stmt_init((MYSQL*) conn);
+    if (stmt == NULL) {
+        error(0, "MYSQL: mysql_stmt_init(), out of memory.");
+        return -1;
+    }
+    if (mysql_stmt_prepare(stmt, octstr_get_cstr(sql), octstr_len(sql))) {
+        error(0, "MYSQL: Unable to prepare statement: %s", mysql_stmt_error(stmt));
+        mysql_stmt_close(stmt);
+        return -1;
+    }
+    /* bind params if any */
+    binds_len = gwlist_len(binds);
+    if (binds_len > 0) {
+        bind = gw_malloc(sizeof(MYSQL_BIND) * binds_len);
+        memset(bind, 0, sizeof(MYSQL_BIND) * binds_len);
+        for (i = 0; i < binds_len; i++) {
+            Octstr *str = gwlist_get(binds, i);
+
+            bind[i].buffer_type = MYSQL_TYPE_STRING;
+            bind[i].buffer = octstr_get_cstr(str);
+            bind[i].buffer_length = octstr_len(str);
+        }
+        /* Bind the buffers */
+        if (mysql_stmt_bind_param(stmt, bind)) {
+          error(0, "MYSQL: mysql_stmt_bind_param() failed: `%s'", mysql_stmt_error(stmt));
+          gw_free(bind);
+          mysql_stmt_close(stmt);
+          return -1;
+        }
+    }
+
+    /* execute statement */
+    if (mysql_stmt_execute(stmt)) {
+        error(0, "MYSQL: mysql_stmt_execute() failed: `%s'", mysql_stmt_error(stmt));
+        gw_free(bind);
+        mysql_stmt_close(stmt);
+        return -1;
+    }
+    gw_free(bind);
+
+#define DESTROY_BIND(bind, binds_len)           \
+    do {                                        \
+        long i;                                 \
+        for (i = 0; i < binds_len; i++) {       \
+            gw_free(bind[i].buffer);            \
+            gw_free(bind[i].length);            \
+            gw_free(bind[i].is_null);           \
+        }                                       \
+        gw_free(bind);                          \
+    } while(0)
+
+    /* Fetch result set meta information */
+    result = mysql_stmt_result_metadata(stmt);
+    if (res == NULL) {
+        error(0, "MYSQL: mysql_stmt_result_metadata() failed: `%s'", mysql_stmt_error(stmt));
+        mysql_stmt_close(stmt);
+        return -1;
+    }
+    /* Get total columns in the query */
+    binds_len = mysql_num_fields(result);
+    bind = gw_malloc(sizeof(MYSQL_BIND) * binds_len);
+    memset(bind, 0, sizeof(MYSQL_BIND) * binds_len);
+    /* bind result bind */
+    for (i = 0; i < binds_len; i++) {
+        MYSQL_FIELD *field = mysql_fetch_field(result); /* retrieve field metadata */
+
+        debug("gwlib.dbpool_mysql", 0, "column=%s buffer_type=%d max_length=%ld length=%ld", field->name, field->type, field->max_length, field->length);
+
+        switch(field->type) {
+        case MYSQL_TYPE_TIME:
+        case MYSQL_TYPE_DATE:
+        case MYSQL_TYPE_DATETIME:
+        case MYSQL_TYPE_TIMESTAMP:
+            bind[i].buffer_type = field->type;
+            bind[i].buffer = (char*)gw_malloc(sizeof(MYSQL_TIME));
+            bind[i].is_null = gw_malloc(sizeof(my_bool));
+            bind[i].length = gw_malloc(sizeof(unsigned long));
+            break;
+        default:
+            bind[i].buffer_type = MYSQL_TYPE_STRING;
+            bind[i].buffer = gw_malloc(field->length);
+            bind[i].buffer_length = field->length;
+            bind[i].length = gw_malloc(sizeof(unsigned long));
+            bind[i].is_null = gw_malloc(sizeof(my_bool));
+            break;
+        }
+    }
+    mysql_free_result(result);
+
+    if (mysql_stmt_bind_result(stmt, bind)) {
+        error(0, "MYSQL: mysql_stmt_bind_result() failed: `%s'", mysql_stmt_error(stmt));
+        DESTROY_BIND(bind, binds_len);
+        mysql_stmt_close(stmt);
+        return -1;
+    }
+
+    *res = gwlist_create();
+    while(!(ret = mysql_stmt_fetch(stmt))) {
+        List *row = gwlist_create();
+        for (i = 0; i < binds_len; i++) {
+            Octstr *str = NULL;
+            MYSQL_TIME *ts;
+
+            if (*bind[i].is_null) {
+                gwlist_produce(row, octstr_create(""));
+                continue;
+            }
+
+            switch(bind[i].buffer_type) {
+            case MYSQL_TYPE_DATE:
+                ts = bind[i].buffer;
+                str = octstr_format("%04d-%02d-%02d", ts->year, ts->month, ts->day);
+                break;
+            case MYSQL_TYPE_TIME:
+            case MYSQL_TYPE_DATETIME:
+            case MYSQL_TYPE_TIMESTAMP:
+                ts = bind[i].buffer;
+                str = octstr_format("%04d-%02d-%02d %02d:%02d:%02d", ts->year, ts->month, ts->day, ts->hour, ts->minute, ts->second);
+                break;
+            default:
+                if (bind[i].length == 0)
+                    str= octstr_create("");
+                else
+                    str = octstr_create_from_data(bind[i].buffer, *bind[i].length);
+                break;
+            }
+            gwlist_produce(row, str);
+        }
+        gwlist_produce(*res, row);
+    }
+    DESTROY_BIND(bind, binds_len);
+#undef DESTROY_BIND
+
+    /* any errors by fetch? */
+    if (ret != MYSQL_NO_DATA) {
+        List *row;
+        error(0, "MYSQL: mysql_stmt_bind_result() failed: `%s'", mysql_stmt_error(stmt));
+        mysql_stmt_close(stmt);
+        while((row = gwlist_extract_first(*res)) != NULL)
+            gwlist_destroy(row, octstr_destroy_item);
+        gwlist_destroy(*res, NULL);
+        *res = NULL;
+        return -1;
+    }
+
+    mysql_stmt_close(stmt);
+
+    return 0;
+}
+
+
+static int mysql_update(void *conn, const Octstr *sql, List *binds)
+{
+    MYSQL_STMT *stmt;
+    MYSQL_BIND *bind = NULL;
+    long i, binds_len;
+    int ret;
+
+    /* allocate statement handle */
+    stmt = mysql_stmt_init((MYSQL*) conn);
+    if (stmt == NULL) {
+        error(0, "MYSQL: mysql_stmt_init(), out of memory.");
+        return -1;
+    }
+    if (mysql_stmt_prepare(stmt, octstr_get_cstr(sql), octstr_len(sql))) {
+        error(0, "MYSQL: Unable to prepare statement: %s", mysql_stmt_error(stmt));
+        mysql_stmt_close(stmt);
+        return -1;
+    }
+    /* bind params if any */
+    binds_len = gwlist_len(binds);
+    if (binds_len > 0) {
+        bind = gw_malloc(sizeof(MYSQL_BIND) * binds_len);
+        memset(bind, 0, sizeof(MYSQL_BIND) * binds_len);
+        for (i = 0; i < binds_len; i++) {
+            Octstr *str = gwlist_get(binds, i);
+
+            bind[i].buffer_type = MYSQL_TYPE_STRING;
+            bind[i].buffer = octstr_get_cstr(str);
+            bind[i].buffer_length = octstr_len(str);
+        }
+        /* Bind the buffers */
+        if (mysql_stmt_bind_param(stmt, bind)) {
+          error(0, "MYSQL: mysql_stmt_bind_param() failed: `%s'", mysql_stmt_error(stmt));
+          gw_free(bind);
+          mysql_stmt_close(stmt);
+          return -1;
+        }
+    }
+
+    /* execute statement */
+    if (mysql_stmt_execute(stmt)) {
+        error(0, "MYSQL: mysql_stmt_execute() failed: `%s'", mysql_stmt_error(stmt));
+        gw_free(bind);
+        mysql_stmt_close(stmt);
+        return -1;
+    }
+    gw_free(bind);
+
+    ret = mysql_stmt_affected_rows(stmt);
+    mysql_stmt_close(stmt);
+
+    return ret;
+}
+
+
 static void mysql_conf_destroy(DBConf *db_conf)
 {
     MySQLConf *conf = db_conf->mysql;
@@ -153,6 +370,8 @@ static struct db_ops mysql_ops = {
     .open = mysql_open_conn,
     .close = mysql_close_conn,
     .check = mysql_check_conn,
+    .select = mysql_select,
+    .update = mysql_update,
     .conf_destroy = mysql_conf_destroy
 };
 
diff --git a/test/test_dbpool.c b/test/test_dbpool.c
index d032852..d390d72 100644
--- a/test/test_dbpool.c
+++ b/test/test_dbpool.c
@@ -58,7 +58,7 @@
  * test_dbpool.c - test DBPool objects
  *
  * Stipe Tolj <[email protected]>
- * Alexander Malysh <[email protected]>
+ * Alexander Malysh <[email protected]>
  */
              
 #include "gwlib/gwlib.h"
@@ -104,40 +104,42 @@ static enum db_type database_type = DBPOOL_MYSQL;
 static void (*client_thread)(void*) = NULL;
 
 #ifdef HAVE_MYSQL
-#include <mysql.h>
 
 static void mysql_client_thread(void *arg)
 {
     unsigned long i, succeeded, failed;
     DBPool *pool = arg;
+    List *result;
+    DBPoolConn *pconn;
 
     succeeded = failed = 0;
 
     info(0,"Client thread started with %ld queries to perform on pool", queries);
 
-    /* perform random queries on the pool */
     for (i = 1; i <= queries; i++) {
-        DBPoolConn *pconn;
-        int state;
-        MYSQL_RES *result;
-
-        /* provide us with a connection from the pool */
         pconn = dbpool_conn_consume(pool);
-        debug("",0,"Query %ld/%ld: mysql thread id %ld obj at %p",
-              i, queries, mysql_thread_id(pconn->conn), (void*) pconn->conn);
 
-        state = mysql_query(pconn->conn, octstr_get_cstr(sql));
-        if (state != 0) {
-            error(0, "MYSQL: %s", mysql_error(pconn->conn));
-            failed++;
-        } else {
+        if (pconn == NULL)
+            continue;
+#if 1 /* selects */
+        if (dbpool_conn_select(pconn, sql, NULL, &result) == 0) {
+            long i,j;
+            for (i=0; i < gwlist_len(result); i++) {
+                List *row = gwlist_get(result, i);
+                for (j=0; j < gwlist_len(row); j++)
+                    debug("", 0, "col = %ld   value = '%s'", j, octstr_get_cstr(gwlist_get(row,j)));
+                gwlist_destroy(row, octstr_destroy_item);
+            }
             succeeded++;
+        } else {
+            failed++;
         }
-        result = mysql_store_result(pconn->conn);
-        mysql_free_result(result);
-
-        /* return the connection to the pool */
+        gwlist_destroy(result, NULL);
         dbpool_conn_produce(pconn);
+#else /* only updates */
+        debug("", 0, "rows processed = %d ", dbpool_conn_update(pconn, sql, NULL));
+        dbpool_conn_produce(pconn);
+#endif
     }
     info(0, "This thread: %ld succeeded, %ld failed.", succeeded, failed);
 }
@@ -152,6 +154,7 @@ static DBConf *mysql_create_conf(Octstr *user, Octstr *pass, Octstr *db, Octstr
     conf->mysql->password = octstr_duplicate(pass);
     conf->mysql->database = octstr_duplicate(db);
     conf->mysql->host = octstr_duplicate(host);
+    conf->mysql->port = 3306;
 
     return conf;
 }
@@ -504,6 +507,10 @@ int main(int argc, char **argv)
           (host ? octstr_get_cstr(host) : octstr_get_cstr(db)), pool_size, octstr_get_cstr(db_type));
     pool = dbpool_create(database_type, conf, pool_size);
     debug("",0,"Connections within pool: %ld", dbpool_conn_count(pool));
+    if (dbpool_conn_count(pool) == 0) {
+        panic(0, "Unable to start without DBConns...");
+        exit(1);
+    }
 
     for (i = 0; i < num_threads; ++i) {
         if (gwthread_create(inc_dec_thread, pool) == -1)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.