OmniSciDB  7bf56492aa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SqliteConnector Class Reference

#include <SqliteConnector.h>

+ Collaboration diagram for SqliteConnector:

Classes

struct  NullableResult
 

Public Member Functions

 SqliteConnector (const std::string &dbName, const std::string &dir=".")
 
 SqliteConnector (sqlite3 *db)
 
virtual ~SqliteConnector ()
 
virtual void query (const std::string &queryString)
 
virtual void query_with_text_params (std::string const &query_only)
 
template<typename STRING_CONTAINER >
void query_with_text_params (STRING_CONTAINER const &query_and_text_params)
 
virtual void query_with_text_params (const std::string &queryString, const std::vector< std::string > &text_param)
 
virtual void query_with_text_param (const std::string &queryString, const std::string &text_param)
 
virtual size_t getNumRows () const
 
virtual size_t getNumCols () const
 
template<typename T >
getData (const int row, const int col)
 
bool isNull (const int row, const int col) const
 
auto getSqlitePtr () const
 

Public Attributes

std::vector< std::string > columnNames
 
std::vector< int > columnTypes
 

Private Member Functions

void throwError ()
 

Private Attributes

sqlite3 * db_
 
std::string dbName_
 
bool atFirstResult_
 
std::vector< std::vector
< NullableResult > > 
results_
 
size_t numCols_
 
size_t numRows_
 

Detailed Description

Definition at line 32 of file SqliteConnector.h.

Constructor & Destructor Documentation

SqliteConnector::SqliteConnector ( const std::string &  dbName,
const std::string &  dir = "." 
)
SqliteConnector::SqliteConnector ( sqlite3 *  db)

Definition at line 44 of file SqliteConnector.cpp.

44 : db_(db) {}
SqliteConnector::~SqliteConnector ( )
virtual

Definition at line 46 of file SqliteConnector.cpp.

References db_, and dbName_.

46  {
47  if (!dbName_.empty()) {
48  sqlite3_close(db_);
49  }
50 }
std::string dbName_

Member Function Documentation

template<typename T >
T SqliteConnector::getData ( const int  row,
const int  col 
)
inline

Definition at line 58 of file SqliteConnector.h.

References assert(), numCols_, numRows_, and results_.

Referenced by Catalog_Namespace::Catalog::addColumn(), Catalog_Namespace::Catalog::addForeignTableDetails(), Catalog_Namespace::Catalog::buildForeignServerMap(), Catalog_Namespace::Catalog::buildMaps(), Catalog_Namespace::Catalog::createDashboard(), Catalog_Namespace::Catalog::createDashboardSystemRoles(), Catalog_Namespace::Catalog::createForeignServerNoLocks(), Catalog_Namespace::Catalog::createLink(), Catalog_Namespace::Catalog::createTable(), Catalog_Namespace::Catalog::delDictionary(), Catalog_Namespace::Catalog::dropForeignServer(), Catalog_Namespace::Catalog::dropFsiSchemasAndTables(), Catalog_Namespace::Catalog::executeDropTableSqliteQueries(), Catalog_Namespace::Catalog::getForeignServerSkipCache(), migrations::MigrationMgr::migrateDateInDaysMetadata(), Catalog_Namespace::Catalog::recordOwnershipOfObjectsInObjectPermissions(), Catalog_Namespace::Catalog::replaceDashboard(), SqliteMemDatabase::runSelect(), Catalog_Namespace::Catalog::setColumnDictionary(), Catalog_Namespace::Catalog::updateDeletedColumnIndicator(), Catalog_Namespace::Catalog::updateDictionaryNames(), Catalog_Namespace::Catalog::updateDictionarySchema(), Catalog_Namespace::Catalog::updateFrontendViewSchema(), Catalog_Namespace::Catalog::updateLinkSchema(), Catalog_Namespace::Catalog::updatePageSize(), and Catalog_Namespace::Catalog::updateTableDescriptorSchema().

58  {
59  assert(row < static_cast<int>(numRows_));
60  assert(col < static_cast<int>(numCols_));
61  return boost::lexical_cast<T>(results_[col][row].result);
62  }
std::vector< std::vector< NullableResult > > results_
int64_t const int32_t sz assert(dest)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

