28 operator sqlite3_stmt* ()
noexcept
47 *
this = std::move(rhs);
63 : mStatement { std::move(stmt) }
69 *
this = std::move(rhs);
80template<
typename Binder>
85 else if (
int result = binder(); result != SQLITE_OK)
92 int index,
const void* data, int64_t
size,
bool makeCopy)
100 return sqlite3_bind_blob64(
102 makeCopy ? SQLITE_TRANSIENT : SQLITE_STATIC);
108 int index,
const std::string& value,
bool makeCopy)
110 return Bind(index, std::string_view { value }, makeCopy);
114 int index, std::string_view value,
bool makeCopy)
125 return sqlite3_bind_text(
126 *
mStatement, index, value.data(), value.size(),
127 makeCopy ? SQLITE_TRANSIENT : SQLITE_STATIC);
132 int index,
const char* value,
bool makeCopy)
134 return Bind(index, std::string_view { value }, makeCopy);
139 return Bind(index,
static_cast<long long>(value));
145 return Bind(index,
static_cast<long long>(value));
151 return Bind(index,
static_cast<long long>(value));
157 return DoBind([&] {
return sqlite3_bind_int64(*
mStatement, index, value); });
162 return DoBind([&] {
return sqlite3_bind_int64(*mStatement, index, value); });
168 return Bind(index,
static_cast<double>(value));
174 return DoBind([&] {
return sqlite3_bind_double(*
mStatement, index, value); });
192 return mStatement !=
nullptr ?
193 sqlite3_bind_parameter_index(*mStatement,
name.data()) :
204 : mStatement { std::move(stmt) }
205 , mErrors { std::move(errors) }
208 assert(mStatement !=
nullptr);
210 const auto rc = sqlite3_step(*mStatement);
212 mHasRows = rc == SQLITE_ROW;
214 if (rc == SQLITE_DONE)
215 mModifiedRowsCount = sqlite3_changes(sqlite3_db_handle(*mStatement));
217 if (rc != SQLITE_DONE && !mHasRows)
218 mErrors.emplace_back(Error(rc));
223 *
this = std::move(rhs);
231 std::swap(mModifiedRowsCount, rhs.mModifiedRowsCount);
273 : mStatement { std::move(stmt) }
274 , mErrors { &errors }
277 assert(mStatement !=
nullptr);
287 *
this = std::move(rhs);
306 if (rc == SQLITE_ROW)
312 if (rc != SQLITE_DONE)
321 if (mDone != rhs.mDone)
327 return mStatement == rhs.mStatement && mRowIndex == rhs.mRowIndex;
332 return !(*
this == rhs);
341 : mStatement { std::move(statement) }
342 , mErrors { &errors }
344 if (mStatement !=
nullptr)
345 mColumnsCount = sqlite3_column_count(*mStatement);
348template <
typename Reader>
365 if constexpr (std::is_void_v<
decltype(reader())>)
376 return DoGet([&] { value = sqlite3_column_int(*
mStatement, columnIndex) != 0; }, columnIndex);
381 return DoGet([&] { value = sqlite3_column_int(*
mStatement, columnIndex); }, columnIndex);
386 if (
sizeof(
long) == 4)
387 return DoGet([&] { value = sqlite3_column_int(*
mStatement, columnIndex); }, columnIndex);
389 return DoGet([&] { value = sqlite3_column_int64(*
mStatement, columnIndex); }, columnIndex);
392bool Row::Get(
int columnIndex,
long long& value)
const
394 return DoGet([&] { value = sqlite3_column_int64(*
mStatement, columnIndex); }, columnIndex);
403 static_cast<float>(sqlite3_column_double(*
mStatement, columnIndex));
410 return DoGet([&] { value = sqlite3_column_double(*
mStatement, columnIndex); },
414bool Row::Get(
int columnIndex, std::string& value)
const
419 const auto* text =
reinterpret_cast<const char*
>(
420 sqlite3_column_text(*
mStatement, columnIndex));
439 return sqlite3_column_bytes(*
mStatement, columnIndex);
444 const auto* data = sqlite3_column_blob(*
mStatement, columnIndex);
451 std::memcpy(buffer, data,
size);
A class representing an error in SQLite.
A class representing a row in a result set.
StatementHandlePtr mStatement
int GetColumnCount() const
std::vector< Error > * mErrors
int64_t GetColumnBytes(int columnIndex) const
bool DoGet(Reader reader, int columnIndex) const
int64_t ReadData(int columnIndex, void *buffer, int64_t maxSize) const
bool Get(int columnIndex, bool &value) const
A class representing an iterator over a result set.
RowIterator & operator=(const RowIterator &)=delete
bool operator==(const RowIterator &other) const noexcept
Row operator*() const noexcept
StatementHandlePtr mStatement
std::vector< Error > * mErrors
RowIterator & operator++() noexcept
bool operator!=(const RowIterator &other) const noexcept
A class representing a context of a run operation.
RunContext & DoBind(Binder binder)
int GetParameterIndex(const std::string &name) const noexcept
std::vector< Error > mErrors
RunContext & Bind(int index, const void *data, int64_t size, bool makeCopy=true)
RunContext & operator=(const RunContext &)=delete
RunContext(StatementHandlePtr statement) noexcept
StatementHandlePtr mStatement
RunContext & BindZeroBlob(int index, int64_t size)
A class representing a result of a run operation.
const std::vector< Error > & GetErrors() const noexcept
RowIterator begin() noexcept
RunResult(StatementHandlePtr statement, std::vector< Error > errors) noexcept
bool IsOk() const noexcept
int GetModifiedRowsCount() const noexcept
std::vector< Error > mErrors
RowIterator end() noexcept
bool HasRows() const noexcept
RunResult & operator=(const RunResult &)=delete
StatementHandlePtr mStatement
A class representing a compiled statement.
Statement(sqlite3_stmt *stmt)
RunContext & Prepare() noexcept
Statement & operator=(const Statement &)=delete
StatementHandlePtr mStatement
std::optional< RunContext > mRunContext
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
std::shared_ptr< StatementHandle > StatementHandlePtr
StatementHandle(sqlite3_stmt *Handle) noexcept