| 488 | } |
| 489 | |
| 490 | bool SQLiteBatch::WriteKey(DataStream&& key, DataStream&& value, bool overwrite) |
| 491 | { |
| 492 | if (!m_database.m_db) return false; |
| 493 | assert(m_insert_stmt && m_overwrite_stmt); |
| 494 | |
| 495 | sqlite3_stmt* stmt; |
| 496 | if (overwrite) { |
| 497 | stmt = m_overwrite_stmt; |
| 498 | } else { |
| 499 | stmt = m_insert_stmt; |
| 500 | } |
| 501 | |
| 502 | // Bind: leftmost parameter in statement is index 1 |
| 503 | // Insert index 1 is key, 2 is value |
| 504 | if (!BindBlobToStatement(stmt, 1, key, "key")) return false; |
| 505 | if (!BindBlobToStatement(stmt, 2, value, "value")) return false; |
| 506 | |
| 507 | // Acquire semaphore if not previously acquired when creating a transaction. |
| 508 | if (!m_txn) m_database.m_write_semaphore.acquire(); |
| 509 | |
| 510 | // Execute |
| 511 | int res = sqlite3_step(stmt); |
| 512 | sqlite3_clear_bindings(stmt); |
| 513 | sqlite3_reset(stmt); |
| 514 | if (res != SQLITE_DONE) { |
| 515 | LogWarning("Unable to execute write statement: %s", sqlite3_errstr(res)); |
| 516 | } |
| 517 | |
| 518 | if (!m_txn) m_database.m_write_semaphore.release(); |
| 519 | |
| 520 | return res == SQLITE_DONE; |
| 521 | } |
| 522 | |
| 523 | bool SQLiteBatch::ExecStatement(sqlite3_stmt* stmt, std::span<const std::byte> blob) |
| 524 | { |
no test coverage detected