virtual size_t SqliteConnector::getNumCols ( ) const
inlinevirtual

Definition at line 55 of file SqliteConnector.h.

References numCols_.

Referenced by SqliteMemDatabase::runSelect().

55 { return numCols_; }

+ Here is the caller graph for this function:

virtual size_t SqliteConnector::getNumRows ( ) const
inlinevirtual

Definition at line 54 of file SqliteConnector.h.

References numRows_.

Referenced by Catalog_Namespace::Catalog::addForeignTableDetails(), Catalog_Namespace::Catalog::buildForeignServerMap(), Catalog_Namespace::Catalog::buildMaps(), Catalog_Namespace::Catalog::createDashboard(), Catalog_Namespace::Catalog::createDashboardSystemRoles(), Catalog_Namespace::Catalog::createForeignServerNoLocks(), Catalog_Namespace::Catalog::createLink(), Catalog_Namespace::Catalog::dropForeignServer(), Catalog_Namespace::Catalog::dropFsiSchemasAndTables(), Catalog_Namespace::Catalog::executeDropTableSqliteQueries(), Catalog_Namespace::Catalog::getForeignServerSkipCache(), migrations::MigrationMgr::migrateDateInDaysMetadata(), Catalog_Namespace::Catalog::recordOwnershipOfObjectsInObjectPermissions(), Catalog_Namespace::Catalog::replaceDashboard(), SqliteMemDatabase::runSelect(), Catalog_Namespace::Catalog::updateDeletedColumnIndicator(), Catalog_Namespace::Catalog::updateDictionaryNames(), Catalog_Namespace::Catalog::updateDictionarySchema(), Catalog_Namespace::Catalog::updateFixlenArrayColumns(), Catalog_Namespace::Catalog::updateFrontendViewAndLinkUsers(), Catalog_Namespace::Catalog::updateFrontendViewSchema(), Catalog_Namespace::Catalog::updateFrontendViewsToDashboards(), Catalog_Namespace::Catalog::updateGeoColumns(), Catalog_Namespace::Catalog::updateLinkSchema(), Catalog_Namespace::Catalog::updatePageSize(), and Catalog_Namespace::Catalog::updateTableDescriptorSchema().

54 { return numRows_; }

+ Here is the caller graph for this function:

auto SqliteConnector::getSqlitePtr ( ) const
inline

Definition at line 73 of file SqliteConnector.h.

References db_.

73 { return db_; }
bool SqliteConnector::isNull ( const int  row,
const int  col 
) const
inline

Definition at line 64 of file SqliteConnector.h.

References assert(), numCols_, numRows_, and results_.

Referenced by Catalog_Namespace::Catalog::buildMaps(), and SqliteMemDatabase::runSelect().

64  {
65  assert(row < static_cast<int>(numRows_));
66  assert(col < static_cast<int>(numCols_));
67  return results_[col][row].is_null;
68  }
std::vector< std::vector< NullableResult > > results_
int64_t const int32_t sz assert(dest)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SqliteConnector::query ( const std::string &  queryString)
virtual

Definition at line 115 of file SqliteConnector.cpp.

References query_with_text_params().

