1#include "DatabaseSvc/SqliteInterface.h"
37 int status = sqlite3_open_v2(fname.c_str(), &m_conn, SQLITE_OPEN_READONLY,0);
39 cerr <<
"Can't open database " << fname <<
": "
40 << sqlite3_errmsg(m_conn) << endl;
42 sqlite3_close(m_conn);
77 int status =
query(dbname, sql, dummy);
95 sqlite3_prepare_v2(m_conn, sql.c_str(), -1, &ppStmt, 0);
99 status = sqlite3_step(ppStmt);
100 if(status == SQLITE_DONE)
105 if(status == SQLITE_ROW)
110 int ncolumns = sqlite3_column_count(ppStmt);
112 for(i=0; i<ncolumns; i++)
115 unsigned long field_len = sqlite3_column_bytes(ppStmt,i);
117 const char* col_name = sqlite3_column_name(ppStmt,i);
118 char column_name[255];
119 strcpy(column_name,col_name);
120 int type = sqlite3_column_type(ppStmt,i);
121 if(type == SQLITE_BLOB)
123 new_record =
new char[field_len];
124 char* col_result = (
char*)sqlite3_column_blob(ppStmt,i);
125 memcpy(new_record,col_result,field_len);
127 else if (type != SQLITE_NULL)
129 new_record =
new char[field_len+1];
130 char* col_result = (
char*)sqlite3_column_text(ppStmt,i);
131 strcpy(new_record,col_result);
137 (*dbrec)[column_name] = new_record;
140 records.push_back(dbrec);
146 cerr <<
"SQLITE query error: " << zErrMsg << endl;
150 sqlite3_free(zErrMsg);
151 sqlite3_finalize(ppStmt);
155 return records.size();
160 int res = sqlite3_close(m_conn);
162 cerr <<
"ERROR: Cannot close connection to " <<
m_dbName << endl;
int query(std::string dbname, std::string query)
int select_db(std::string dbname)