sql table prefix
This commit is contained in:
parent
842f266d82
commit
d6c00d6529
3 changed files with 17 additions and 14 deletions
|
@ -41,6 +41,7 @@ Servatrice::Servatrice(QObject *parent)
|
|||
tcpServer->listen(QHostAddress::Any, settings->value("server/port", 4747).toInt());
|
||||
|
||||
QString dbType = settings->value("database/type").toString();
|
||||
dbPrefix = settings->value("database/prefix").toString();
|
||||
if (dbType == "mysql")
|
||||
openDatabase();
|
||||
|
||||
|
@ -89,7 +90,7 @@ bool Servatrice::openDatabase()
|
|||
|
||||
if (!nextGameId) {
|
||||
QSqlQuery query;
|
||||
if (!query.exec("select max(id) from games"))
|
||||
if (!query.exec("select max(id) from " + dbPrefix + "_games"))
|
||||
return false;
|
||||
if (!query.next())
|
||||
return false;
|
||||
|
@ -129,7 +130,7 @@ AuthenticationResult Servatrice::checkUserPassword(const QString &user, const QS
|
|||
checkSql();
|
||||
|
||||
QSqlQuery query;
|
||||
query.prepare("select password from users where name = :name and active = 1");
|
||||
query.prepare("select password from " + dbPrefix + "_users where name = :name and active = 1");
|
||||
query.bindValue(":name", user);
|
||||
if (!execSqlQuery(query))
|
||||
return PasswordWrong;
|
||||
|
@ -152,7 +153,7 @@ ServerInfo_User *Servatrice::getUserData(const QString &name)
|
|||
checkSql();
|
||||
|
||||
QSqlQuery query;
|
||||
query.prepare("select admin, country, avatar_bmp from users where name = :name and active = 1");
|
||||
query.prepare("select admin, country, avatar_bmp from " + dbPrefix + "_users where name = :name and active = 1");
|
||||
query.bindValue(":name", name);
|
||||
if (!execSqlQuery(query))
|
||||
return new ServerInfo_User(name);
|
||||
|
|
|
@ -44,6 +44,7 @@ public:
|
|||
bool getGameShouldPing() const { return true; }
|
||||
int getMaxGameInactivityTime() const { return maxGameInactivityTime; }
|
||||
int getMaxPlayerInactivityTime() const { return maxPlayerInactivityTime; }
|
||||
QString getDbPrefix() const { return dbPrefix; }
|
||||
protected:
|
||||
AuthenticationResult checkUserPassword(const QString &user, const QString &password);
|
||||
ServerInfo_User *getUserData(const QString &name);
|
||||
|
@ -51,6 +52,7 @@ private:
|
|||
QTimer *pingClock;
|
||||
QTcpServer *tcpServer;
|
||||
QString loginMessage;
|
||||
QString dbPrefix;
|
||||
QSettings *settings;
|
||||
int maxGameInactivityTime;
|
||||
int maxPlayerInactivityTime;
|
||||
|
|
|
@ -106,7 +106,7 @@ int ServerSocketInterface::getDeckPathId(int basePathId, QStringList path)
|
|||
return 0;
|
||||
|
||||
QSqlQuery query;
|
||||
query.prepare("select id from decklist_folders where id_parent = :id_parent and name = :name and user = :user");
|
||||
query.prepare("select id from " + servatrice->getDbPrefix() + "_decklist_folders where id_parent = :id_parent and name = :name and user = :user");
|
||||
query.bindValue(":id_parent", basePathId);
|
||||
query.bindValue(":name", path.takeFirst());
|
||||
query.bindValue(":user", userInfo->getName());
|
||||
|
@ -129,7 +129,7 @@ int ServerSocketInterface::getDeckPathId(const QString &path)
|
|||
bool ServerSocketInterface::deckListHelper(DeckList_Directory *folder)
|
||||
{
|
||||
QSqlQuery query;
|
||||
query.prepare("select id, name from decklist_folders where id_parent = :id_parent and user = :user");
|
||||
query.prepare("select id, name from " + servatrice->getDbPrefix() + "_decklist_folders where id_parent = :id_parent and user = :user");
|
||||
query.bindValue(":id_parent", folder->getId());
|
||||
query.bindValue(":user", userInfo->getName());
|
||||
if (!servatrice->execSqlQuery(query))
|
||||
|
@ -142,7 +142,7 @@ bool ServerSocketInterface::deckListHelper(DeckList_Directory *folder)
|
|||
return false;
|
||||
}
|
||||
|
||||
query.prepare("select id, name, upload_time from decklist_files where id_folder = :id_folder and user = :user");
|
||||
query.prepare("select id, name, upload_time from " + servatrice->getDbPrefix() + "_decklist_files where id_folder = :id_folder and user = :user");
|
||||
query.bindValue(":id_folder", folder->getId());
|
||||
query.bindValue(":user", userInfo->getName());
|
||||
if (!servatrice->execSqlQuery(query))
|
||||
|
@ -188,7 +188,7 @@ ResponseCode ServerSocketInterface::cmdDeckNewDir(Command_DeckNewDir *cmd, Comma
|
|||
return RespNameNotFound;
|
||||
|
||||
QSqlQuery query;
|
||||
query.prepare("insert into decklist_folders (id_parent, user, name) values(:id_parent, :user, :name)");
|
||||
query.prepare("insert into " + servatrice->getDbPrefix() + "_decklist_folders (id_parent, user, name) values(:id_parent, :user, :name)");
|
||||
query.bindValue(":id_parent", folderId);
|
||||
query.bindValue(":user", userInfo->getName());
|
||||
query.bindValue(":name", cmd->getDirName());
|
||||
|
@ -203,17 +203,17 @@ void ServerSocketInterface::deckDelDirHelper(int basePathId)
|
|||
|
||||
QSqlQuery query;
|
||||
|
||||
query.prepare("select id from decklist_folders where id_parent = :id_parent");
|
||||
query.prepare("select id from " + servatrice->getDbPrefix() + "_decklist_folders where id_parent = :id_parent");
|
||||
query.bindValue(":id_parent", basePathId);
|
||||
servatrice->execSqlQuery(query);
|
||||
while (query.next())
|
||||
deckDelDirHelper(query.value(0).toInt());
|
||||
|
||||
query.prepare("delete from decklist_files where id_folder = :id_folder");
|
||||
query.prepare("delete from " + servatrice->getDbPrefix() + "_decklist_files where id_folder = :id_folder");
|
||||
query.bindValue(":id_folder", basePathId);
|
||||
servatrice->execSqlQuery(query);
|
||||
|
||||
query.prepare("delete from decklist_folders where id = :id");
|
||||
query.prepare("delete from " + servatrice->getDbPrefix() + "_decklist_folders where id = :id");
|
||||
query.bindValue(":id", basePathId);
|
||||
servatrice->execSqlQuery(query);
|
||||
}
|
||||
|
@ -241,14 +241,14 @@ ResponseCode ServerSocketInterface::cmdDeckDel(Command_DeckDel *cmd, CommandCont
|
|||
|
||||
QSqlQuery query;
|
||||
|
||||
query.prepare("select id from decklist_files where id = :id and user = :user");
|
||||
query.prepare("select id from " + servatrice->getDbPrefix() + "_decklist_files where id = :id and user = :user");
|
||||
query.bindValue(":id", cmd->getDeckId());
|
||||
query.bindValue(":user", userInfo->getName());
|
||||
servatrice->execSqlQuery(query);
|
||||
if (!query.next())
|
||||
return RespNameNotFound;
|
||||
|
||||
query.prepare("delete from decklist_files where id = :id");
|
||||
query.prepare("delete from " + servatrice->getDbPrefix() + "_decklist_files where id = :id");
|
||||
query.bindValue(":id", cmd->getDeckId());
|
||||
servatrice->execSqlQuery(query);
|
||||
|
||||
|
@ -279,7 +279,7 @@ ResponseCode ServerSocketInterface::cmdDeckUpload(Command_DeckUpload *cmd, Comma
|
|||
deckName = "Unnamed deck";
|
||||
|
||||
QSqlQuery query;
|
||||
query.prepare("insert into decklist_files (id_folder, user, name, upload_time, content) values(:id_folder, :user, :name, NOW(), :content)");
|
||||
query.prepare("insert into " + servatrice->getDbPrefix() + "_decklist_files (id_folder, user, name, upload_time, content) values(:id_folder, :user, :name, NOW(), :content)");
|
||||
query.bindValue(":id_folder", folderId);
|
||||
query.bindValue(":user", userInfo->getName());
|
||||
query.bindValue(":name", deckName);
|
||||
|
@ -296,7 +296,7 @@ DeckList *ServerSocketInterface::getDeckFromDatabase(int deckId)
|
|||
|
||||
QSqlQuery query;
|
||||
|
||||
query.prepare("select content from decklist_files where id = :id and user = :user");
|
||||
query.prepare("select content from " + servatrice->getDbPrefix() + "_decklist_files where id = :id and user = :user");
|
||||
query.bindValue(":id", deckId);
|
||||
query.bindValue(":user", userInfo->getName());
|
||||
servatrice->execSqlQuery(query);
|
||||
|
|
Loading…
Reference in a new issue