Referenced by Catalog_Namespace::Catalog::addForeignTableDetails(), Catalog_Namespace::Catalog::buildForeignServerMap(), Catalog_Namespace::Catalog::buildMaps(), Catalog_Namespace::Catalog::createDashboard(), Catalog_Namespace::Catalog::createDashboardSystemRoles(), Catalog_Namespace::Catalog::createFsiSchemasAndDefaultServers(), Catalog_Namespace::Catalog::createLink(), Catalog_Namespace::Catalog::createTable(), Catalog_Namespace::Catalog::deleteMetadataForDashboard(), Catalog_Namespace::Catalog::dropFsiSchemasAndTables(), Catalog_Namespace::Catalog::dropTable(), migrations::MigrationMgr::migrateDateInDaysMetadata(), query_with_text_params(), Catalog_Namespace::Catalog::recordOwnershipOfObjectsInObjectPermissions(), Catalog_Namespace::Catalog::renameColumn(), Catalog_Namespace::Catalog::renamePhysicalTable(), Catalog_Namespace::Catalog::replaceDashboard(), SqliteMemDatabase::runSelect(), Catalog_Namespace::Catalog::updateDeletedColumnIndicator(), Catalog_Namespace::Catalog::updateDictionaryNames(), Catalog_Namespace::Catalog::updateDictionarySchema(), Catalog_Namespace::Catalog::updateFixlenArrayColumns(), Catalog_Namespace::Catalog::updateFrontendViewAndLinkUsers(), Catalog_Namespace::Catalog::updateFrontendViewSchema(), Catalog_Namespace::Catalog::updateFrontendViewsToDashboards(), Catalog_Namespace::Catalog::updateGeoColumns(), Catalog_Namespace::Catalog::updateLinkSchema(), Catalog_Namespace::Catalog::updateLogicalToPhysicalTableLinkSchema(), Catalog_Namespace::Catalog::updateLogicalToPhysicalTableMap(), Catalog_Namespace::Catalog::updatePageSize(), and Catalog_Namespace::Catalog::updateTableDescriptorSchema().

115  {
116  query_with_text_params(queryString, std::vector<std::string>{});
117 }
virtual void query_with_text_params(std::string const &query_only)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SqliteConnector::query_with_text_param ( const std::string &  queryString,
const std::string &  text_param 
)
virtual

Definition at line 110 of file SqliteConnector.cpp.

References query_with_text_params().

Referenced by Catalog_Namespace::Catalog::createLink(), Catalog_Namespace::Catalog::createTable(), Catalog_Namespace::Catalog::delDictionary(), Catalog_Namespace::Catalog::dropForeignServer(), Catalog_Namespace::Catalog::dropTable(), Catalog_Namespace::Catalog::executeDropTableSqliteQueries(), and Catalog_Namespace::Catalog::setColumnDictionary().

111  {
112  query_with_text_params(queryString, std::vector<std::string>{text_param});
113 }
virtual void query_with_text_params(std::string const &query_only)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

virtual void SqliteConnector::query_with_text_params ( std::string const &  query_only)
inlinevirtual

Definition at line 39 of file SqliteConnector.h.

References query().

Referenced by Catalog_Namespace::Catalog::addColumn(), Catalog_Namespace::Catalog::addReferenceToForeignDict(), Catalog_Namespace::Catalog::createDashboard(), Catalog_Namespace::Catalog::createDashboardSystemRoles(), Catalog_Namespace::Catalog::createForeignServerNoLocks(), Catalog_Namespace::Catalog::createLink(), Catalog_Namespace::Catalog::createTable(), Catalog_Namespace::Catalog::deleteMetadataForDashboard(), Catalog_Namespace::Catalog::dropColumn(), Catalog_Namespace::Catalog::dropForeignServer(), Catalog_Namespace::Catalog::executeDropTableSqliteQueries(), Catalog_Namespace::Catalog::getForeignServerSkipCache(), migrations::MigrationMgr::migrateDateInDaysMetadata(), query(), query_with_text_param(), query_with_text_params(), Catalog_Namespace::Catalog::recordOwnershipOfObjectsInObjectPermissions(), Catalog_Namespace::Catalog::renameColumn(), Catalog_Namespace::Catalog::renamePhysicalTable(), Catalog_Namespace::Catalog::replaceDashboard(), Catalog_Namespace::Catalog::setColumnDictionary(), Catalog_Namespace::Catalog::setColumnSharedDictionary(), Catalog_Namespace::Catalog::updateFixlenArrayColumns(), Catalog_Namespace::Catalog::updateGeoColumns(), and Catalog_Namespace::Catalog::updateLogicalToPhysicalTableMap().

39  {
40  query(query_only);
41  }
virtual void query(const std::string &queryString)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename STRING_CONTAINER >
void SqliteConnector::query_with_text_params ( STRING_CONTAINER const &  query_and_text_params)
inline

Definition at line 43 of file SqliteConnector.h.

References query_with_text_params().

43  {
45  *query_and_text_params.begin(),
46  std::vector<std::string>{std::next(query_and_text_params.begin()),
47  query_and_text_params.end()});
48  }
virtual void query_with_text_params(std::string const &query_only)

