1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "libs/sqlite3.h"
static int callback(void *NotUsed, int argc, char **argv, char **azColName)
{
int i;
for(i=0; i<argc; i++){
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
}
printf("\n");
return 0;
}
int main(int argc,char * argv[])
{
// chdir("/mnt/ext1/games/");
// int fd1 = open("log1.txt",O_CREAT|0666);
// dup2(fd1, 1);
sqlite3 *db;
char *zErrMsg = 0;
int retCode;
retCode = sqlite3_open_v2("test.dat", &db,SQLITE_OPEN_READWRITE,NULL);
if( retCode )
{
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
exit(1);
}
std::string query="select * from cards order by due";
retCode = sqlite3_exec(db, query.c_str(), callback, 0, &zErrMsg);
if( retCode!=SQLITE_OK )
{
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}
sqlite3_close(db);
return 0;
}