首页 > 技术知识 > 正文

qt的数据库的部分代码如下:

插入部分:

QSqlQuery query(db); QString t1 = QDateTime::currentDateTime().toString(“yyyyMMdd hh:mm:ss”); QString str1 = temps+”_point”; query.prepare (“INSERT INTO “+str1+” ( infoname,info_address,info_rate,info_value,isactivepower,time) VALUES ( :infoname, :info_address, :info_rate, :info_value,:isactivepower,:time);”); query.bindValue(“:infoname”, data.infoname); query.bindValue(“:info_address”, data.info_address); query.bindValue(“:info_rate”, data.info_rate); query.bindValue(“:info_value”,data.info_value); query.bindValue(“:isactivepower”,data.isactivepower); query.bindValue(“:time”, t1); // qDebug()<<“语句”<<query.lastQuery(); query.exec();

读取部分:

QSqlQuery query(db); QString temps= date; temps.remove(QChar(-),Qt::CaseInsensitive); QMap<int,infovalue> infos; infovalue iec; int hour= QTime::currentTime().hour(); int minutes= QTime::currentTime().minute(); int indexflag=hour*60+minutes; query.prepare(“SELECT * FROM “+temps+” where time =:time and type =:type and indexflag <:indexflag order by indexflag;”); query.bindValue(“:time”, date); query.bindValue(“:type”, type); query.bindValue(“:indexflag”, indexflag);

大概如上所示,具体的数据操作由各自的所需进行编写

猜你喜欢