+ Here is the call graph for this function:

void SqliteConnector::query_with_text_params ( const std::string &  queryString,
const std::vector< std::string > &  text_param 
)
virtual

Definition at line 57 of file SqliteConnector.cpp.

References assert(), atFirstResult_, columnNames, columnTypes, db_, anonymous_namespace{TypedDataAccessors.h}::is_null(), numCols_, numRows_, results_, and throwError().

59  {
60  atFirstResult_ = true;
61  numRows_ = 0;
62  numCols_ = 0;
63  columnNames.clear();
64  columnTypes.clear();
65  results_.clear();
66  sqlite3_stmt* stmt;
67  int returnCode = sqlite3_prepare_v2(db_, queryString.c_str(), -1, &stmt, nullptr);
68  if (returnCode != SQLITE_OK) {
69  throwError();
70  }
71 
72  int numParams_ = 1;
73  for (auto text_param : text_params) {
74  returnCode = sqlite3_bind_text(
75  stmt, numParams_++, text_param.c_str(), text_param.size(), SQLITE_TRANSIENT);
76  if (returnCode != SQLITE_OK) {
77  throwError();
78  }
79  }
80 
81  do {
82  returnCode = sqlite3_step(stmt);
83  if (returnCode != SQLITE_ROW && returnCode != SQLITE_DONE) {
84  throwError();
85  }
86  if (returnCode == SQLITE_DONE) {
87  break;
88  }
89  if (atFirstResult_) {
90  numCols_ = sqlite3_column_count(stmt);
91  for (size_t c = 0; c < numCols_; ++c) {
92  columnNames.emplace_back(sqlite3_column_name(stmt, c));
93  columnTypes.push_back(sqlite3_column_type(stmt, c));
94  }
95  results_.resize(numCols_);
96  atFirstResult_ = false;
97  }
98  numRows_++;
99  for (size_t c = 0; c < numCols_; ++c) {
100  auto col_text = reinterpret_cast<const char*>(sqlite3_column_text(stmt, c));
101  bool is_null = sqlite3_column_type(stmt, c) == SQLITE_NULL;
102  assert(is_null == !col_text);
103  results_[c].push_back(NullableResult{is_null ? "" : col_text, is_null});
104  }
105  } while (1 == 1); // Loop control in break statement above
106 
107  sqlite3_finalize(stmt);
108 }
std::vector< std::vector< NullableResult > > results_
std::vector< int > columnTypes
int64_t const int32_t sz assert(dest)
bool is_null(const T &v, const SQLTypeInfo &t)
std::vector< std::string > columnNames

+ Here is the call graph for this function:

void SqliteConnector::throwError ( )
private

Definition at line 52 of file SqliteConnector.cpp.

References db_.

Referenced by query_with_text_params().

52  {
53  string errorMsg(sqlite3_errmsg(db_));
54  throw runtime_error("Sqlite3 Error: " + errorMsg);
55 }

+ Here is the caller graph for this function:

Member Data Documentation

bool SqliteConnector::atFirstResult_
private

Definition at line 85 of file SqliteConnector.h.

Referenced by query_with_text_params().

std::vector<std::string> SqliteConnector::columnNames

Definition at line 70 of file SqliteConnector.h.

Referenced by query_with_text_params().

std::vector<int> SqliteConnector::columnTypes

Definition at line 71 of file SqliteConnector.h.

Referenced by query_with_text_params(), and SqliteMemDatabase::runSelect().

sqlite3* SqliteConnector::db_
private
std::string SqliteConnector::dbName_
private

Definition at line 84 of file SqliteConnector.h.

Referenced by ~SqliteConnector().

size_t SqliteConnector::numCols_
private

Definition at line 87 of file SqliteConnector.h.

Referenced by getData(), getNumCols(), isNull(), and query_with_text_params().

size_t SqliteConnector::numRows_
private

Definition at line 88 of file SqliteConnector.h.

Referenced by getData(), getNumRows(), isNull(), and query_with_text_params().

std::vector<std::vector<NullableResult> > SqliteConnector::results_
private

Definition at line 86 of file SqliteConnector.h.

Referenced by getData(), isNull(), and query_with_text_params().


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