第一次用Windows live writer,就用此文章做下试验吧。
代码如下,摘自《精通qt4编程》
@H_403_5@QTime t; srand(1); t.start(); query.prepare("INSERT INTO automobil " "VALUES (?,?,?)"); long records = 10000; for(int i=0;i<records;i++) { query.bindValue(0,i); query.bindValue(1,"四轮"); query.bindValue(2,"轿车"); query.bindValue(3,"富康"); query.bindValue(4,rand()%100); query.bindValue(5,rand()%10000); query.bindValue(6,rand()%300); query.bindValue(7,rand()%200000); query.bindValue(8,rand()%52); query.bindValue(9,rand()%100); bSuccess = query.exec(); if(!bSuccess) { QsqlError lastError = query.lastError(); qDebug() << lastError.driverText()<<QString(QObject::tr("插入失败")); } } qDebug()<<QObject::tr("插入 %1条记录,耗时: %2 ms").arg(records).arg(t.elapsed()); t.restart(); bSuccess = query.exec("SELECT * FROM automobil ORDER BY id DESC"); if(bSuccess) qDebug()<<QObject::tr("排序 %1 条记录,耗时: %2 ms").arg(records).arg(t.elapsed()); else qDebug()<<QObject::tr("排序失败!"); t.restart(); for(int i=0;i<records;i++) { query.clear(); query.prepare(QString("UPDATE automobil SET " "attribute=?,type=?,kind=?," "nation=?,carnumber=?,elevaltor=?," "distance=?,oil=?,temperature=? " "WHERE id=%1").arg(i)); query.bindValue(0,"四轮"); query.bindValue(1,"轿车"); query.bindValue(2,"富康"); query.bindValue(3,rand()%100); query.bindValue(4,rand()%10000); query.bindValue(5,rand()%300); query.bindValue(6,rand()%200000); query.bindValue(7,rand()%52); query.bindValue(8,rand()%100); bSuccess = query.exec(); if(!bSuccess) { QsqlError lastError = query.lastError(); qDebug() << lastError.driverText()<<QString(QObject::tr("更新失败")); } } qDebug()<<QObject::tr("更新 %1条记录,耗时: %2 ms").arg(records).arg(t.elapsed());