-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
92 lines (60 loc) · 1.58 KB
/
main.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "sqlite3.h"
#include <iostream>
#include <algorithm>
using namespace std;
extern "C" int getGlobalKeyPress(); // Reach in to evtest c program
static int callback(void *NotUsed, int argc, char **argv, char **azColName) {
cout<<"db action done"<<endl;
int i;
for(i = 0; i<argc; i++) {
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
}
printf("\n");
return 0;
}
int run_ev_loop = 1;
// Returns true if x is in range [low..high], else false
bool inRange(int low, int high, int x)
{
return ((x-low) <= (high-low));
}
void valuateGlobalCommand(int k_code){
printf(":: COMMAND IS INTEGER %d \n",k_code);
if(inRange(1,9, k_code)){
printf("zesssss");
}
}
void runloop(){
while(run_ev_loop){
int keycode = getGlobalKeyPress();
printf("\nincomming->> %d\n", keycode);
if(keycode != -1){
valuateGlobalCommand(keycode);
keycode = -1;
}
}
}
int main(int argc, char **argv){
sqlite3* db;
char *errMsg = 0;
const char *sql;
int res = sqlite3_open("db_1.db", &db);
if(res){
//database failed to open
cout << "Database failed to open" << endl;
}else{
//your database code here
cout << "Database opened" << endl;
sql="INSERT INTO nodes (password,type,tags) VALUES('hof','url','la la')";
res = sqlite3_exec(db,sql, callback,0,&errMsg);
if( res != SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", errMsg);
sqlite3_free(errMsg);
} else{
fprintf(stdout, "Records created successfully\n");
}
}
sqlite3_close(db);
runloop();
return 0;
}