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
64 Error(
"TSQLiteServer",
"opening of %s failed with error: %d %s", dbase, sqlite3_errcode(
fSQLite), sqlite3_errmsg(
fSQLite));
104 return Exec(
"BEGIN TRANSACTION");
115 Error(
"Query",
"not connected");
119 sqlite3_stmt *preparedStmt =
nullptr;
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;
148 int ret = sqlite3_exec(
fSQLite, sql, NULL, NULL, &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 nullptr;
239 if (columnRes ==
nullptr) {
240 Error(
"GetTableInfo",
"could not query columns");
244 TList* lst =
nullptr;
248 while ((columnRow = columnRes->
Next()) !=
nullptr) {
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 =
nullptr;
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");
char * Form(const char *fmt,...)
virtual void Add(TObject *obj)
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual TSQLRow * Next()=0
virtual const char * GetField(Int_t field)=0
void SetError(Int_t code, const char *msg, const char *method=nullptr)
set new values for error fields if method is specified, displays error message
virtual Bool_t IsConnected() const
Int_t SelectDataBase(const char *dbname) final
Select a database.
TSQLStatement * Statement(const char *sql, Int_t=100) final
Produce TSQLiteStatement.
Bool_t HasStatement() const final
We assume prepared statements work for all SQLite-versions.
Int_t DropDataBase(const char *dbname) final
Drop (i.e.
TSQLResult * GetTables(const char *dbname, const char *wild=nullptr) final
List all tables in the specified database.
TSQLResult * Query(const char *sql) final
Execute SQL command.
const char * ServerInfo() final
Return server info, must be deleted by user.
TSQLResult * GetColumns(const char *dbname, const char *table, const char *wild=nullptr) final
List all columns in specified table (database argument is ignored).
Int_t Shutdown() final
Shutdown the database server.
Bool_t Exec(const char *sql) final
Execute SQL command which does not produce any result sets.
Int_t Reload() final
Reload permission tables.
TSQLResult * GetDataBases(const char *wild=nullptr) final
List all available databases.
Int_t CreateDataBase(const char *dbname) final
Create a database.
~TSQLiteServer()
Close SQLite DB.
void Close(Option_t *opt="") final
Close connection to SQLite DB.
TSQLiteServer(const char *db, const char *uid=nullptr, const char *pw=nullptr)
Open a connection to an SQLite DB server.
Bool_t StartTransaction() final
submit "START TRANSACTION" query to database return kTRUE, if successful
TSQLTableInfo * GetTableInfo(const char *tablename) final
Produces SQL table info.
const char * Data() const