87 lines
2.2 KiB
C++
87 lines
2.2 KiB
C++
#include "sresultsender.h"
|
|
#include "sutilfunction.h"
|
|
#include <QSqlDatabase>
|
|
#include <QSettings>
|
|
#include <QSqlError>
|
|
#include <QSqlQuery>
|
|
namespace
|
|
{
|
|
const QString SEPERATOR = "!@#";
|
|
}
|
|
class DBContainer
|
|
{
|
|
public:
|
|
DBContainer(QSqlDatabase& _db):m_db(_db)
|
|
{
|
|
|
|
}
|
|
~DBContainer()
|
|
{
|
|
m_db.close();
|
|
}
|
|
private:
|
|
QSqlDatabase &m_db;
|
|
};
|
|
|
|
|
|
namespace
|
|
{
|
|
const QString DBNAME = "effectprocess";
|
|
}
|
|
|
|
SResultSender::SResultSender(QObject* parent):QObject(parent)
|
|
{
|
|
init();
|
|
}
|
|
|
|
void SResultSender::init()
|
|
{
|
|
databaseSetting(DBNAME);
|
|
}
|
|
|
|
bool SResultSender::send(const State_s1_effect& _result)
|
|
{
|
|
QSqlDatabase db = QSqlDatabase::database(DBNAME);
|
|
|
|
if (!db.open())
|
|
{
|
|
emit error(E_ERROR_CODE::DB_OPEN_ERROR, db.lastError().text());
|
|
return false;
|
|
}
|
|
|
|
DBContainer container(db);
|
|
|
|
QString strQuery = "delete from stats_s1_effect where eventcode = " + QString::number(_result.event_num);
|
|
|
|
QSqlQuery query(db);
|
|
|
|
if (!query.exec(strQuery))
|
|
{
|
|
emit error(E_ERROR_CODE::DB_QUERY_ERROR, query.lastError().text() + SEPERATOR + query.lastQuery());
|
|
return false;
|
|
}
|
|
|
|
strQuery = "insert into stats_s1_effect ("
|
|
"event_num,view_buzz,replybuzz,replycount,likecount,viewcount,interactioncount,reachcount,engagementcount) "
|
|
"values "
|
|
"(:event_num,:view_buzz,:replybuzz,:replycount,:likecount,:viewcount,:interactioncount,:reachcount,:engagementcount)";
|
|
query.prepare(strQuery);
|
|
query.bindValue(":event_num", _result.event_num);
|
|
query.bindValue(":view_buzz", _result.view_buzz);
|
|
query.bindValue(":replybuzz", _result.replybuzz);
|
|
query.bindValue(":replycount", _result.replycount);
|
|
query.bindValue(":likecount", _result.likecount);
|
|
query.bindValue(":viewcount", _result.viewcount);
|
|
query.bindValue(":interactioncount", _result.interactioncount);
|
|
query.bindValue(":reachcount", _result.reachcount);
|
|
query.bindValue(":engagementcount", _result.engagementcount);
|
|
|
|
if (!query.exec())
|
|
{
|
|
emit error(E_ERROR_CODE::DB_QUERY_ERROR, query.lastError().text() + SEPERATOR + query.lastQuery());
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|