82 if ( status < 0 )
return -1;
87 sqlite3_prepare_v2( m_conn, sql.c_str(), -1, &ppStmt, 0 );
91 status = sqlite3_step( ppStmt );
92 if ( status == SQLITE_DONE ) {
break; }
94 if ( status == SQLITE_ROW )
99 int ncolumns = sqlite3_column_count( ppStmt );
101 for ( i = 0; i < ncolumns; i++ )
104 unsigned long field_len = sqlite3_column_bytes( ppStmt, i );
106 const char* col_name = sqlite3_column_name( ppStmt, i );
107 char column_name[255];
108 strcpy( column_name, col_name );
109 int type = sqlite3_column_type( ppStmt, i );
110 if (
type == SQLITE_BLOB )
112 new_record =
new char[field_len];
113 char* col_result = (
char*)sqlite3_column_blob( ppStmt, i );
114 memcpy( new_record, col_result, field_len );
116 else if (
type != SQLITE_NULL )
118 new_record =
new char[field_len + 1];
119 char* col_result = (
char*)sqlite3_column_text( ppStmt, i );
120 strcpy( new_record, col_result );
122 else { new_record = NULL; }
123 ( *dbrec )[column_name] = new_record;
126 records.push_back( dbrec );
132 cerr <<
"SQLITE query error: " << zErrMsg << endl;
136 sqlite3_free( zErrMsg );
137 sqlite3_finalize( ppStmt );
141 return records.size();