35 fSrvInfo += sqlite3_libversion();
37 if (strncmp(db,
"sqlite://", 9)) {
39 Error(
"TSQLiteServer",
"protocol in db argument should be sqlite it is %s",
40 givenProtocol.
Data());
45 const char *dbase = db + 9;
47 #ifndef SQLITE_OPEN_URI 48 #define SQLITE_OPEN_URI 0x00000000 50 #if SQLITE_VERSION_NUMBER >= 3005000 53 Int_t error = sqlite3_open(dbase, &fSQLite);
64 Error(
"TSQLiteServer",
"opening of %s failed with error: %d %s", dbase, sqlite3_errcode(fSQLite), sqlite3_errmsg(fSQLite));
65 sqlite3_close(fSQLite);
104 return Exec(
"BEGIN TRANSACTION");
115 Error(
"Query",
"not connected");
119 sqlite3_stmt *preparedStmt =
NULL;
123 #if SQLITE_VERSION_NUMBER >= 3005000 124 int retVal = sqlite3_prepare_v2(
fSQLite, sql, -1, &preparedStmt,
NULL);
126 int retVal = sqlite3_prepare(
fSQLite, sql, -1, &preparedStmt,
NULL);
128 if (retVal != SQLITE_OK) {
129 Error(
"Query",
"SQL Error: %d %s", retVal, sqlite3_errmsg(
fSQLite));
143 Error(
"Exec",
"not connected");
147 char *sqlite_err_msg;
149 if (ret != SQLITE_OK) {
150 Error(
"Exec",
"SQL Error: %d %s", ret, sqlite_err_msg);
151 sqlite3_free(sqlite_err_msg);
164 Error(
"SelectDataBase",
"SelectDataBase command makes no sense for SQLite!");
174 Error(
"GetDataBases",
"GetDataBases command makes no sense for SQLite!");
187 Error(
"GetTables",
"not connected");
191 TString sql =
"SELECT name FROM sqlite_master where type='table'";
193 sql +=
Form(
" AND name LIKE '%s'", wild);
211 Error(
"GetColumns",
"not connected");
216 Error(
"GetColumns",
"Not implementable for SQLite as a query with wildcard, use GetFieldNames() after SELECT instead!");
219 TString sql =
Form(
"PRAGMA table_info('%s')", table);
231 Error(
"GetTableInfo",
"not connected");
235 if ((tablename==0) || (*tablename==0))
return 0;
239 if (columnRes ==
NULL) {
240 Error(
"GetTableInfo",
"could not query columns");
248 while ((columnRow = columnRes->
Next()) !=
NULL) {
281 Error(
"CreateDataBase",
"CreateDataBase command makes no sense for SQLite!");
291 Error(
"DropDataBase",
"DropDataBase command makes no sense for SQLite!");
302 Error(
"Reload",
"not connected");
306 Error(
"Reload",
"not implemented");
317 Error(
"Shutdown",
"not connected");
321 Error(
"Shutdown",
"not implemented");
342 SetError(-1,
"no query string specified",
"Statement");
347 Error(
"Statement",
"not connected");
351 sqlite3_stmt *preparedStmt =
NULL;
355 #if SQLITE_VERSION_NUMBER >= 3005000 356 int retVal = sqlite3_prepare_v2(
fSQLite, sql, -1, &preparedStmt,
NULL);
358 int retVal = sqlite3_prepare(
fSQLite, sql, -1, &preparedStmt,
NULL);
360 if (retVal != SQLITE_OK) {
361 Error(
"Statement",
"SQL Error: %d %s", retVal, sqlite3_errmsg(
fSQLite));
367 stmt->
fRes = preparedStmt;
378 Error(
"ServerInfo",
"not connected");
Bool_t Exec(const char *sql)
Execute SQL command which does not produce any result sets.
TSQLResult * Query(const char *sql)
Execute SQL command.
Int_t Reload()
Reload permission tables.
~TSQLiteServer()
Close SQLite DB.
void Error(const char *location, const char *msgfmt,...)
TSQLResult * GetColumns(const char *dbname, const char *table, const char *wild=0)
List all columns in specified table (database argument is ignored).
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
char * Form(const char *fmt,...)
virtual const char * GetField(Int_t field)=0
Int_t CreateDataBase(const char *dbname)
Create a database.
Bool_t StartTransaction()
submit "START TRANSACTION" query to database return kTRUE, if successful
const char * ServerInfo()
Return server info, must be deleted by user.
Int_t Shutdown()
Shutdown the database server.
Int_t SelectDataBase(const char *dbname)
Select a database.
Bool_t HasStatement() const
We assume prepared statements work for all SQLite-versions.
void SetError(Int_t code, const char *msg, const char *method=0)
set new values for error fields if method is specified, displays error message
TSQLResult * GetDataBases(const char *wild=0)
List all available databases.
void Close(Option_t *opt="")
Close connection to SQLite DB.
TSQLStatement * Statement(const char *sql, Int_t=100)
Produce TSQLiteStatement.
virtual Bool_t IsConnected() const
virtual void Add(TObject *obj)
TSQLResult * GetTables(const char *dbname, const char *wild=0)
List all tables in the specified database.
Int_t DropDataBase(const char *dbname)
Drop (i.e.
virtual TSQLRow * Next()=0
const char * Data() const
TSQLTableInfo * GetTableInfo(const char *tablename)
Produces SQL table info.