00001
00023 #ifndef __CALDB_H__
00024 #define __CALDB_H__
00025
00026
00027 #include <sqlite3.h>
00028
00029
00030 #include <dbus/dbus.h>
00031 #include <string>
00032 using namespace std;
00033 using std::string;
00034
00035
00036
00037 #ifndef _QRESULT__
00038 #define _QRESULT__
00039 typedef struct _QueryResult QueryResult;
00040
00041 struct _QueryResult {
00042 public:
00043 char **pResult;
00044 int iRow;
00045 int iColumn;
00046 };
00047 #endif
00048
00054 class CCalendarDB {
00055
00056 public:
00063 int setAutocommitOff();
00072 int initDB();
00073
00083 void setApplicationName (string appName);
00084
00091 sqlite3 *getDb();
00092
00101 int insertRows(sqlite3_stmt* preparedStmt,int& iSqliteError);
00102
00110 bool updateDB(sqlite3_stmt * preparedStmt,int& iSqliteError);
00119 void sqliteErrorMapper(int iSqliteError, int& pErrorCode );
00120
00121
00128 bool rollbackDB();
00129
00136 bool commitDB(string szMessage);
00137
00144 bool closeDB();
00145
00153 QueryResult *getRecords(char *pQuery, int& iSqliteError);
00154
00163 static CCalendarDB *Instance();
00164
00165
00166 bool sendDBusMessage (string szSendMessage);
00167
00168 bool initializeDBus ();
00169
00170
00171 ~CCalendarDB();
00172 void InstanceDestroy();
00173
00180 int execSQL(const char *pQuery);
00181
00182 private:
00183
00191 CCalendarDB();
00192
00193
00194
00195 CCalendarDB(CCalendarDB & calendardb);
00196
00197
00198 CCalendarDB & operator=(CCalendarDB & calendardb);
00199
00207 int migrate(const char *table, const char *createClause);
00208
00209 sqlite3 * pDb;
00210 DBusConnection *pBus;
00211 static CCalendarDB *pCalendarDb;
00212
00213 void sem_p(void);
00214
00215 void sem_v(void);
00216
00217 int sem_id;
00218
00219 };
00220
00221
00222 #endif