1 #ifndef ZSERIO_SQL_CONNECTION_H_INC
2 #define ZSERIO_SQL_CONNECTION_H_INC
125 sqlite3* m_connection;
130 m_connection(connection),
131 m_connectionType(connectionType)
144 sqlite3_close_v2(m_connection);
147 m_connection = connection;
148 m_connectionType = connectionType;
153 return m_connectionType;
163 std::unique_ptr<sqlite3_stmt, SqliteFinalizer> statement(
prepareStatement(sqlQuery));
164 int result = sqlite3_step(statement.get());
165 if (result != SQLITE_DONE)
167 throw SqliteException(
"SqliteConnection::executeUpdate(): sqlite3_step failed: ")
174 sqlite3_stmt* statement =
nullptr;
175 const int result = sqlite3_prepare_v2(
176 m_connection, sqlQuery.
data(),
static_cast<int>(sqlQuery.
size()), &statement,
nullptr);
177 if (result != SQLITE_OK)
179 throw SqliteException(
"SqliteConnection::prepareStatement(): sqlite3_prepare_v2() failed: ")
188 bool wasTransactionStarted =
false;
189 if (sqlite3_get_autocommit(m_connection) != 0)
192 wasTransactionStarted =
true;
195 return wasTransactionStarted;
200 if (wasTransactionStarted)
constexpr size_type size() const noexcept
constexpr const_pointer data() const noexcept
sqlite3_stmt * prepareStatement(StringView sqlQuery)
SqliteConnection & operator=(SqliteConnection &&)=delete
SqliteConnection(SqliteConnection &&)=delete
sqlite3 * getConnection()
SqliteConnection(const SqliteConnection &)=delete
SqliteConnection & operator=(const SqliteConnection &)=delete
SqliteConnection(sqlite3 *connection=nullptr, ConnectionType connectionType=INTERNAL_CONNECTION)
ConnectionType getConnectionType() const
void endTransaction(bool wasTransactionStarted)
void executeUpdate(StringView sqlQuery)
void reset(sqlite3 *connection=nullptr, ConnectionType connectionType=INTERNAL_CONNECTION)