@@ -13,6 +13,9 @@ namespace impeller {
1313
1414struct ArchiveStatement ::Handle {
1515 Handle (void * db, const std::string& statememt) {
16+ if (db == nullptr ) {
17+ return ;
18+ }
1619 ::sqlite3_stmt* handle = nullptr ;
1720 if (::sqlite3_prepare_v2 (reinterpret_cast <sqlite3*>(db), //
1821 statememt.c_str (), //
@@ -31,12 +34,12 @@ struct ArchiveStatement::Handle {
3134 FML_CHECK (res == SQLITE_OK) << " Unable to finalize the archive." ;
3235 }
3336
34- bool IsValid () { return handle_ != nullptr ; }
37+ bool IsValid () const { return handle_ != nullptr ; }
3538
3639 ::sqlite3_stmt* Get () const { return handle_; }
3740
3841 private:
39- ::sqlite3_stmt* handle_;
42+ ::sqlite3_stmt* handle_ = nullptr ;
4043
4144 FML_DISALLOW_COPY_AND_ASSIGN (Handle);
4245};
@@ -55,6 +58,9 @@ bool ArchiveStatement::IsValid() const {
5558}
5659
5760bool ArchiveStatement::Reset () {
61+ if (!IsValid ()) {
62+ return false ;
63+ }
5864 if (::sqlite3_reset (statement_handle_->Get ()) != SQLITE_OK) {
5965 return false ;
6066 }
@@ -81,13 +87,19 @@ static constexpr int ToColumn(size_t index) {
8187}
8288
8389size_t ArchiveStatement::GetColumnCount () {
90+ if (!IsValid ()) {
91+ return 0u ;
92+ }
8493 return ::sqlite3_column_count (statement_handle_->Get ());
8594}
8695
8796/*
8897 * Bind Variants
8998 */
9099bool ArchiveStatement::WriteValue (size_t index, const std::string& item) {
100+ if (!IsValid ()) {
101+ return false ;
102+ }
91103 return ::sqlite3_bind_text (statement_handle_->Get (), //
92104 ToParam (index), //
93105 item.data (), //
@@ -96,18 +108,27 @@ bool ArchiveStatement::WriteValue(size_t index, const std::string& item) {
96108}
97109
98110bool ArchiveStatement::BindIntegral (size_t index, int64_t item) {
111+ if (!IsValid ()) {
112+ return false ;
113+ }
99114 return ::sqlite3_bind_int64 (statement_handle_->Get (), //
100115 ToParam (index), //
101116 item) == SQLITE_OK;
102117}
103118
104119bool ArchiveStatement::WriteValue (size_t index, double item) {
120+ if (!IsValid ()) {
121+ return false ;
122+ }
105123 return ::sqlite3_bind_double (statement_handle_->Get (), //
106124 ToParam (index), //
107125 item) == SQLITE_OK;
108126}
109127
110128bool ArchiveStatement::WriteValue (size_t index, const Allocation& item) {
129+ if (!IsValid ()) {
130+ return false ;
131+ }
111132 return ::sqlite3_bind_blob (statement_handle_->Get (), //
112133 ToParam (index), //
113134 item.GetBuffer (), //
@@ -119,11 +140,17 @@ bool ArchiveStatement::WriteValue(size_t index, const Allocation& item) {
119140 * Column Variants
120141 */
121142bool ArchiveStatement::ColumnIntegral (size_t index, int64_t & item) {
143+ if (!IsValid ()) {
144+ return false ;
145+ }
122146 item = ::sqlite3_column_int64 (statement_handle_->Get (), ToColumn (index));
123147 return true ;
124148}
125149
126150bool ArchiveStatement::ReadValue (size_t index, double & item) {
151+ if (!IsValid ()) {
152+ return false ;
153+ }
127154 item = ::sqlite3_column_double (statement_handle_->Get (), ToColumn (index));
128155 return true ;
129156}
@@ -137,6 +164,9 @@ bool ArchiveStatement::ReadValue(size_t index, double& item) {
137164 */
138165
139166bool ArchiveStatement::ReadValue (size_t index, std::string& item) {
167+ if (!IsValid ()) {
168+ return false ;
169+ }
140170 /*
141171 * Get the character data
142172 */
@@ -156,6 +186,9 @@ bool ArchiveStatement::ReadValue(size_t index, std::string& item) {
156186}
157187
158188bool ArchiveStatement::ReadValue (size_t index, Allocation& item) {
189+ if (!IsValid ()) {
190+ return false ;
191+ }
159192 /*
160193 * Get a blob pointer
161194 */
@@ -180,6 +213,9 @@ bool ArchiveStatement::ReadValue(size_t index, Allocation& item) {
180213}
181214
182215ArchiveStatement::Result ArchiveStatement::Execute () {
216+ if (!IsValid ()) {
217+ return Result::kFailure ;
218+ }
183219 switch (::sqlite3_step (statement_handle_->Get ())) {
184220 case SQLITE_DONE:
185221 return Result::kDone ;
0 commit comments