Skip to content

Commit

Permalink
Update mythread.h
Browse files Browse the repository at this point in the history
fix the sql error when ID is a num
  • Loading branch information
Big7lion authored Jun 7, 2017
1 parent a7e80c2 commit c10b3e1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions DataCollector/mythread.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class WorkerThread : public QThread
if(!strTables.contains(current_ID))
{
qDebug()<<"no ID table exist";
query_string = QString("create table IF NOT EXISTS %1(ID INT NOT NULL,TEMP VARCHAR(20) NOT NULL,P INT NOT NULL,I INT NOT NULL,D INT NOT NULL,TIME VARCHAR(30),PRIMARY KEY (ID))").arg(current_ID);
query_string = QString("create table IF NOT EXISTS `%1` (ID INT NOT NULL,TEMP VARCHAR(20) NOT NULL,P INT NOT NULL,I INT NOT NULL,D INT NOT NULL,TIME VARCHAR(30),PRIMARY KEY (ID))").arg(current_ID);
qDebug()<<query_string;
if(query.exec(query_string))
{
Expand All @@ -68,7 +68,7 @@ class WorkerThread : public QThread
qDebug()<<query.lastError();
}
query.clear();
query_string = QString("alter table %1 modify ID INT auto_increment").arg(current_ID);
query_string = QString("alter table `%1` modify ID INT auto_increment").arg(current_ID);
qDebug()<<query_string;
if(query.exec(query_string))
{
Expand All @@ -88,15 +88,15 @@ class WorkerThread : public QThread
msleep(5);
if(data_write_falg)
{
query.prepare(QString("insert into %1 (`TEMP`, `P`, `I`, `D`, `TIME`) values(?,?,?,?,?)").arg(current_ID));
query.prepare(QString("insert into `%1` (`TEMP`, `P`, `I`, `D`, `TIME`) values(?,?,?,?,?)").arg(current_ID));
query.bindValue(1,P_data);
query.bindValue(2,I_data);
query.bindValue(3,D_data);
query.bindValue(0,Temp_data);
query.bindValue(4,QTime::currentTime().toString(" hh:mm:ss"));
success = query.exec();
if(!success){
qDebug() << "²åÈëʧ°Ü£º" <<endl;
qDebug() << "insert failed!" <<endl;
}
data_write_falg = 0;
}
Expand Down

0 comments on commit c10b3e1

Please sign in to comment.