#include <QtCore/QCoreApplication>
#include <QtSql>
#include <QTextCodec>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QTextCodec::setCodecForTr(QTextCodec::codecForLocale());
QSqlDatabase dbconn=QSqlDatabase::addDatabase("QSQLITE");
dbconn.setDatabaseName("mytest1.db");
if(!dbconn.open()){
qDebug()<<QObject::tr("打开数据库错误!");
}else{
qDebug()<<QObject::tr("打开数据库成功!");
}
QSqlQuery query;
//query.exec("create table table3(id INTEGER PRIMARY KEY AUTOINCREMENT,name varchar(20));");
//query.exec("delete from table2 where id = 0;");
//query.exec("drop table table1;drop table table2;");
query.exec(QObject::tr("insert into table3 (name) values('22');"));
query.exec("select * from table3;");
while(query.next()){
int ele0=query.value(0).toInt();
QString ele1=query.value(1).toString();
qDebug()<<ele0<<ele1;
}
query.exec("drop table3");
return a.exec();
}