KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
KVSQLite::table Class Reference

Detailed Description

Examples
db_sqlite_examples.C.

Definition at line 268 of file SQLiteDB.h.

#include <SQLiteDB.h>

Public Member Functions

 table (const TString &Name, const std::vector< KVSQLite::column > &cols)
 
 table (const TString &Name="")
 
virtual ~table ()
 
columnadd_column (const KVSQLite::column &c)
 
columnadd_column (const TString &name, const TString &type)
 
columnadd_column (const TString &name, KVSQLite_column_type type)
 
const columnadd_foreign_key (const table &other_table, const column &other_column)
 
const columnadd_foreign_key (const TString &other_table, const TString &other_column)
 
const columnadd_primary_key (const TString &name)
 
int check_columns (const KVNameValueList &)
 
KVSQLite::columnget_column (const TString &n)
 
KVSQLite::columnget_column (int i)
 
TString get_column_names (const TString &exclude="", const TString &delim=",") const
 
const char * get_insert_command () const
 
bool has_column (const TString &name) const
 
bool is_temporary () const
 
const char * name () const
 
int number_of_columns () const
 
KVSQLite::columnoperator[] (const TString &n)
 
const KVSQLite::columnoperator[] (const TString &n) const
 
KVSQLite::columnoperator[] (int i)
 
const KVSQLite::columnoperator[] (int i) const
 
void prepare_data (const KVNameValueList &, const KVNamedParameter *=nullptr)
 
void print () const
 
void set_all_columns_null ()
 set the value of all columns in the table to NULL
 
void set_insert_mode (KVSQLite_insert_mode i)
 
void set_name (const TString &name)
 
void set_temporary (bool temp=true)
 
void show_columns () const
 print list of columns
 

Private Member Functions

void init_type_map ()
 

Private Attributes

std::unordered_map< std::string, int > fColMap
 
std::vector< KVSQLite::columnfColumns
 
KVSQLite_insert_mode fInsert
 
TString fName
 
bool fTemp
 

Static Private Attributes

static std::map< TString, KVSQLite::column_type::typestype_map
 

Constructor & Destructor Documentation

◆ table() [1/2]

KVSQLite::table::table ( const TString Name = "")
inline

Definition at line 285 of file SQLiteDB.h.

◆ table() [2/2]

KVSQLite::table::table ( const TString Name,
const std::vector< KVSQLite::column > &  cols 
)
inline

Definition at line 290 of file SQLiteDB.h.

◆ ~table()

virtual KVSQLite::table::~table ( )
inlinevirtual

Definition at line 296 of file SQLiteDB.h.

Member Function Documentation

◆ add_column() [1/3]

column & table::add_column ( const KVSQLite::column c)

add column to table

Returns
reference to added column.
Note
cannot be used for existing table in database: see database::add_column()
Examples
db_sqlite_examples.C.

Definition at line 1115 of file SQLiteDB.cpp.

◆ add_column() [2/3]

column & table::add_column ( const TString name,
const TString type 
)

add column to table

Returns
reference to added column
Note
cannot be used for existing table in database: see database::add_column()

Definition at line 1133 of file SQLiteDB.cpp.

◆ add_column() [3/3]

column & KVSQLite::table::add_column ( const TString name,
KVSQLite_column_type  type 
)
inline

add column to table. return reference to added column.

Definition at line 338 of file SQLiteDB.h.

◆ add_foreign_key() [1/2]

const column & table::add_foreign_key ( const table other_table,
const column other_column 
)

add a foreign key to the table, which is an INTEGER reference to another column in another table.

Returns
reference to key (cannot be modified)
Note
as foreign keys are only really useful if they have the same name in the child and parent tables, we set the name of the foreign key by default to that of the other_column

Definition at line 1201 of file SQLiteDB.cpp.

◆ add_foreign_key() [2/2]

const column & table::add_foreign_key ( const TString other_table,
const TString other_column 
)

add a foreign key to the table, which is an INTEGER reference to another column in another table

Returns
reference to key (cannot be modified)
Note
as foreign keys are only really useful if they have the same name in the child and parent tables, we set the name of the foreign key by default to that of the other_column

Definition at line 1177 of file SQLiteDB.cpp.

◆ add_primary_key()

const column & table::add_primary_key ( const TString name)

add a PRIMARY KEY column to the table

Returns
reference to primary key (cannot be modified)
Note
by default this is an INTEGER type column
as it is auto-incremented with each inserted row, it should not be included in TSQLStatement used to write data to db
Examples
db_sqlite_examples.C.

Definition at line 1152 of file SQLiteDB.cpp.

◆ check_columns()

int table::check_columns ( const KVNameValueList l)

make sure that all parameters in the list have corresponding columns in the table

Returns
the number of columns to be added

Definition at line 1221 of file SQLiteDB.cpp.

◆ get_column() [1/2]

KVSQLite::column & KVSQLite::table::get_column ( const TString n)
inline

Definition at line 373 of file SQLiteDB.h.

◆ get_column() [2/2]

KVSQLite::column & KVSQLite::table::get_column ( int  i)
inline

Definition at line 355 of file SQLiteDB.h.

◆ get_column_names()

TString table::get_column_names ( const TString exclude = "",
const TString delim = "," 
) const

Return a comma-separated list of the colum names

Parameters
[in]delimseparator to use in list (default: ",")
[in]excludelist of column names to exclude from list

Definition at line 1282 of file SQLiteDB.cpp.

◆ get_insert_command()

const char * table::get_insert_command ( ) const

Definition at line 336 of file SQLiteDB.cpp.

◆ has_column()

bool KVSQLite::table::has_column ( const TString name) const
inline

return true if column with given name exists

Definition at line 359 of file SQLiteDB.h.

◆ init_type_map()

void table::init_type_map ( )
private

Definition at line 1082 of file SQLiteDB.cpp.

◆ is_temporary()

bool KVSQLite::table::is_temporary ( ) const
inline

Definition at line 332 of file SQLiteDB.h.

◆ name()

const char * KVSQLite::table::name ( ) const
inline

Definition at line 298 of file SQLiteDB.h.

◆ number_of_columns()

int KVSQLite::table::number_of_columns ( ) const
inline

Definition at line 388 of file SQLiteDB.h.

◆ operator[]() [1/4]

KVSQLite::column & KVSQLite::table::operator[] ( const TString n)
inline

Definition at line 365 of file SQLiteDB.h.

◆ operator[]() [2/4]

const KVSQLite::column & KVSQLite::table::operator[] ( const TString n) const
inline

Definition at line 369 of file SQLiteDB.h.

◆ operator[]() [3/4]

KVSQLite::column & KVSQLite::table::operator[] ( int  i)
inline

Definition at line 351 of file SQLiteDB.h.

◆ operator[]() [4/4]

const KVSQLite::column & KVSQLite::table::operator[] ( int  i) const
inline

Definition at line 347 of file SQLiteDB.h.

◆ prepare_data()

void table::prepare_data ( const KVNameValueList l,
const KVNamedParameter null_value = nullptr 
)

fill all columns in table with data contained in KVNameValueList parameters having the same name.

any columns which do not appear in the KVNameValueList (except for PRIMARY KEY) will be set to 'null'

if required, any parameters with the same type&value as "null_value" will be set to 'null' too

Definition at line 1244 of file SQLiteDB.cpp.

◆ print()

void KVSQLite::table::print ( ) const
inline

Definition at line 383 of file SQLiteDB.h.

◆ set_all_columns_null()

void table::set_all_columns_null ( )

set the value of all columns in the table to NULL

Definition at line 1266 of file SQLiteDB.cpp.

◆ set_insert_mode()

void KVSQLite::table::set_insert_mode ( KVSQLite_insert_mode  i)
inline

The insert mode determines how to deal with errors caused by constraints The possible values of i are (with corresponding SQLite meaning):

KVSQLite::insert_mode::DEFAULT ("INSERT INTO [table] ...")
KVSQLite::insert_mode::FAIL ("INSERT OR FAIL INTO [table] ...")
- if any data in row being inserted fails a constraint on one or more
columns, insertion fails with error
KVSQLite::insert_mode::IGNORE ("INSERT OR IGNORE INTO [table] ...")
- if any data in row being inserted fails a constraint on one or more
columns, the row is silently ignored (existing row unchanged)
KVSQLite::insert_mode::REPLACE ("INSERT OR REPLACE INTO [table] ...")
- if any data in row being inserted fails a constraint on one or more
columns, we replace the old row with the new one

Definition at line 308 of file SQLiteDB.h.

◆ set_name()

void KVSQLite::table::set_name ( const TString name)
inline

Definition at line 302 of file SQLiteDB.h.

◆ set_temporary()

void KVSQLite::table::set_temporary ( bool  temp = true)
inline

Create a temporary table

Definition at line 327 of file SQLiteDB.h.

◆ show_columns()

void table::show_columns ( ) const

print list of columns

Definition at line 1095 of file SQLiteDB.cpp.

Member Data Documentation

◆ fColMap

std::unordered_map<std::string, int> KVSQLite::table::fColMap
mutableprivate

Definition at line 278 of file SQLiteDB.h.

◆ fColumns

std::vector<KVSQLite::column> KVSQLite::table::fColumns
mutableprivate

Definition at line 277 of file SQLiteDB.h.

◆ fInsert

KVSQLite_insert_mode KVSQLite::table::fInsert
private

Definition at line 276 of file SQLiteDB.h.

◆ fName

TString KVSQLite::table::fName
private

Definition at line 275 of file SQLiteDB.h.

◆ fTemp

bool KVSQLite::table::fTemp
private

Definition at line 280 of file SQLiteDB.h.

◆ type_map

std::map< TString, KVSQLite::column_type::types > table::type_map
staticprivate

Definition at line 279 of file SQLiteDB.h.