CernVM-FS
2.12.0
|
#include <sql.h>
Public Member Functions | |
Sql (sqlite3 *sqlite_db, const std::string &statement) | |
virtual | ~Sql () |
bool | Execute () |
bool | FetchRow () |
std::string | DebugResultTable () |
bool | Reset () |
int | GetLastError () const |
std::string | GetLastErrorMsg () const |
bool | BindBlob (const int index, const void *value, const unsigned size) |
bool | BindBlobTransient (const int index, const void *value, const unsigned size) |
bool | BindDouble (const int index, const double value) |
bool | BindInt (const int index, const int value) |
bool | BindInt64 (const int index, const sqlite3_int64 value) |
bool | BindNull (const int index) |
bool | BindTextTransient (const int index, const std::string &value) |
bool | BindTextTransient (const int index, const char *value, const int size) |
bool | BindText (const int index, const std::string &value) |
bool | BindText (const int index, const char *value, const int size, void(*dtor)(void *)=SQLITE_STATIC) |
template<typename T > | |
bool | Bind (const int index, const T &value) |
int | RetrieveType (const int idx_column) const |
int | RetrieveBytes (const int idx_column) const |
const void * | RetrieveBlob (const int idx_column) const |
double | RetrieveDouble (const int idx_column) const |
int | RetrieveInt (const int idx_column) const |
sqlite3_int64 | RetrieveInt64 (const int idx_column) const |
const unsigned char * | RetrieveText (const int idx_column) const |
std::string | RetrieveString (const int idx_column) const |
template<typename T > | |
T | Retrieve (const int index) |
template<> | |
bool | Bind (const int index, const int &value) |
template<> | |
bool | Bind (const int index, const unsigned int &value) |
template<> | |
bool | Bind (const int index, const uint64_t &value) |
template<> | |
bool | Bind (const int index, const sqlite3_int64 &value) |
template<> | |
bool | Bind (const int index, const std::string &value) |
template<> | |
bool | Bind (const int index, const float &value) |
template<> | |
bool | Bind (const int index, const double &value) |
template<> | |
int | Retrieve (const int index) |
template<> | |
bool | Retrieve (const int index) |
template<> | |
sqlite3_int64 | Retrieve (const int index) |
template<> | |
uint64_t | Retrieve (const int index) |
template<> | |
std::string | Retrieve (const int index) |
template<> | |
float | Retrieve (const int index) |
template<> | |
double | Retrieve (const int index) |
Protected Member Functions | |
Sql () | |
bool | IsInitialized () const |
bool | Init (const sqlite3 *database, const std::string &statement) |
void | DeferredInit (const sqlite3 *database, const char *statement) |
bool | Successful () const |
Private Member Functions | |
bool | Init (const char *statement) |
void | LazyInit () |
Private Attributes | |
sqlite3 * | database_ |
sqlite3_stmt * | statement_ |
const char * | query_string_ |
int | last_error_code_ |
Base class for all SQL statement classes. It wraps a single SQL statement and all necessary calls of the sqlite3 API to deal with this statement.
NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE * NOTE This base class implements a lazy initialization of the SQLite * NOTE prepared statement. Therefore it is strongly discouraged to use * NOTE any sqlite3_***() functions directly in the subclasses. Instead * NOTE one must wrap them in this base class and implement the lazy * NOTE initialization scheme as seen below. * NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE *
Derived classes can decide if their statement should be prepared immediately or on first use (aka lazily). The derived constructor must call Sql::Init() or Sql::DeferredInit() accordingly.
Sql objects created via the public constructor rather than by the constructor of a derived class are prepared immediately by default.
sqlite::Sql::Sql | ( | sqlite3 * | sqlite_db, |
const std::string & | statement | ||
) |
|
virtual |
|
inline |
Figures out the type to be bound by template parameter deduction NOTE: For strings this is suboptimal, since it needs to assume that the provided buffer is transient and copy it to be sure.
|
inline |
Definition at line 450 of file sql_impl.h.
|
inline |
Definition at line 455 of file sql_impl.h.
|
inline |
Definition at line 460 of file sql_impl.h.
|
inline |
Definition at line 465 of file sql_impl.h.
|
inline |
Definition at line 470 of file sql_impl.h.
|
inline |
Definition at line 475 of file sql_impl.h.
|
inline |
Definition at line 480 of file sql_impl.h.
|
inline |
Definition at line 355 of file sql.h.
Referenced by catalog::SqlCatalog::BindHashBlob().
|
inline |
|
inline |
Definition at line 371 of file sql.h.
Referenced by swissknife::CommandMigrate::MigrationWorker_217::UpdateCatalogSchema().
|
inline |
|
inline |
Definition at line 381 of file sql.h.
Referenced by history::SqlInsertBranch::BindBranch(), catalog::SqlCatalog::BindMd5(), SqlListReferences::BindOlderThan(), SqlInsertReference::BindReference(), SqlRemoveReference::BindReference(), SqlContainsReference::BindReference(), SqlGetTimestamp::BindReference(), history::SqlInsertTag::BindTag(), history::SqlFindTagByDate::BindTimestamp(), SqlListReferences::BindType(), swissknife::CommandMigrate::HardlinkRemovalMigrationWorker::BreakUpHardlinks(), swissknife::CommandMigrate::MigrationWorker_20x::GenerateCatalogStatistics(), swissknife::CommandMigrate::MigrationWorker_217::GenerateNewStatisticsCounters(), catalog::WritableCatalog::InsertBindMountpoint(), catalog::WritableCatalog::InsertNestedCatalog(), swissknife::CommandMigrate::MigrationWorker_20x::MigrateFileMetadata(), swissknife::CommandMigrate::MigrationWorker_20x::MigrateNestedCatalogMountPoints(), swissknife::CommandMigrate::BulkhashRemovalMigrationWorker::RemoveRedundantBulkHashes(), catalog::WritableCatalog::UpdateNestedCatalog(), and swissknife::CommandMigrate::AbstractMigrationWorker< DerivedT >::UpdateNestedCatalogReferences().
|
inline |
Definition at line 386 of file sql.h.
Referenced by catalog::SqlCatalog::BindHashBlob().
|
inline |
Definition at line 399 of file sql.h.
Referenced by history::SqlInsertBranch::BindBranch(), history::SqlFindBranchHead::BindBranchName(), history::SqlRemoveTag::BindName(), history::SqlFindTag::BindName(), history::SqlInsertTag::BindTag(), BindTextTransient(), catalog::WritableCatalog::InsertBindMountpoint(), catalog::WritableCatalog::InsertNestedCatalog(), catalog::WritableCatalog::RemoveBindMountpoint(), catalog::WritableCatalog::RemoveNestedCatalog(), catalog::WritableCatalog::UpdateNestedCatalog(), and swissknife::CommandMigrate::AbstractMigrationWorker< DerivedT >::UpdateNestedCatalogReferences().
|
inline |
|
inline |
Definition at line 391 of file sql.h.
Referenced by SqlInsertReference::BindReference(), SqlRemoveReference::BindReference(), SqlContainsReference::BindReference(), SqlGetTimestamp::BindReference(), and history::SqlInsertTag::BindTag().
|
inline |
std::string sqlite::Sql::DebugResultTable | ( | ) |
|
protected |
Defers the initialization of the prepared statement to the first usage to safe memory and CPU cycles for statements that are defined but never used. Typically this method is used in constructors of derived classes.
database | the sqlite database pointer to be query against |
statement | the query string to be prepared for execution |
Definition at line 158 of file sql.cc.
Referenced by SqlContainsReference::SqlContainsReference(), SqlCountReferences::SqlCountReferences(), history::SqlCountTags::SqlCountTags(), history::SqlGetHashes::SqlGetHashes(), SqlGetTimestamp::SqlGetTimestamp(), history::SqlInsertBranch::SqlInsertBranch(), history::SqlListBranches::SqlListBranches(), SqlListReferences::SqlListReferences(), history::SqlRecycleBinFlush::SqlRecycleBinFlush(), history::SqlRecycleBinList::SqlRecycleBinList(), SqlRemoveReference::SqlRemoveReference(), and history::SqlRemoveTag::SqlRemoveTag().
bool sqlite::Sql::Execute | ( | ) |
Executes the prepared statement. (this method should be used for modifying statements like DELETE or INSERT)
Definition at line 42 of file sql.cc.
Referenced by catalog::WritableCatalog::AddFileChunk(), swissknife::CommandMigrate::MigrationWorker_20x::AnalyzeFileLinkcounts(), swissknife::CommandMigrate::ChownMigrationWorker::ApplyPersonaMappings(), swissknife::CommandMigrate::MigrationWorker_20x::AttachOldCatalogDatabase(), swissknife::CommandMigrate::HardlinkRemovalMigrationWorker::BreakUpHardlinks(), catalog::CatalogDatabase::CompactDatabase(), sqlite::Database< DerivedT >::Configure(), catalog::WritableCatalog::CopyToParent(), history::HistoryDatabase::CreateBranchesTable(), ReflogDatabase::CreateEmptyDatabase(), swissknife::FileStatsDatabase::CreateEmptyDatabase(), history::HistoryDatabase::CreateEmptyDatabase(), catalog::CatalogDatabase::CreateEmptyDatabase(), StatisticsDatabase::CreateEmptyDatabase(), sqlite::Database< DerivedT >::CreatePropertiesTable(), history::HistoryDatabase::CreateRecycleBinTable(), history::HistoryDatabase::CreateTagsTable(), swissknife::CommandMigrate::MigrationWorker_20x::DetachOldCatalogDatabase(), swissknife::CommandMigrate::MigrationWorker_20x::FixNestedCatalogTransitionPoints(), catalog::WritableCatalog::IncLinkcount(), catalog::WritableCatalog::InitPreparedStatements(), catalog::WritableCatalog::InsertBindMountpoint(), catalog::CatalogDatabase::InsertInitialValues(), catalog::TreeCountersBase< FieldT >::InsertIntoDatabase(), catalog::WritableCatalog::InsertNestedCatalog(), history::HistoryDatabase::LiveSchemaUpgradeIfNecessary(), StatisticsDatabase::LiveSchemaUpgradeIfNecessary(), catalog::CatalogDatabase::LiveSchemaUpgradeIfNecessary(), swissknife::CommandMigrate::MigrationWorker_20x::MigrateFileMetadata(), swissknife::CommandMigrate::MigrationWorker_20x::MigrateNestedCatalogMountPoints(), swissknife::CommandFileStats::ProcessCatalog(), StatisticsDatabase::Prune(), history::SqliteHistory::PruneBranches(), catalog::WritableCatalog::RemoveBindMountpoint(), swissknife::CommandMigrate::MigrationWorker_20x::RemoveDanglingNestedMountpoints(), catalog::WritableCatalog::RemoveEntry(), catalog::WritableCatalog::RemoveFileChunks(), catalog::WritableCatalog::RemoveNestedCatalog(), swissknife::CommandMigrate::BulkhashRemovalMigrationWorker::RemoveRedundantBulkHashes(), StatisticsDatabase::StoreEntry(), catalog::WritableCatalog::TouchEntry(), swissknife::CommandMigrate::MigrationWorker_217::UpdateCatalogSchema(), catalog::WritableCatalog::UpdateEntry(), catalog::WritableCatalog::UpdateNestedCatalog(), swissknife::CommandMigrate::AbstractMigrationWorker< DerivedT >::UpdateNestedCatalogReferences(), history::HistoryDatabase::UpgradeSchemaRevision_10_1(), history::HistoryDatabase::UpgradeSchemaRevision_10_3(), sqlite::Database< DerivedT >::Vacuum(), and catalog::TreeCountersBase< FieldT >::WriteToDatabase().
bool sqlite::Sql::FetchRow | ( | ) |
Execute the prepared statement or fetch its next row. This method is intended to step through the result set. If it returns false this does not necessarily mean, that the actual statement execution failed, but that no row was fetched.
Definition at line 62 of file sql.cc.
Referenced by swissknife::CommandMigrate::MigrationWorker_20x::AnalyzeFileLinkcounts(), swissknife::CommandMigrate::AbstractMigrationWorker< DerivedT >::CollectAndAggregateStatistics(), DebugResultTable(), catalog::Catalog::FindNested(), swissknife::CommandMigrate::MigrationWorker_20x::FixNestedCatalogTransitionPoints(), swissknife::CommandMigrate::MigrationWorker_20x::GenerateCatalogStatistics(), swissknife::CommandMigrate::MigrationWorker_217::GenerateNewStatisticsCounters(), sqlite::Database< DerivedT >::GetFreePageRatio(), catalog::WritableCatalog::GetMaxLinkId(), catalog::Catalog::GetNumEntries(), catalog::Catalog::GetReferencedObjects(), catalog::CatalogDatabase::GetRowIdWasteRatio(), catalog::Catalog::ListingMd5Path(), catalog::Catalog::ListingMd5PathStat(), catalog::Catalog::ListMd5PathChunks(), catalog::Catalog::ListNestedCatalogs(), catalog::Catalog::ListOwnNestedCatalogs(), catalog::Catalog::LookupEntry(), catalog::Catalog::LookupXattrsMd5Path(), catalog::Catalog::OpenDatabase(), swissknife::CommandFileStats::ProcessCatalog(), history::SqliteHistory::PruneBranches(), catalog::TreeCountersBase< FieldT >::ReadFromDatabase(), swissknife::CommandMigrate::MigrationWorker_20x::RemoveDanglingNestedMountpoints(), and swissknife::CommandMigrate::StatsMigrationWorker::RepairStatisticsCounters().
|
inline |
Definition at line 343 of file sql.h.
Referenced by swissknife::Error(), Execute(), Init(), swissknife::CommandMigrate::MigrationWorker_20x::MigrateFileMetadata(), and catalog::Catalog::OpenDatabase().
std::string sqlite::Sql::GetLastErrorMsg | ( | ) | const |
Returns the english language error description of the last error happened in the context of the sqlite3 database object this statement is registered to. Note: In a multithreaded context it might be unpredictable which the actual last error is.
Definition at line 164 of file sql.cc.
Referenced by swissknife::Error(), and Execute().
|
protected |
Initializes the prepared statement immediately.
database | the sqlite database pointer to be query against |
statement | the query string to be prepared for execution |
Definition at line 132 of file sql.cc.
Referenced by LazyInit(), Sql(), and catalog::SqlCatalog::SqlCatalog().
|
private |
|
inlineprotected |
Definition at line 464 of file sql.h.
Referenced by LazyInit().
|
inlineprivate |
Definition at line 497 of file sql.h.
Referenced by BindBlob(), BindBlobTransient(), BindDouble(), BindInt(), BindInt64(), BindNull(), BindText(), Execute(), and FetchRow().
bool sqlite::Sql::Reset | ( | ) |
Reset a prepared statement to make it reusable.
Definition at line 126 of file sql.cc.
Referenced by catalog::WritableCatalog::AddFileChunk(), catalog::Catalog::FindNested(), swissknife::CommandMigrate::MigrationWorker_20x::FixNestedCatalogTransitionPoints(), catalog::WritableCatalog::GetMaxLinkId(), catalog::WritableCatalog::IncLinkcount(), catalog::TreeCountersBase< FieldT >::InsertIntoDatabase(), catalog::Catalog::ListingMd5Path(), catalog::Catalog::ListingMd5PathStat(), catalog::Catalog::ListMd5PathChunks(), catalog::Catalog::ListNestedCatalogs(), catalog::Catalog::ListOwnNestedCatalogs(), catalog::Catalog::LookupEntry(), catalog::Catalog::LookupXattrsMd5Path(), swissknife::CommandMigrate::MigrationWorker_20x::MigrateNestedCatalogMountPoints(), catalog::TreeCountersBase< FieldT >::ReadFromDatabase(), swissknife::CommandMigrate::MigrationWorker_20x::RemoveDanglingNestedMountpoints(), catalog::WritableCatalog::RemoveEntry(), catalog::WritableCatalog::RemoveFileChunks(), catalog::WritableCatalog::TouchEntry(), catalog::WritableCatalog::UpdateEntry(), swissknife::CommandMigrate::AbstractMigrationWorker< DerivedT >::UpdateNestedCatalogReferences(), and catalog::TreeCountersBase< FieldT >::WriteToDatabase().
|
inline |
|
inline |
Definition at line 486 of file sql_impl.h.
|
inline |
Definition at line 491 of file sql_impl.h.
|
inline |
Definition at line 496 of file sql_impl.h.
|
inline |
Definition at line 501 of file sql_impl.h.
|
inline |
Definition at line 506 of file sql_impl.h.
|
inline |
Definition at line 511 of file sql_impl.h.
|
inline |
Definition at line 516 of file sql_impl.h.
|
inline |
Definition at line 436 of file sql.h.
Referenced by swissknife::CommandFileStats::ProcessCatalog(), and catalog::SqlCatalog::RetrieveHashBlob().
|
inline |
Determines the number of bytes necessary to store the column's data as a string. This might involve type conversions and depends on which other RetrieveXXX methods were called on the same column index before!
See SQLite documentation for sqlite_column_bytes() for details: https://www.sqlite.org/c3ref/column_blob.html
Definition at line 433 of file sql.h.
Referenced by swissknife::CommandFileStats::ProcessCatalog(), and catalog::SqlCatalog::RetrieveHashBlob().
|
inline |
Definition at line 439 of file sql.h.
Referenced by DebugResultTable(), and catalog::CatalogDatabase::GetRowIdWasteRatio().
|
inline |
Definition at line 442 of file sql.h.
Referenced by swissknife::CommandFileStats::ProcessCatalog().
|
inline |
Definition at line 445 of file sql.h.
Referenced by swissknife::CommandMigrate::MigrationWorker_20x::AnalyzeFileLinkcounts(), swissknife::CommandMigrate::AbstractMigrationWorker< DerivedT >::CollectAndAggregateStatistics(), DebugResultTable(), swissknife::CommandMigrate::MigrationWorker_20x::GenerateCatalogStatistics(), swissknife::CommandMigrate::MigrationWorker_217::GenerateNewStatisticsCounters(), sqlite::Database< DerivedT >::GetFreePageRatio(), catalog::Catalog::GetNumEntries(), catalog::Catalog::OpenDatabase(), swissknife::CommandFileStats::ProcessCatalog(), swissknife::CommandMigrate::StatsMigrationWorker::RepairStatisticsCounters(), SqlContainsReference::RetrieveAnswer(), history::SqlListBranches::RetrieveBranch(), SqlCountReferences::RetrieveCount(), history::SqlCountTags::RetrieveCount(), SqlListReferences::RetrieveHash(), history::SqlRecycleBinList::RetrieveHash(), catalog::SqlCatalog::RetrieveMd5(), and SqlGetTimestamp::RetrieveTimestamp().
|
inline |
Definition at line 451 of file sql.h.
Referenced by history::SqlListBranches::RetrieveBranch(), SqlListReferences::RetrieveHash(), history::SqlGetHashes::RetrieveHash(), and history::SqlRecycleBinList::RetrieveHash().
|
inline |
Definition at line 448 of file sql.h.
Referenced by DebugResultTable(), catalog::SqlCatalog::RetrieveHashHex(), and RetrieveString().
|
inline |
Definition at line 421 of file sql.h.
Referenced by history::SqlListBranches::RetrieveBranch().
|
inlineprotected |
Checks the last action for success
Definition at line 489 of file sql.h.
Referenced by BindBlob(), BindBlobTransient(), BindDouble(), BindInt(), BindInt64(), BindNull(), BindText(), Execute(), Init(), Reset(), and ~Sql().
|
private |
Definition at line 506 of file sql.h.
Referenced by DeferredInit(), GetLastErrorMsg(), Init(), and LazyInit().
|
private |
Definition at line 509 of file sql.h.
Referenced by BindBlob(), BindBlobTransient(), BindDouble(), BindInt(), BindInt64(), BindNull(), BindText(), Execute(), FetchRow(), GetLastError(), Init(), Reset(), Successful(), and ~Sql().
|
private |
Definition at line 508 of file sql.h.
Referenced by DeferredInit(), and LazyInit().
|
private |
Definition at line 507 of file sql.h.
Referenced by BindBlob(), BindBlobTransient(), BindDouble(), BindInt(), BindInt64(), BindNull(), BindText(), DebugResultTable(), Execute(), FetchRow(), Init(), IsInitialized(), Reset(), RetrieveBlob(), RetrieveBytes(), RetrieveDouble(), RetrieveInt(), RetrieveInt64(), RetrieveText(), RetrieveType(), and ~Sql().