KaliVeda
1.12/06
Heavy-Ion Analysis Toolkit
|
Interface to ROOT SQLite database backend ,.
WARNING*: opens in read/write mode. there is no protection against modifying an existing database.
Example output:
Example output:
Example output:
For more details on use (also for inserting data), see example db_sqlite_examples.C
Definition at line 374 of file SQLiteDB.h.
Public Member Functions | |
database () | |
database (const database &db) | |
database (const TString &dbfile) | |
virtual | ~database () |
column & | add_column (const TString &table, const TString &name, const TString &type) |
void | add_missing_columns (const TString &table, const KVNameValueList &l) |
void | add_table (KVSQLite::table &) |
void | clear_table (const TString &name) |
Delete all data from table. More... | |
void | close () |
void | copy_table_data (const TString &source, const TString &destination, const TString &columns="*", const TString &selection="") |
int | count (const TString &table, const TString &column="*", const TString &selection="", bool distinct=false) const |
TGraph * | create_graph (const TString &tablename, const TString &Xcolumn, const TString &Ycolumn, const TString &selection="") |
void | delete_data (const TString &table, const TString &selection="") |
void | Dump () const |
Print on stdout contents of database. More... | |
void | end_data_insertion () |
KVNumberList | get_integer_list (const TString &table, const TString &column, const TString &selection="", const TString &anything_else="") |
KVNameValueList | get_name_value_list (const TString &table, const TString &name_column, const TString &value_column, const TString &selection="", const TString &anything_else="") |
bool | get_next_result () const |
int | get_number_of_tables () const |
TString | get_string_list (const TString &table, const TString &column, const TString &selection="", const TString &anything_else="") |
bool | good () const |
bool | has_table (const TString &table) |
void | insert_data_row () |
bool | is_inserting () const |
bool | is_open () const |
void | open (const TString &dbfile) |
database & | operator= (const database &db) |
KVSQLite::table & | operator[] (const TString &name) |
const KVSQLite::table & | operator[] (const TString &name) const |
bool | prepare_data_insertion (const TString &) |
void | print_selection (const TString &table, const TString &columns, const TString &condition, int column_width=20) const |
Print on stdout contents of database. More... | |
bool | select_data (const TString &table, const TString &columns="*", const TString &selection="", bool distinct=false, const TString &anything_else="") const |
void | show_tables () const |
print list of tables More... | |
bool | update (const TString &table, const TString &columns, const TString &selection="") |
Private Member Functions | |
void | PrintResults (TSQLResult *tabent, int column_width=20) const |
void | read_table_infos () |
initialise map of database tables from existing database More... | |
unique_ptr< TSQLResult > | SelectRowsFromTable (const TString &table, const TString &columns="*", const TString &condition="") const |
Private Attributes | |
KVSQLite::table * | fBulkTable |
unique_ptr< TSQLiteServer > | fDBserv |
bool | fEmptyResultSet |
bool | fInserting |
bool | fIsValid |
TString | fSelectedColumns |
bool | fSelecting |
unique_ptr< TSQLStatement > | fSQLstmt |
std::unordered_map< std::string, KVSQLite::table > | fTables |
#include <SQLiteDB.h>
|
inline |
Definition at line 398 of file SQLiteDB.h.
|
inline |
Definition at line 399 of file SQLiteDB.h.
|
inline |
because of the use of std::unique_ptr, we cannot copy the address of the TSQLiteServer from db - it would delete the database connection in db
therefore if we "copy" a database, we create a new, independent interface to the same database
this is basically a workaround/kludge for C++11/14/g++6
Definition at line 403 of file SQLiteDB.h.
|
inlinevirtual |
Definition at line 422 of file SQLiteDB.h.
column & KVSQLite::database::add_column | ( | const TString & | table, |
const TString & | name, | ||
const TString & | type | ||
) |
add column to existing table
Definition at line 796 of file SQLiteDB.cpp.
void KVSQLite::database::add_missing_columns | ( | const TString & | _table_, |
const KVNameValueList & | l | ||
) |
add to table any columns which are defined in the list but don't exist
Definition at line 811 of file SQLiteDB.cpp.
void KVSQLite::database::add_table | ( | KVSQLite::table & | t | ) |
add table to database (if it does not exist already)
WARNING: after calling this method, do not use the table given as argument
it does not correspond to the table in the database
instead use db["table name"]
to access the table
Definition at line 193 of file SQLiteDB.cpp.
Delete all data from table.
Definition at line 664 of file SQLiteDB.cpp.
|
inline |
Definition at line 432 of file SQLiteDB.h.
void KVSQLite::database::copy_table_data | ( | const TString & | source, |
const TString & | destination, | ||
const TString & | columns = "*" , |
||
const TString & | selection = "" |
||
) |
Copy all selected data in 'source' table to 'destination'
If the columns of the two tables are not identical, specify the columns to copy in 'columns' (comma-separated list)
Definition at line 844 of file SQLiteDB.cpp.
int KVSQLite::database::count | ( | const TString & | table, |
const TString & | column = "*" , |
||
const TString & | selection = "" , |
||
bool | distinct = false |
||
) | const |
Returns number of rows in table for which selection holds true:
Definition at line 680 of file SQLiteDB.cpp.
TGraph * KVSQLite::database::create_graph | ( | const TString & | tablename, |
const TString & | Xcolumn, | ||
const TString & | Ycolumn, | ||
const TString & | selection = "" |
||
) |
Create and fill a TGraph from values Xcolumn and Ycolumn in table, using the selection if required
Definition at line 640 of file SQLiteDB.cpp.
delete rows from the table corresponding to selection
This is equivalent to
With no selection, deletes all rows of table (clear_table())
Definition at line 775 of file SQLiteDB.cpp.
void KVSQLite::database::Dump | ( | ) | const |
Print on stdout contents of database.
Definition at line 145 of file SQLiteDB.cpp.
void KVSQLite::database::end_data_insertion | ( | ) |
Call after prepare_data_insertion() & insert_data_row() have been used to insert data into a table
Definition at line 405 of file SQLiteDB.cpp.
KVNumberList KVSQLite::database::get_integer_list | ( | const TString & | table, |
const TString & | column, | ||
const TString & | selection = "" , |
||
const TString & | anything_else = "" |
||
) |
DISTINCT
values of "column" (only 1 column name at a time) for given selection Definition at line 571 of file SQLiteDB.cpp.
KVNameValueList KVSQLite::database::get_name_value_list | ( | const TString & | tablename, |
const TString & | name_column, | ||
const TString & | value_column, | ||
const TString & | selection = "" , |
||
const TString & | anything_else = "" |
||
) |
Fill KVNameValueList with selected rows from table, adding for each row a parameter with the name contained in "name_column" (must be of type TEXT
) and the value contained in "value_column" (can be INTEGER
, REAL
, or TEXT
)
Definition at line 616 of file SQLiteDB.cpp.
bool KVSQLite::database::get_next_result | ( | ) | const |
Retrieve next result row resulting from previous call to select_data()
Definition at line 526 of file SQLiteDB.cpp.
|
inline |
Definition at line 418 of file SQLiteDB.h.
TString KVSQLite::database::get_string_list | ( | const TString & | table, |
const TString & | column, | ||
const TString & | selection = "" , |
||
const TString & | anything_else = "" |
||
) |
Definition at line 592 of file SQLiteDB.cpp.
|
inline |
Definition at line 437 of file SQLiteDB.h.
|
inline |
Definition at line 450 of file SQLiteDB.h.
void KVSQLite::database::insert_data_row | ( | ) |
Call (repeatedly) after a call to prepare_data_insertion() in order to insert current contents of table columns as a new row in the database.
Value of each column should first be set like this:
Call end_data_insertion() when all data has been inserted
Definition at line 365 of file SQLiteDB.cpp.
|
inline |
Definition at line 423 of file SQLiteDB.h.
|
inline |
Definition at line 442 of file SQLiteDB.h.
Open/create sqlite db file given path
[in] | dbfile | full path to file |
Definition at line 97 of file SQLiteDB.cpp.
Definition at line 412 of file SQLiteDB.h.
|
inline |
Definition at line 456 of file SQLiteDB.h.
|
inline |
Definition at line 465 of file SQLiteDB.h.
bool KVSQLite::database::prepare_data_insertion | ( | const TString & | table | ) |
Call this method before insert_dat_row() in order to perform bulk data insertion operation. i.e. something like:
Until method end_data_insertion() is called, you cannot call prepare_data_insertion() with a different table name.
Definition at line 243 of file SQLiteDB.cpp.
void KVSQLite::database::print_selection | ( | const TString & | table, |
const TString & | columns, | ||
const TString & | condition, | ||
int | column_width = 20 |
||
) | const |
Print on stdout contents of database.
Definition at line 166 of file SQLiteDB.cpp.
|
private |
Definition at line 117 of file SQLiteDB.cpp.
|
private |
initialise map of database tables from existing database
Definition at line 51 of file SQLiteDB.cpp.
bool KVSQLite::database::select_data | ( | const TString & | table, |
const TString & | columns = "*" , |
||
const TString & | selection = "" , |
||
bool | distinct = false , |
||
const TString & | anything_else = "" |
||
) | const |
Select data in database from given table according to
In order to retrieve results, call get_next_result() until it returns false.
columns | ="*" by default, i.e. data from all columns is retrieved. If specific column data is to be selected, give a comma-separated list of column names. These will be quoted correctly in case they contain spaces. |
distinct | can be used in conjunction with a selection of specific columns in order to retrieve only rows of data with different values for the column(s). |
Definition at line 441 of file SQLiteDB.cpp.
|
private |
[in] | table | name of table |
[in] | columns | comma-separated list of columns |
[in] | condition | selection to be applied, if any |
SELECT [columns] FROM [table] WHERE [condition]
Definition at line 33 of file SQLiteDB.cpp.
void KVSQLite::database::show_tables | ( | ) | const |
print list of tables
Definition at line 77 of file SQLiteDB.cpp.
bool KVSQLite::database::update | ( | const TString & | table, |
const TString & | columns, | ||
const TString & | selection = "" |
||
) |
update the given columns of an entry in the table corresponding to selection (if given) the current values of the data members of the columns will be used
This is equivalent to
Definition at line 717 of file SQLiteDB.cpp.
|
mutableprivate |
Definition at line 382 of file SQLiteDB.h.
|
private |
Definition at line 375 of file SQLiteDB.h.
|
mutableprivate |
Definition at line 385 of file SQLiteDB.h.
|
mutableprivate |
Definition at line 383 of file SQLiteDB.h.
|
private |
Definition at line 386 of file SQLiteDB.h.
|
mutableprivate |
Definition at line 387 of file SQLiteDB.h.
|
mutableprivate |
Definition at line 384 of file SQLiteDB.h.
|
mutableprivate |
Definition at line 381 of file SQLiteDB.h.
|
mutableprivate |
Definition at line 377 of file SQLiteDB.h.