Skip to content

Commit 559c727

Browse files
authored
read bit field with sqlite3_column_int64 (#2704)
* read bit field with sqlite3_column_int64 follow the standard conversion * handle all error code in v2 * always finalize stmt in ReadDB * fix loop condition
1 parent d06a909 commit 559c727

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

gframe/data_manager.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,21 @@ DataManager::DataManager() : _datas(32768), _strings(32768) {
1313
extra_setcode = { {8512558u, {0x8f, 0x54, 0x59, 0x82, 0x13a}}, };
1414
}
1515
bool DataManager::ReadDB(sqlite3* pDB) {
16-
sqlite3_stmt* pStmt{};
16+
sqlite3_stmt* pStmt = nullptr;
1717
const char* sql = "select * from datas,texts where datas.id=texts.id";
1818
if (sqlite3_prepare_v2(pDB, sql, -1, &pStmt, 0) != SQLITE_OK)
19-
return Error(pDB);
19+
return Error(pDB, pStmt);
2020
wchar_t strBuffer[4096];
2121
int step = 0;
2222
do {
2323
CardDataC cd;
2424
CardString cs;
2525
step = sqlite3_step(pStmt);
26-
if (step == SQLITE_BUSY || step == SQLITE_ERROR || step == SQLITE_MISUSE)
27-
return Error(pDB, pStmt);
28-
else if (step == SQLITE_ROW) {
26+
if (step == SQLITE_ROW) {
2927
cd.code = sqlite3_column_int(pStmt, 0);
3028
cd.ot = sqlite3_column_int(pStmt, 1);
3129
cd.alias = sqlite3_column_int(pStmt, 2);
32-
auto setcode = sqlite3_column_int64(pStmt, 3);
30+
uint64_t setcode = static_cast<uint64_t>(sqlite3_column_int64(pStmt, 3));
3331
if (setcode) {
3432
auto it = extra_setcode.find(cd.code);
3533
if (it != extra_setcode.end()) {
@@ -42,7 +40,7 @@ bool DataManager::ReadDB(sqlite3* pDB) {
4240
else
4341
cd.set_setcode(setcode);
4442
}
45-
cd.type = sqlite3_column_int(pStmt, 4);
43+
cd.type = static_cast<decltype(cd.type)>(sqlite3_column_int64(pStmt, 4));
4644
cd.attack = sqlite3_column_int(pStmt, 5);
4745
cd.defense = sqlite3_column_int(pStmt, 6);
4846
if (cd.type & TYPE_LINK) {
@@ -51,13 +49,13 @@ bool DataManager::ReadDB(sqlite3* pDB) {
5149
}
5250
else
5351
cd.link_marker = 0;
54-
unsigned int level = sqlite3_column_int(pStmt, 7);
52+
uint32_t level = static_cast<uint32_t>(sqlite3_column_int(pStmt, 7));
5553
cd.level = level & 0xff;
5654
cd.lscale = (level >> 24) & 0xff;
5755
cd.rscale = (level >> 16) & 0xff;
58-
cd.race = sqlite3_column_int(pStmt, 8);
59-
cd.attribute = sqlite3_column_int(pStmt, 9);
60-
cd.category = sqlite3_column_int(pStmt, 10);
56+
cd.race = static_cast<decltype(cd.race)>(sqlite3_column_int64(pStmt, 8));
57+
cd.attribute = static_cast<decltype(cd.attribute)>(sqlite3_column_int64(pStmt, 9));
58+
cd.category = static_cast<decltype(cd.category)>(sqlite3_column_int64(pStmt, 10));
6159
_datas[cd.code] = cd;
6260
if (const char* text = (const char*)sqlite3_column_text(pStmt, 12)) {
6361
BufferIO::DecodeUTF8(text, strBuffer);
@@ -76,7 +74,9 @@ bool DataManager::ReadDB(sqlite3* pDB) {
7674
}
7775
_strings[cd.code] = cs;
7876
}
79-
} while (step != SQLITE_DONE);
77+
else if (step != SQLITE_DONE)
78+
return Error(pDB, pStmt);
79+
} while (step == SQLITE_ROW);
8080
sqlite3_finalize(pStmt);
8181
return true;
8282
}

0 commit comments

Comments
 (0)