KaliVeda  1.12/06
Heavy-Ion Analysis Toolkit
List of all members | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
KVSQLite::table Class Reference

Examples
db_sqlite_examples.C.

Definition at line 253 of file 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 TString &name, const table &other_table, const column &other_column)
 
const columnadd_foreign_key (const TString &name, const TString &other_table, const TString &other_column)
 
const columnadd_primary_key (const TString &name)
 
int check_columns (const KVNameValueList &)
 
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)
 
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 More...
 
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 More...
 

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
 

#include <SQLiteDB.h>

Constructor & Destructor Documentation

◆ table() [1/2]

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

Definition at line 268 of file SQLiteDB.h.

◆ table() [2/2]

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

Definition at line 273 of file SQLiteDB.h.

◆ ~table()

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

Definition at line 278 of file SQLiteDB.h.

Member Function Documentation

◆ add_column() [1/3]

column & KVSQLite::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 1056 of file SQLiteDB.cpp.

◆ add_column() [2/3]

column & KVSQLite::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 1073 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 320 of file SQLiteDB.h.

◆ add_foreign_key() [1/2]

const column & KVSQLite::table::add_foreign_key ( const TString name,
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)

Definition at line 1132 of file SQLiteDB.cpp.

◆ add_foreign_key() [2/2]

const column & KVSQLite::table::add_foreign_key ( const TString name,
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)

Definition at line 1114 of file SQLiteDB.cpp.

◆ add_primary_key()

const column & KVSQLite::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 1092 of file SQLiteDB.cpp.

◆ check_columns()

int KVSQLite::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 1149 of file SQLiteDB.cpp.

◆ get_insert_command()

const char * KVSQLite::table::get_insert_command ( ) const

Definition at line 310 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 333 of file SQLiteDB.h.

◆ init_type_map()

void KVSQLite::table::init_type_map ( )
private

Definition at line 1023 of file SQLiteDB.cpp.

◆ is_temporary()

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

Definition at line 314 of file SQLiteDB.h.

◆ name()

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

Definition at line 280 of file SQLiteDB.h.

◆ number_of_columns()

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

Definition at line 363 of file SQLiteDB.h.

◆ operator[]() [1/3]

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

Definition at line 339 of file SQLiteDB.h.

◆ operator[]() [2/3]

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

Definition at line 348 of file SQLiteDB.h.

◆ operator[]() [3/3]

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

Definition at line 329 of file SQLiteDB.h.

◆ prepare_data()

void KVSQLite::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 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 1172 of file SQLiteDB.cpp.

◆ print()

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

Definition at line 358 of file SQLiteDB.h.

◆ set_all_columns_null()

void KVSQLite::table::set_all_columns_null ( )

set the value of all columns in the table to NULL

Definition at line 1194 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
if(M) return M -> method
table(const TString &Name="")
Definition: SQLiteDB.h:268

Definition at line 290 of file SQLiteDB.h.

◆ set_name()

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

Definition at line 284 of file SQLiteDB.h.

◆ set_temporary()

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

Create a temporary table

Definition at line 309 of file SQLiteDB.h.

◆ show_columns()

void KVSQLite::table::show_columns ( ) const

print list of columns

Definition at line 1036 of file SQLiteDB.cpp.

Member Data Documentation

◆ fColMap

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

Definition at line 258 of file SQLiteDB.h.

◆ fColumns

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

Definition at line 256 of file SQLiteDB.h.

◆ fInsert

KVSQLite_insert_mode KVSQLite::table::fInsert
private

Definition at line 255 of file SQLiteDB.h.

◆ fName

TString KVSQLite::table::fName
private

Definition at line 254 of file SQLiteDB.h.

◆ fTemp

bool KVSQLite::table::fTemp
private

Definition at line 263 of file SQLiteDB.h.

◆ type_map

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

Definition at line 262 of file SQLiteDB.h.


The documentation for this class was generated from the following files: