added redirect and ability to save checkboxes
This commit is contained in:
@@ -31,7 +31,7 @@ bool initDb() {
|
||||
"value TEXT,"
|
||||
"created_at DATETIME DEFAULT CURRENT_TIMESTAMP,"
|
||||
"updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,"
|
||||
"FOREIGN KEY (character_id) REFERENCES characters(id) ON DELETE CASCADE);";
|
||||
"FOREIGN KEY (character_id) REFERENCES shadowrun_characters(id) ON DELETE CASCADE);";
|
||||
|
||||
if (!db.exec(create_sql_data)){
|
||||
CROW_LOG_ERROR << "Failed to create shadowrun_data table";
|
||||
@@ -41,7 +41,7 @@ bool initDb() {
|
||||
}
|
||||
|
||||
int64_t getKeyOfCharacter(const string& name){
|
||||
auto sql = format("SELECT 1 FROM shadowrun_characters WHERE name = '{}' LIMIT 1;", name);
|
||||
auto sql = format("SELECT id FROM shadowrun_characters WHERE name = '{}' LIMIT 1;", name);
|
||||
auto db = Database();
|
||||
|
||||
if (!db.open())
|
||||
@@ -63,7 +63,7 @@ int64_t getKeyOfCharacter(const string& name){
|
||||
}
|
||||
}
|
||||
|
||||
bool storeCharacterData(int64_t characterKey, vector<pair<const string&, const string&>>& idValues){
|
||||
bool storeCharacterData(int64_t characterKey, vector<pair<const string, const string>>& idValues){
|
||||
auto sql = format("SELECT name FROM shadowrun_data WHERE character_id = {};", characterKey);
|
||||
auto db = Database();
|
||||
if (!db.open())
|
||||
@@ -74,13 +74,13 @@ bool storeCharacterData(int64_t characterKey, vector<pair<const string&, const s
|
||||
for (auto& idValue : idValues) {
|
||||
// update if already exist
|
||||
if(set.contains(idValue.first)){
|
||||
auto sql = format("UPDATE shadowrun_data SET value = {}, updated_at = CURRENT_TIMESTAMP WHERE name = {} AND character_id = {}", idValue.second, idValue.first, characterKey);
|
||||
auto sql = format("UPDATE shadowrun_data SET value = '{}', updated_at = CURRENT_TIMESTAMP WHERE name = '{}' AND character_id = {}", idValue.second, idValue.first, characterKey);
|
||||
if (!db.exec(sql)){
|
||||
CROW_LOG_WARNING << "Failed to update " << idValue.first << " with " << idValue.second;
|
||||
}
|
||||
} else {
|
||||
auto sql = format("INSERT INTO shadowrun_data (character_id, name, value)"
|
||||
"VALUES ({}, {}, {})", characterKey, idValue.first, idValue.second);
|
||||
auto sql = format("INSERT INTO shadowrun_data (character_id, name, value) "
|
||||
"VALUES ({}, '{}', '{}')", characterKey, idValue.first, idValue.second);
|
||||
if (!db.exec(sql)){
|
||||
CROW_LOG_WARNING << "Failed to insert " << idValue.first << " with " << idValue.second;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user