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>
--- 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 ();