KaliVeda
Toolkit for HIC analysis
|
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 401 of file SQLiteDB.h.
#include <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 (const table &) |
void | clear_table (const TString &name) |
Delete all data from table. | |
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. | |
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="") |
KVSQLite::table & | get_table (const TString &name) |
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_selected_data (const TString &tables, const TString &columns="*", const TString &selection="", bool distinct=false, const TString &anything_else="") |
Print out results of a call to select_data(). | |
void | print_selection (const TString &table, const TString &columns, const TString &condition, int column_width=20) const |
Print on stdout contents of database. | |
bool | select_data (const TString &tables, const TString &columns="*", const TString &selection="", bool distinct=false, const TString &anything_else="") const |
void | show_tables () const |
print list of tables | |
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 | |
std::unique_ptr< TSQLResult > | SelectRowsFromTable (const TString &table, const TString &columns="*", const TString &condition="") const |
Private Attributes | |
table * | fBulkTable |
std::unique_ptr< TSQLiteServer > | fDBserv |
bool | fEmptyResultSet |
bool | fInserting |
bool | fIsValid |
TString | fSelectedColumns |
bool | fSelecting |
std::unique_ptr< TSQLStatement > | fSQLstmt |
std::list< const column * > | fSQLstmtCols |
std::unordered_map< std::string, KVSQLite::table > | fTables |
|
inline |
Definition at line 422 of file SQLiteDB.h.
|
inline |
Definition at line 423 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 427 of file SQLiteDB.h.
|
inlinevirtual |
Definition at line 446 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 855 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 870 of file SQLiteDB.cpp.
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 219 of file SQLiteDB.cpp.
Delete all data from table.
Definition at line 723 of file SQLiteDB.cpp.
|
inline |
Definition at line 459 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 903 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 739 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 699 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 834 of file SQLiteDB.cpp.
void KVSQLite::database::Dump | ( | ) | const |
Print on stdout contents of database.
Definition at line 171 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 433 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 630 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 675 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 595 of file SQLiteDB.cpp.
|
inline |
Definition at line 442 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 651 of file SQLiteDB.cpp.
|
inline |
Definition at line 491 of file SQLiteDB.h.
|
inline |
Definition at line 464 of file SQLiteDB.h.
|
inline |
Definition at line 477 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 393 of file SQLiteDB.cpp.
|
inline |
Definition at line 450 of file SQLiteDB.h.
|
inline |
Definition at line 469 of file SQLiteDB.h.
Open/create sqlite db file given path
Any special characters/environment variables are first expanded, so you can use:
Definition at line 110 of file SQLiteDB.cpp.
Definition at line 436 of file SQLiteDB.h.
|
inline |
Definition at line 483 of file SQLiteDB.h.
|
inline |
Definition at line 487 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 269 of file SQLiteDB.cpp.
void KVSQLite::database::print_selected_data | ( | const TString & | tables, |
const TString & | columns = "*" , |
||
const TString & | selection = "" , |
||
bool | distinct = false , |
||
const TString & | anything_else = "" |
||
) |
Print out results of a call to select_data().
Definition at line 458 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 192 of file SQLiteDB.cpp.
|
private |
Definition at line 143 of file SQLiteDB.cpp.
|
private |
initialise map of database tables from existing database
Definition at line 52 of file SQLiteDB.cpp.
bool KVSQLite::database::select_data | ( | const TString & | tables, |
const TString & | columns = "*" , |
||
const TString & | selection = "" , |
||
bool | distinct = false , |
||
const TString & | anything_else = "" |
||
) | const |
Select data in database from given table(s) according to
In order to retrieve results, call get_next_result() until it returns false.
tables | if more than 1 table is given, separate table names with commas. if 1 table has a foreign key referencing the other, this allows to JOIN data in both tables together. [columns] can then refer to columns in either table. |
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 493 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 34 of file SQLiteDB.cpp.
void KVSQLite::database::show_tables | ( | ) | const |
print list of tables
Definition at line 84 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 776 of file SQLiteDB.cpp.
|
mutableprivate |
Definition at line 406 of file SQLiteDB.h.
|
private |
Definition at line 402 of file SQLiteDB.h.
|
mutableprivate |
Definition at line 409 of file SQLiteDB.h.
|
mutableprivate |
Definition at line 407 of file SQLiteDB.h.
|
private |
Definition at line 410 of file SQLiteDB.h.
|
mutableprivate |
Definition at line 411 of file SQLiteDB.h.
|
mutableprivate |
Definition at line 408 of file SQLiteDB.h.
|
mutableprivate |
Definition at line 404 of file SQLiteDB.h.
|
mutableprivate |
Definition at line 405 of file SQLiteDB.h.
|
mutableprivate |
Definition at line 403 of file SQLiteDB.h.