mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-27 18:59:26 +08:00
实现HTTP服务架构
This commit is contained in:
@@ -66,23 +66,23 @@ bool DaoEntity::isConnected()
|
||||
return db_->isConnected();
|
||||
}
|
||||
|
||||
bool DaoEntity::exec(string sql)
|
||||
int DaoEntity::exec(string sql)
|
||||
{
|
||||
return db_->exec(sql);
|
||||
}
|
||||
|
||||
bool DaoEntity::exec(string sql, vector<Fields>& result)
|
||||
int DaoEntity::exec(string sql, vector<Fields>& result)
|
||||
{
|
||||
return db_->exec(sql, result);
|
||||
}
|
||||
|
||||
bool DaoEntity::insertFields(Fields& fields)
|
||||
int DaoEntity::insertFields(Fields& fields)
|
||||
{
|
||||
string sql = fields.toSqlInsert(tableName_);
|
||||
return this->db_->exec(sql);
|
||||
}
|
||||
|
||||
bool DaoEntity::insertFields(vector<Fields>& vec_fields)
|
||||
int DaoEntity::insertFields(vector<Fields>& vec_fields)
|
||||
{
|
||||
//"insert into TABLE () values ()";
|
||||
string sql = "insert into " + tableName_;
|
||||
@@ -127,7 +127,7 @@ bool DaoEntity::insertFields(vector<Fields>& vec_fields)
|
||||
return this->db_->exec(sql);
|
||||
}
|
||||
|
||||
bool DaoEntity::duplicateUpdate(Fields& fields, const vector<string>& keys)
|
||||
int DaoEntity::duplicateUpdate(Fields& fields, const vector<string>& keys)
|
||||
{
|
||||
//insert into device_attr(device_id, attr_id, attr_val) values('26', 'model', '型号1') on duplicate key update attr_val='型号1';
|
||||
string key;
|
||||
@@ -161,33 +161,34 @@ bool DaoEntity::duplicateUpdate(Fields& fields, const vector<string>& keys)
|
||||
// });
|
||||
//}
|
||||
|
||||
bool DaoEntity::queryFields(string keys, const string& condition, vector<Fields>& result)
|
||||
int DaoEntity::queryFields(string keys, const string& condition, vector<Fields>& result)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "SELECT " + keys + " FROM " << tableName_ << (" " + condition) << "; ";
|
||||
return this->db_->exec(oss.str(), result);
|
||||
}
|
||||
|
||||
bool DaoEntity::queryFields(string keys, const string& condition, PageInfo& page, vector<Fields>& result)
|
||||
int DaoEntity::queryFields(string keys, const string& condition, PageInfo& page, vector<Fields>& result)
|
||||
{
|
||||
int err = 0;
|
||||
ostringstream oss;
|
||||
oss << "SELECT count(1) total FROM `" << tableName_ << "` " << condition << ";";
|
||||
|
||||
vector<Fields> res_total;
|
||||
if (!this->db_->exec(oss.str().c_str(), res_total))
|
||||
if (err = this->db_->exec(oss.str().c_str(), res_total))
|
||||
{
|
||||
return false;
|
||||
return err;
|
||||
}
|
||||
|
||||
if (res_total.size() <= 0)
|
||||
{
|
||||
page.total = 0;
|
||||
return true;
|
||||
return err;
|
||||
}
|
||||
page.total = res_total[0].get<int>("total");
|
||||
if (page.total <= 0)
|
||||
{
|
||||
return true;
|
||||
return err;
|
||||
}
|
||||
|
||||
oss.str("");
|
||||
@@ -200,13 +201,13 @@ bool DaoEntity::queryFields(string keys, const string& condition, PageInfo& page
|
||||
return this->db_->exec(oss.str().c_str(), result);
|
||||
}
|
||||
|
||||
bool DaoEntity::updateFields(Fields& fields, const string& condition)
|
||||
int DaoEntity::updateFields(Fields& fields, const string& condition)
|
||||
{
|
||||
string sql = fields.toSqlUpdate(tableName_, condition);
|
||||
return this->db_->exec(sql);
|
||||
}
|
||||
|
||||
bool DaoEntity::updateFields(Fields& fields, vector<string> vecKeys, const string& condition)
|
||||
int DaoEntity::updateFields(Fields& fields, vector<string> vecKeys, const string& condition)
|
||||
{
|
||||
string sql = fields.toSqlUpdate(tableName_, vecKeys, condition);
|
||||
return this->db_->exec(sql);
|
||||
|
||||
Reference in New Issue
Block a user