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)
143 sqlite3_close_v2(m_connection);
145 m_connection = connection;
146 m_connectionType = connectionType;
151 return m_connectionType;
161 std::unique_ptr<sqlite3_stmt, SqliteFinalizer> statement(
prepareStatement(sqlQuery));
162 int result = sqlite3_step(statement.get());
163 if (result != SQLITE_DONE)
165 throw SqliteException(
"SqliteConnection::executeUpdate(): sqlite3_step failed: ")
172 sqlite3_stmt* statement =
nullptr;
173 const int result = sqlite3_prepare_v2(
174 m_connection, sqlQuery.
data(),
static_cast<int>(sqlQuery.
size()), &statement,
nullptr);
175 if (result != SQLITE_OK)
177 throw SqliteException(
"SqliteConnection::prepareStatement(): sqlite3_prepare_v2() failed: ")
186 bool wasTransactionStarted =
false;
187 if (sqlite3_get_autocommit(m_connection) != 0)
190 wasTransactionStarted =
true;
193 return wasTransactionStarted;
198 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)