]> git.sesse.net Git - nageru/commitdiff
Use REPLACE instead of INSERT + DELETE for frame files.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 9 Mar 2019 17:13:53 +0000 (18:13 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 9 Mar 2019 17:13:53 +0000 (18:13 +0100)
futatabi/db.cpp

index 1ad17cbfece33368742f5e08da29e8072156edb7..33d88d4f369e2819a585a32fb771f99d8ffccef8 100644 (file)
@@ -262,26 +262,6 @@ void DB::store_frame_file(const string &filename, size_t size, const vector<Fram
        // Delete any existing instances with this filename.
        sqlite3_stmt *stmt;
 
        // Delete any existing instances with this filename.
        sqlite3_stmt *stmt;
 
-       ret = sqlite3_prepare_v2(db, "DELETE FROM filev2 WHERE filename=?", -1, &stmt, 0);
-       if (ret != SQLITE_OK) {
-               fprintf(stderr, "DELETE prepare: %s\n", sqlite3_errmsg(db));
-               exit(1);
-       }
-
-       sqlite3_bind_text(stmt, 1, filename.data(), filename.size(), SQLITE_STATIC);
-
-       ret = sqlite3_step(stmt);
-       if (ret == SQLITE_ROW) {
-               fprintf(stderr, "DELETE step: %s\n", sqlite3_errmsg(db));
-               exit(1);
-       }
-
-       ret = sqlite3_finalize(stmt);
-       if (ret != SQLITE_OK) {
-               fprintf(stderr, "DELETE finalize: %s\n", sqlite3_errmsg(db));
-               exit(1);
-       }
-
        // Create the protobuf blob for the new row.
        FileContentsProto file_contents;
        unordered_set<unsigned> seen_stream_idx;  // Usually only one.
        // Create the protobuf blob for the new row.
        FileContentsProto file_contents;
        unordered_set<unsigned> seen_stream_idx;  // Usually only one.
@@ -307,7 +287,7 @@ void DB::store_frame_file(const string &filename, size_t size, const vector<Fram
        file_contents.SerializeToString(&serialized);
 
        // Insert the new row.
        file_contents.SerializeToString(&serialized);
 
        // Insert the new row.
-       ret = sqlite3_prepare_v2(db, "INSERT INTO filev2 (filename, size, frames) VALUES (?, ?, ?)", -1, &stmt, 0);
+       ret = sqlite3_prepare_v2(db, "REPLACE INTO filev2 (filename, size, frames) VALUES (?, ?, ?)", -1, &stmt, 0);
        if (ret != SQLITE_OK) {
                fprintf(stderr, "INSERT prepare: %s\n", sqlite3_errmsg(db));
                exit(1);
        if (ret != SQLITE_OK) {
                fprintf(stderr, "INSERT prepare: %s\n", sqlite3_errmsg(db));
                exit(1);