-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSelectOnDB.cpp
47 lines (35 loc) · 921 Bytes
/
SelectOnDB.cpp
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
#include <iostream>
#include <sqlite3.h>
using namespace std;
static int callback(void *data, int argc, char **argv, char **azColName){
int i;
fprintf(stderr, "%s: ", (const char*)data);
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)
{
sqlite3 *DB;
int exit = 0;
exit = sqlite3_open("example.db", &DB);
string data("CALLBACK FUNCTION");
string sql("SELECT * FROM PERSON;");
if(exit)
{
std::cerr << "Error open DB " << sqlite3_errmsg(DB) << std::endl;
return(-1);
}
else
std::cout << "Opened Database Successfully!" << std::endl;
int rc = sqlite3_exec(DB, sql.c_str(), callback, (void *)data.c_str(), NULL);
if( rc != SQLITE_OK )
cerr << "Error SELECT" << endl;
else {
cout << "Operation OK!" << endl;
}
sqlite3_close(DB);
return(0);
}