9 #include "flutter/fml/logging.h"
10 #include "third_party/sqlite/sqlite3.h"
15 Handle(
void* db,
const std::string& statememt) {
19 ::sqlite3_stmt* handle =
nullptr;
20 if (::sqlite3_prepare_v2(
reinterpret_cast<sqlite3*
>(db),
22 static_cast<int>(statememt.size()),
24 nullptr) == SQLITE_OK) {
30 if (handle_ ==
nullptr) {
33 auto res = ::sqlite3_finalize(handle_);
34 FML_CHECK(res == SQLITE_OK) <<
"Unable to finalize the archive.";
37 bool IsValid()
const {
return handle_ !=
nullptr; }
39 ::sqlite3_stmt*
Get()
const {
return handle_; }
42 ::sqlite3_stmt* handle_ =
nullptr;
44 FML_DISALLOW_COPY_AND_ASSIGN(
Handle);
47 ArchiveStatement::ArchiveStatement(
void* db,
const std::string& statememt)
48 : statement_handle_(
std::make_unique<Handle>(db, statememt)) {
49 if (!statement_handle_->IsValid()) {
50 statement_handle_.reset();
57 return statement_handle_ !=
nullptr;
64 if (::sqlite3_reset(statement_handle_->Get()) != SQLITE_OK) {
68 if (::sqlite3_clear_bindings(statement_handle_->Get()) != SQLITE_OK) {
75 static constexpr
int ToParam(
size_t index) {
79 return static_cast<int>(index + 1);
86 return static_cast<int>(index);
93 return ::sqlite3_column_count(statement_handle_->Get());
103 return ::sqlite3_bind_text(statement_handle_->Get(),
106 static_cast<int>(item.size()),
107 SQLITE_TRANSIENT) == SQLITE_OK;
110 bool ArchiveStatement::BindIntegral(
size_t index, int64_t item) {
114 return ::sqlite3_bind_int64(statement_handle_->Get(),
123 return ::sqlite3_bind_double(statement_handle_->Get(),
132 return ::sqlite3_bind_blob(statement_handle_->Get(),
136 SQLITE_TRANSIENT) == SQLITE_OK;
142 bool ArchiveStatement::ColumnIntegral(
size_t index, int64_t& item) {
146 item = ::sqlite3_column_int64(statement_handle_->Get(),
ToColumn(index));
154 item = ::sqlite3_column_double(statement_handle_->Get(),
ToColumn(index));
173 auto chars =
reinterpret_cast<const char*
>(
174 ::sqlite3_column_text(statement_handle_->Get(),
ToColumn(index)));
179 size_t textByteSize =
180 ::sqlite3_column_bytes(statement_handle_->Get(),
ToColumn(index));
182 std::string text(chars, textByteSize);
195 auto blob =
reinterpret_cast<const uint8_t*
>(
196 ::sqlite3_column_blob(statement_handle_->Get(),
ToColumn(index)));
202 ::sqlite3_column_bytes(statement_handle_->Get(),
ToColumn(index));
207 if (!item.
Truncate(byteSize,
false )) {
211 memmove(item.
GetBuffer(), blob, byteSize);
219 switch (::sqlite3_step(statement_handle_->Get())) {