db_bridge/mysql_db.cpp
changeset 126 52722ac7693f
parent 65 76514757b0d6
equal deleted inserted replaced
125:9c0fdc119939 126:52722ac7693f
    45 Abstract_DB::DB_RESULT MySQL_DB::query (std::string sql_string)
    45 Abstract_DB::DB_RESULT MySQL_DB::query (std::string sql_string)
    46 {
    46 {
    47     Abstract_DB::DB_ROW vec;
    47     Abstract_DB::DB_ROW vec;
    48     Abstract_DB::DB_RESULT rows;
    48     Abstract_DB::DB_RESULT rows;
    49     MYSQL_ROW row;
    49     MYSQL_ROW row;
    50     int i = 0;
    50     int i = 0, num_fields = 0;
    51 
    51 
    52     /*
    52     /*
    53      * send SQL query
    53      * send SQL query
    54      */
    54      */
    55     if (mysql_query (conn, sql_string.c_str ())) {
    55     if (mysql_query (conn, sql_string.c_str ())) {
    56         std::cerr << server << ": " << mysql_error (conn) << std::endl;
    56         std::cerr << server << ": " << mysql_error (conn) << std::endl;
    57         return rows;
    57         return rows;
    58     }
    58     }
    59 
    59 
    60     res = mysql_use_result (conn);
    60     res = mysql_use_result (conn);
       
    61     num_fields = mysql_num_fields (res);
    61 
    62 
    62     /*
    63     /*
    63      * push everything into a vector< vector<string> >
    64      * push everything into a vector< vector<string> >
    64      */
    65      */
    65     while ((row = mysql_fetch_row (res)) != NULL) {
    66     while ((row = mysql_fetch_row (res)) != NULL) {
    66         i = 0;
    67 	for (i = 0; i < num_fields; i++) {
    67         while (row[i] != NULL) {
    68             vec.push_back (row[i]);
    68             vec.push_back (row[i++]);
       
    69         }
    69         }
    70         rows.push_back (vec);
    70         rows.push_back (vec);
    71         vec.clear ();
    71         vec.clear ();
    72     }
    72     }
    73 
    73