# HG changeset patch
# User Markus Bröker <mbroeker@largo.dyndns.tv>
# Date 1274878604 -7200
# Node ID 52722ac7693f3e906ef85220308c628adad1d741
# Parent  9c0fdc119939057f4049678fc13127773edea8e7
mysql_db: get not more than num_fields fields from a row

I haven't tested the old approach, because i have never installed
or used mysql. But it's nice to see that it actually works with
this small patch.

committer: Markus Bröker <mbroeker@largo.homelinux.org>

diff --git a/db_bridge/mysql_db.cpp b/db_bridge/mysql_db.cpp
--- a/db_bridge/mysql_db.cpp
+++ b/db_bridge/mysql_db.cpp
@@ -47,7 +47,7 @@
     Abstract_DB::DB_ROW vec;
     Abstract_DB::DB_RESULT rows;
     MYSQL_ROW row;
-    int i = 0;
+    int i = 0, num_fields = 0;
 
     /*
      * send SQL query
@@ -58,14 +58,14 @@
     }
 
     res = mysql_use_result (conn);
+    num_fields = mysql_num_fields (res);
 
     /*
      * push everything into a vector< vector<string> >
      */
     while ((row = mysql_fetch_row (res)) != NULL) {
-        i = 0;
-        while (row[i] != NULL) {
-            vec.push_back (row[i++]);
+	for (i = 0; i < num_fields; i++) {
+            vec.push_back (row[i]);
         }
         rows.push_back (vec);
         vec.clear ();