| 2076 | } |
| 2077 | |
| 2078 | void PostMigrateTables() { |
| 2079 | auto maybe_add_two_view_geometries_blob_column = |
| 2080 | [this](const std::string& column_name) { |
| 2081 | if (!ExistsColumn("two_view_geometries", column_name)) { |
| 2082 | SQLITE3_EXEC( |
| 2083 | database_, |
| 2084 | StringPrintf( |
| 2085 | "ALTER TABLE two_view_geometries ADD COLUMN %s BLOB;", |
| 2086 | column_name.c_str()) |
| 2087 | .c_str(), |
| 2088 | nullptr); |
| 2089 | } |
| 2090 | }; |
| 2091 | |
| 2092 | maybe_add_two_view_geometries_blob_column("F"); |
| 2093 | maybe_add_two_view_geometries_blob_column("E"); |
| 2094 | maybe_add_two_view_geometries_blob_column("H"); |
| 2095 | maybe_add_two_view_geometries_blob_column("qvec"); |
| 2096 | maybe_add_two_view_geometries_blob_column("tvec"); |
| 2097 | |
| 2098 | // Read current user_version for migration gating. |
| 2099 | int user_version = 0; |
| 2100 | { |
| 2101 | sqlite3_stmt* version_stmt; |
| 2102 | SQLITE3_CALL(sqlite3_prepare_v2( |
| 2103 | database_, "PRAGMA user_version;", -1, &version_stmt, nullptr)); |
| 2104 | if (SQLITE3_CALL(sqlite3_step(version_stmt)) == SQLITE_ROW) { |
| 2105 | user_version = sqlite3_column_int(version_stmt, 0); |
| 2106 | } |
| 2107 | SQLITE3_CALL(sqlite3_finalize(version_stmt)); |
| 2108 | } |
| 2109 | |
| 2110 | // Migrate identity and zero poses to NULL for old databases. In version |
| 2111 | // 3.13.0 and earlier, identity was used as sentinel for "not set". Between |
| 2112 | // Feb 2021 and Jul 2023, zero quaternion (0,0,0,0) was also used as |
| 2113 | // default. New databases correctly write NULL for unset and can store |
| 2114 | // actual poses. |
| 2115 | if (user_version <= MakeDatabaseVersionNumber(3, 13, 0, 0)) { |
| 2116 | sqlite3_stmt* read_stmt; |
| 2117 | SQLITE3_CALL(sqlite3_prepare_v2( |
| 2118 | database_, |
| 2119 | "SELECT pair_id, qvec, tvec FROM two_view_geometries " |
| 2120 | "WHERE qvec IS NOT NULL AND tvec IS NOT NULL;", |
| 2121 | -1, |
| 2122 | &read_stmt, |
| 2123 | nullptr)); |
| 2124 | |
| 2125 | sqlite3_stmt* update_stmt; |
| 2126 | SQLITE3_CALL(sqlite3_prepare_v2( |
| 2127 | database_, |
| 2128 | "UPDATE two_view_geometries SET qvec = NULL, tvec = NULL " |
| 2129 | "WHERE pair_id = ?;", |
| 2130 | -1, |
| 2131 | &update_stmt, |
| 2132 | nullptr)); |
| 2133 | |
| 2134 | while (SQLITE3_CALL(sqlite3_step(read_stmt)) == SQLITE_ROW) { |
| 2135 | const Eigen::Vector4d qvec = |
no test coverage detected