| 158 | } |
| 159 | |
| 160 | Error Connection::Execute(std::string_view sql) noexcept |
| 161 | { |
| 162 | if (mInDestructor || mConnection == nullptr) |
| 163 | return Error(SQLITE_MISUSE); |
| 164 | |
| 165 | auto tx = BeginTransaction("Connection_Execute"); |
| 166 | |
| 167 | auto first = sql.data(); |
| 168 | auto last = first + sql.size(); |
| 169 | |
| 170 | while (first != last) |
| 171 | { |
| 172 | const char* next = nullptr; |
| 173 | sqlite3_stmt* statement = nullptr; |
| 174 | |
| 175 | int result = sqlite3_prepare_v2 ( |
| 176 | mConnection, first, last - first, &statement, &next); |
| 177 | |
| 178 | if (result != SQLITE_OK) |
| 179 | return Error(result); |
| 180 | |
| 181 | first = next; |
| 182 | |
| 183 | if (statement == nullptr) |
| 184 | continue; |
| 185 | |
| 186 | auto finalizer = finally([statement] { sqlite3_finalize(statement); }); |
| 187 | |
| 188 | result = sqlite3_step(statement); |
| 189 | |
| 190 | if (result != SQLITE_OK && result != SQLITE_DONE && result != SQLITE_ROW) |
| 191 | return Error(result); |
| 192 | |
| 193 | while (result == SQLITE_ROW) |
| 194 | result = sqlite3_step(statement); |
| 195 | } |
| 196 | |
| 197 | return tx.Commit(); |
| 198 | } |
| 199 | |
| 200 | Transaction Connection::BeginTransaction(std::string name) |
| 201 | { |
no test coverage detected