39 if (strncmp(db,
"sqlite://", 9)) {
41 Error(
"TSQLiteServer",
"protocol in db argument should be sqlite it is %s",
42 givenProtocol.
Data());
47 const char *dbase = db + 9;
49#ifndef SQLITE_OPEN_URI
50#define SQLITE_OPEN_URI 0x00000000
52#if SQLITE_VERSION_NUMBER >= 3005000
66 Error(
"TSQLiteServer",
"opening of %s failed with error: %d %s", dbase, sqlite3_errcode(
fSQLite), sqlite3_errmsg(
fSQLite));
106 return Exec(
"BEGIN TRANSACTION");
117 return sqlite3_get_autocommit(
fSQLite) == 0;
127 return Exec(
"COMMIT TRANSACTION");
136 return Exec(
"ROLLBACK TRANSACTION");
147 Error(
"Query",
"not connected");
151 sqlite3_stmt *preparedStmt =
nullptr;
155#if SQLITE_VERSION_NUMBER >= 3005000
156 int retVal = sqlite3_prepare_v2(
fSQLite, sql, -1, &preparedStmt,
nullptr);
158 int retVal = sqlite3_prepare(
fSQLite, sql, -1, &preparedStmt,
nullptr);
160 if (retVal != SQLITE_OK) {
161 Error(
"Query",
"SQL Error: %d %s", retVal, sqlite3_errmsg(
fSQLite));
175 Error(
"Exec",
"not connected");
179 char *sqlite_err_msg;
180 int ret = sqlite3_exec(
fSQLite, sql, NULL, NULL, &sqlite_err_msg);
181 if (ret != SQLITE_OK) {
182 Error(
"Exec",
"SQL Error: %d %s", ret, sqlite_err_msg);
183 sqlite3_free(sqlite_err_msg);
196 Error(
"SelectDataBase",
"SelectDataBase command makes no sense for SQLite!");
206 Error(
"GetDataBases",
"GetDataBases command makes no sense for SQLite!");
219 Error(
"GetTables",
"not connected");
223 TString sql =
"SELECT name FROM sqlite_master where type='table'";
225 sql +=
Form(
" AND name LIKE '%s'", wild);
243 Error(
"GetColumns",
"not connected");
248 Error(
"GetColumns",
"Not implementable for SQLite as a query with wildcard, use GetFieldNames() after SELECT instead!");
251 TString sql =
Form(
"PRAGMA table_info('%s')", table);
263 Error(
"GetTableInfo",
"not connected");
267 if (!tablename || (*tablename==0))
return nullptr;
271 if (columnRes ==
nullptr) {
272 Error(
"GetTableInfo",
"could not query columns");
276 TList* lst =
nullptr;
280 while ((columnRow = columnRes->
Next()) !=
nullptr) {
313 Error(
"CreateDataBase",
"CreateDataBase command makes no sense for SQLite!");
323 Error(
"DropDataBase",
"DropDataBase command makes no sense for SQLite!");
334 Error(
"Reload",
"not connected");
338 Error(
"Reload",
"not implemented");
349 Error(
"Shutdown",
"not connected");
353 Error(
"Shutdown",
"not implemented");
374 SetError(-1,
"no query string specified",
"Statement");
379 Error(
"Statement",
"not connected");
383 sqlite3_stmt *preparedStmt =
nullptr;
387#if SQLITE_VERSION_NUMBER >= 3005000
388 int retVal = sqlite3_prepare_v2(
fSQLite, sql, -1, &preparedStmt, NULL);
390 int retVal = sqlite3_prepare(
fSQLite, sql, -1, &preparedStmt, NULL);
392 if (retVal != SQLITE_OK) {
393 Error(
"Statement",
"SQL Error: %d %s", retVal, sqlite3_errmsg(
fSQLite));
399 stmt->
fRes = preparedStmt;
410 Error(
"ServerInfo",
"not connected");
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
void Add(TObject *obj) override
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.
Bool_t Commit() final
submit "COMMIT TRANSACTION" query to database return kTRUE, if successful
TSQLResult * Query(const char *sql) final
Execute SQL command.
Bool_t HasTransactionInFlight() final
returns kTRUE when transaction is running
const char * ServerInfo() final
Return server info, must be deleted by user.
Bool_t Rollback() final
submit "ROLLBACK TRANSACTION" query to database return kTRUE, if successful
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 "BEGIN TRANSACTION" query to database return kTRUE, if successful
TSQLTableInfo * GetTableInfo(const char *tablename) final
Produces SQL table info.
const char * Data() const