Hi I need to delete all rows from QSqlDatabase table, my code looks,
QString dbName = QDir::currentPath()+"/DB";
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(dbName);
if(db.open()){
QSqlQuery query(db);
query.prepare("truncate fRecogtable"); // this not working
//query.prepare("Delete from fRecogtable"); //this working
if(!query.exec() )
qDebug() << "deletion failed";
query.clear();
db.close();
}
The issue is the command truncate fRecogtable
not deleting the record from table where as Delete from fRecogtable
working. I need to use truncate
as I have to reset auto incremental fields.
What can be the issue?
Edit:
Finally I manged to get work with
query.prepare("Delete from fRecogtable");
if(!query.exec() )
qDebug() << "deletion failed";
query.clear();
query.prepare("DELETE FROM SQLITE_SEQUENCE WHERE name='fRecogtable'");
if(!query.exec() )
qDebug() << "deletion failed";
Thanks Haris