使用sqlite3
C ++绑定GCC(MINGW) 4.6.2
以下代码不起作用,即回调函数不会在屏幕上打印任何内容。
有什么建议吗?
#include <iostream>
#include "sqlite3.h"
using namespace std;
static int callback(void *NotUsed, int argc, char **argv, char **azColName)
{
for (int i=0; i<argc; i++)
{
cout << azColName[i] << "=" << argv[i] << endl;
cout << "\n" << endl;
}
return 0;
}
class db
{
public:
sqlite3* mydb;
char database;
char* mysql;
char* zErrMsg;
db()
{
zErrMsg = 0;
}
void open(string mydatabase)
{
sqlite3_open(mydatabase.c_str(), &mydb);
}
void exec(char* mysql)
{
int rc = sqlite3_exec(mydb, mysql, callback, 0, &zErrMsg);
}
void close()
{
sqlite3_close(mydb);
}
};
int main()
{
db* mystorage;
string s_var = "test.db";
char* sql = "SELECT * FROM COMPANY;";
mystorage -> open(s_var);
mystorage -> exec(sql);
mystorage -> close();
return 0;
}