mirror of https://github.com/mgba-emu/mgba.git
No-Intro: Prevent database from being downgraded
This commit is contained in:
parent
17cf2e6237
commit
dfab801277
|
@ -72,6 +72,7 @@ bool NoIntroDBLoadClrMamePro(struct NoIntroDB* db, struct VFile* vf) {
|
||||||
|
|
||||||
sqlite3_stmt* gamedbTable = NULL;
|
sqlite3_stmt* gamedbTable = NULL;
|
||||||
sqlite3_stmt* gamedbDrop = NULL;
|
sqlite3_stmt* gamedbDrop = NULL;
|
||||||
|
sqlite3_stmt* gamedbSelect = NULL;
|
||||||
sqlite3_stmt* gameTable = NULL;
|
sqlite3_stmt* gameTable = NULL;
|
||||||
sqlite3_stmt* romTable = NULL;
|
sqlite3_stmt* romTable = NULL;
|
||||||
char* fieldName = NULL;
|
char* fieldName = NULL;
|
||||||
|
@ -91,6 +92,11 @@ bool NoIntroDBLoadClrMamePro(struct NoIntroDB* db, struct VFile* vf) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char selectGamedb[] = "SELECT * FROM gamedb WHERE name = ? AND version >= ?;";
|
||||||
|
if (sqlite3_prepare_v2(db->db, selectGamedb, -1, &gamedbSelect, NULL)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static const char insertGame[] = "INSERT INTO games (dbid, name) VALUES (?, ?);";
|
static const char insertGame[] = "INSERT INTO games (dbid, name) VALUES (?, ?);";
|
||||||
if (sqlite3_prepare_v2(db->db, insertGame, -1, &gameTable, NULL)) {
|
if (sqlite3_prepare_v2(db->db, insertGame, -1, &gameTable, NULL)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -161,6 +167,11 @@ bool NoIntroDBLoadClrMamePro(struct NoIntroDB* db, struct VFile* vf) {
|
||||||
break;
|
break;
|
||||||
case ')':
|
case ')':
|
||||||
if (currentDb < 0 && dbType && dbVersion) {
|
if (currentDb < 0 && dbType && dbVersion) {
|
||||||
|
sqlite3_clear_bindings(gamedbSelect);
|
||||||
|
sqlite3_reset(gamedbSelect);
|
||||||
|
sqlite3_bind_text(gamedbSelect, 1, dbType, -1, SQLITE_TRANSIENT);
|
||||||
|
sqlite3_bind_text(gamedbSelect, 2, dbVersion, -1, SQLITE_TRANSIENT);
|
||||||
|
if (sqlite3_step(gamedbSelect) != SQLITE_ROW) {
|
||||||
sqlite3_clear_bindings(gamedbDrop);
|
sqlite3_clear_bindings(gamedbDrop);
|
||||||
sqlite3_reset(gamedbDrop);
|
sqlite3_reset(gamedbDrop);
|
||||||
sqlite3_bind_text(gamedbDrop, 1, dbType, -1, SQLITE_TRANSIENT);
|
sqlite3_bind_text(gamedbDrop, 1, dbType, -1, SQLITE_TRANSIENT);
|
||||||
|
@ -174,6 +185,7 @@ bool NoIntroDBLoadClrMamePro(struct NoIntroDB* db, struct VFile* vf) {
|
||||||
if (sqlite3_step(gamedbTable) == SQLITE_DONE) {
|
if (sqlite3_step(gamedbTable) == SQLITE_DONE) {
|
||||||
currentDb = sqlite3_last_insert_rowid(db->db);
|
currentDb = sqlite3_last_insert_rowid(db->db);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
free((void*) dbType);
|
free((void*) dbType);
|
||||||
free((void*) dbVersion);
|
free((void*) dbVersion);
|
||||||
dbType = NULL;
|
dbType = NULL;
|
||||||
|
@ -272,6 +284,7 @@ bool NoIntroDBLoadClrMamePro(struct NoIntroDB* db, struct VFile* vf) {
|
||||||
|
|
||||||
sqlite3_finalize(gamedbTable);
|
sqlite3_finalize(gamedbTable);
|
||||||
sqlite3_finalize(gamedbDrop);
|
sqlite3_finalize(gamedbDrop);
|
||||||
|
sqlite3_finalize(gamedbSelect);
|
||||||
sqlite3_finalize(gameTable);
|
sqlite3_finalize(gameTable);
|
||||||
sqlite3_finalize(romTable);
|
sqlite3_finalize(romTable);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue