diff options
author | Joe Zhao <ztuowen@gmail.com> | 2015-09-04 11:28:34 -0600 |
---|---|---|
committer | Joe Zhao <ztuowen@gmail.com> | 2015-09-04 11:28:34 -0600 |
commit | 4e296d5f189c2a5a4505149a7cfba3b1f50f0d85 (patch) | |
tree | eb790522b1ea8214999a80edd8508d459aaed254 /logging.cpp | |
parent | 4797fa9af722263307f08b386458691a5b70fa29 (diff) | |
download | pomodori-4e296d5f189c2a5a4505149a7cfba3b1f50f0d85.tar.gz pomodori-4e296d5f189c2a5a4505149a7cfba3b1f50f0d85.tar.bz2 pomodori-4e296d5f189c2a5a4505149a7cfba3b1f50f0d85.zip |
sqlite logging
Diffstat (limited to 'logging.cpp')
-rw-r--r-- | logging.cpp | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/logging.cpp b/logging.cpp index 3d1fb14..f9b3100 100644 --- a/logging.cpp +++ b/logging.cpp @@ -4,19 +4,37 @@ #include "logging.h" #include "stdlib.h" -#include<iostream> -#include <fstream> +#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) { - ofstream fot; - fot.open("~/.pomodori"); - time_t now = time(0); - fot<<ctime(&now)<<endl; + 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); }
\ No newline at end of file |