bool ServerSocketInterface::deckListHelper(int folderId, ServerInfo_DeckStorage_Folder *folder) { QSqlQuery query(sqlInterface->getDatabase()); query.prepare("select id, name from " + servatrice->getDbPrefix() + "_decklist_folders where id_parent = :id_parent and id_user = :id_user"); query.bindValue(":id_parent", folderId); query.bindValue(":id_user", userInfo->id()); if (!sqlInterface->execSqlQuery(query)) return false; while (query.next()) { ServerInfo_DeckStorage_TreeItem *newItem = folder->add_items(); newItem->set_id(query.value(0).toInt()); newItem->set_name(query.value(1).toString().toStdString()); if (!deckListHelper(newItem->id(), newItem->mutable_folder())) return false; } query.prepare("select id, name, upload_time from " + servatrice->getDbPrefix() + "_decklist_files where id_folder = :id_folder and id_user = :id_user"); query.bindValue(":id_folder", folderId); query.bindValue(":id_user", userInfo->id()); if (!sqlInterface->execSqlQuery(query)) return false; while (query.next()) { ServerInfo_DeckStorage_TreeItem *newItem = folder->add_items(); newItem->set_id(query.value(0).toInt()); newItem->set_name(query.value(1).toString().toStdString()); ServerInfo_DeckStorage_File *newFile = newItem->mutable_file(); newFile->set_creation_time(query.value(2).toDateTime().toTime_t()); } return true; }
bool ServerSocketInterface::deckListHelper(int folderId, ServerInfo_DeckStorage_Folder *folder) { QSqlQuery *query = sqlInterface->prepareQuery("select id, name from {prefix}_decklist_folders where id_parent = :id_parent and id_user = :id_user"); query->bindValue(":id_parent", folderId); query->bindValue(":id_user", userInfo->id()); if (!sqlInterface->execSqlQuery(query)) return false; QMap<int, QString> results; while(query->next()) results[query->value(0).toInt()] = query->value(1).toString(); foreach(int key, results.keys()) { ServerInfo_DeckStorage_TreeItem *newItem = folder->add_items(); newItem->set_id(key); newItem->set_name(results.value(key).toStdString()); if (!deckListHelper(newItem->id(), newItem->mutable_folder())) return false; } query = sqlInterface->prepareQuery("select id, name, upload_time from {prefix}_decklist_files where id_folder = :id_folder and id_user = :id_user"); query->bindValue(":id_folder", folderId); query->bindValue(":id_user", userInfo->id()); if (!sqlInterface->execSqlQuery(query)) return false; while (query->next()) { ServerInfo_DeckStorage_TreeItem *newItem = folder->add_items(); newItem->set_id(query->value(0).toInt()); newItem->set_name(query->value(1).toString().toStdString()); ServerInfo_DeckStorage_File *newFile = newItem->mutable_file(); newFile->set_creation_time(query->value(2).toDateTime().toTime_t()); } return true; }