实现削峰套利策略的编辑页面

This commit is contained in:
lixiaoyuan
2025-08-26 18:36:25 +08:00
parent 7fe51ea362
commit 8f6c83147b
37 changed files with 1506 additions and 729 deletions

64
src/database/SQL.cpp Normal file
View File

@@ -0,0 +1,64 @@
#include "SQL.h"
std::string SQL::str()
{
if (type == TYPE::select)
{
// SELECT * from t_tabname WHERE id='1';
if (sql_k.empty()) {}
std::string s = "SELECT " + (sql_k.empty() ? "*" : sql_k) + " FROM `" + tabname + "`";
if (!sql_c.empty()) { s += (" WHERE" + sql_c); }
return s + ";";
}
else if (type == TYPE::update)
{
// UPDATE t_tabname SET a='1', b='2' WHERE id='1';
std::string s = "UPDATE `" + tabname + "` SET " + sql_k + " WHERE" + sql_c;
return s + ";";
}
else if (type == TYPE::insert)
{
// INSERT INTO t_tabname (a,b,c) VALUES('1','2','3');
std::string s = "INSERT INTO `" + tabname + "` (" + sql_k + ") VALUES(" + sql_v + ");";
return s;
}
else if (type == TYPE::del)
{
return "";
}
return "";
}
SQL& SQL::table(std::string t)
{
tabname = t;
return *this;
}
SQL& SQL::select(std::string k)
{
if (!sql_k.empty()) { sql_k += ","; }
sql_k += k;
return *this;
}
SQL& SQL::where(std::string expr)
{
sql_c += (" " + expr);
return *this;
}
SQL& SQL::update(std::string k, std::string v)
{
if (!sql_k.empty()) { sql_k += ","; }
sql_k += ("`" + k + "`='" + v + "'");
return *this;
}
SQL& SQL::insert(std::string k, std::string v)
{
if (!sql_k.empty()) { sql_k += ","; }
sql_k += ("`" + k + "`");
if (!sql_v.empty()) { sql_v += ","; }
sql_v += ("'" + v + "'");
return *this;
}