123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #include "databaseeventthread.h"
- #define HostName "172.17.35.51"
- //#define HostName "124.71.140.20"
- #define HostPort 3306
- #define UserName "usky"
- #define PassWord "Yt#75Usky"
- #define DatabaseName "usky-park"
- DatabaseEventThread::DatabaseEventThread(QObject *parent) : QThread(parent)
- {
- hour = 255;
- keep=false;
- sqlList.clear();
- db = QSqlDatabase::addDatabase("QMYSQL","write_db1");
- db.setHostName(QString(HostName));
- db.setPort(HostPort);
- db.setUserName(QString(UserName));
- db.setPassword(QString(PassWord));
- db.setDatabaseName(QString(DatabaseName));
- }
- void DatabaseEventThread::appendSql(QString sql)
- {
- sqlList.append(sql);
- }
- void DatabaseEventThread::stop()
- {
- keep = false;
- }
- void DatabaseEventThread::run()
- {
- keep = true;
- while (keep) {
- if(!db.open()){
- db.open();
- }else{
- if(sqlList.length()>0){
- while (sqlList.length()>0) {
- db.exec(sqlList.first());
- emit dbdata_log(QString("[%1] DatabaseEventThread sqlList.length() %2 writeProcess sql %3").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss.zzz")).arg(sqlList.length()).arg(sqlList.first()));
- sqlList.removeFirst();
- usleep(1000);
- }
- }
- }
- usleep(50000);
- }
- }
|