Select max(id) form TableName
Select max(id) form TableName
To copy to clipboard, switch view to plain text mode
Should do the trick.
Or You may try.
qry.prepare("SELECT Id FROM TableName Order by Id");
if(!qry.exec())
{
qFatal("Failed to count records");
return;
}
while(qry.next())
{
int index = qry.value(0).toInt();
if(temp < index)
break;
else
++temp;
}
QSqlQuery qry;
qry.prepare("SELECT Id FROM TableName Order by Id");
if(!qry.exec())
{
qFatal("Failed to count records");
return;
}
while(qry.next())
{
int index = qry.value(0).toInt();
if(temp < index)
break;
else
++temp;
}
To copy to clipboard, switch view to plain text mode
This will get you the first free id.If by any chance You would get some free ids in between due to dropping a row.
Bookmarks