I have a small function like this
bool QcgDatabase::onceindb(const QString& userId)
{
mDb->prepareSqlQuery("SELECT count(*) FROM mytable WHERE userid=:userId;", "database");
mDb->prepareBindValue(":userId", userId);
mDb->sqlExec();
bool d = mDb->sqlQuery().isActive();
QVariant c = mDb->sqlQuery().value(QString("count(*)"));
int e = c.toInt();
if (e == 1) {
return true;
}
else {
return false;
}
}
When I do this command in SQL, the result looks like this
I just want to take value 2
for comparison below, but in the code when I debug, QVariant c
always return invalid, therefore e is always = 0
. I thought my SQL command is not active, but when I debug, bool d
always return true. Do you guys know why? how can I receive 2
as expected ?