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
|
//
// Created by joe on 9/3/15.
//
#include "logging.h"
#include "stdlib.h"
#include "stdio.h"
#include <ctime>
#include <string>
#include <sqlite3.h>
#include <unistd.h>
#include <pwd.h>
struct passwd *pw = getpwuid(getuid());
using namespace std;
void log(tres* res,int code)
{
if (code)
{
sqlite3 *db;
char *zErrMsg = 0;
char sqlop[50];
sprintf(sqlop,"%s/.pomodori",pw->pw_dir);
int rc = sqlite3_open(sqlop,&db);
if( rc ){
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
exit(0);
}
sprintf(sqlop,"insert into log (Cat) Values ('%s');",res->reason);
rc = sqlite3_exec(db, sqlop, NULL, 0, &zErrMsg);
if( rc!=SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}
sqlite3_close(db);
}
exit(0);
}
|