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);大概如上所示,具体的数据操作由各自的所需进行编写
免责声明:文章内容来自互联网,本站不对其真实性负责,也不承担任何法律责任,如有侵权等情况,请与本站联系删除。
转载请注明出处:qt sqlquery数据的插入和读写 https://www.yhzz.com.cn/a/15956.html