sqlite事务实例:
第一种方法:
QString tempStr1="";
QDateTime startT=QDateTime::currentDateTime();
query.exec("BEGIN TRANSACTION;");
bool ok1=false;
while((!subEndDateTime.isNull())&&subEndDateTime.toTime_t()<=endDateTime.toTime_t())
{
QString s_str = startDateTime.toString("yyyy-MM-dd HH:mm:ss");
QString e_str = subEndDateTime.toString("yyyy-MM-dd HH:mm:ss");
tempStr1="update cardetectinfo set groupTag='"+QString::number(groupTag)+"' where cameraName='"+cameraName+"' and checkPointName='"+checkPointName+"' and countTime>='" +s_str+"' and countTime<='"+e_str+"';";
ok1= query.exec(tempStr1);
startDateTime=subEndDateTime.addSecs(1);
subEndDateTime=startDateTime.addSecs(sec_sum);
groupTag++;
}
if(ok1 )
{
query.exec("COMMIT");
}else
{
query.exec("ROLLBACK");
}
第二种方法:
QString tempStr1="";
QDateTime startT=QDateTime::currentDateTime();
query.exec("BEGIN TRANSACTION;");
bool ok1=false;
while((!subEndDateTime.isNull())&&subEndDateTime.toTime_t()<=endDateTime.toTime_t())
{
QString s_str = startDateTime.toString("yyyy-MM-dd HH:mm:ss");
QString e_str = subEndDateTime.toString("yyyy-MM-dd HH:mm:ss");
query.prepare("update cardetectinfo set groupTag=? where cameraName=? and checkPointName=? and countTime>=? and countTime<=?");
query.bindValue(0,groupTag);
query.bindValue(1,cameraName);
query.bindValue(2,checkPointName);
query.bindValue(3,s_str);
query.bindValue(4,e_str);
ok1= query.exec();
startDateTime=subEndDateTime.addSecs(1);
subEndDateTime=startDateTime.addSecs(sec_sum);
groupTag++;
}
if(ok1 )
{
query.exec("COMMIT");
}else
{
query.exec("ROLLBACK");
}
但是多语句提交一直未搞定,期待解决!
|