jano_alex_es
5th May 2009, 08:58
Hello,
The next code works perfectly:
//Note: CSQLUsers::AL_PUPIL is "1", an intenger
QSqlQuery data(QString("SELECT id FROM users WHERE iaccesslevel=%1 AND sname = 'Alex' ") .arg(CSQLUsers::AL_PUPIL), *pointer_my_database->GetDBPtr());
bool test1 = data.first();
bool test2 = data.isValid();
bool test3 = data.isSelect();
But, when I try to use the arguments of QString (something that works with integers or other sort of variables)
//Note: CSQLUsers::AL_PUPIL is "1", an intenger
QString name = 'Alex';
QSqlQuery data(QString("SELECT id FROM users WHERE iaccesslevel=%1 AND sname = %2 ") .arg(CSQLUsers::AL_PUPIL) .arg(name), *pointer_my_database->GetDBPtr());
bool test1 = data.first();
bool test2 = data.isValid();
bool test3 = data.isSelect();
the three booleans are false... why? the argument should be converted to QString properly and call the SQL :S
thanks!
The next code works perfectly:
//Note: CSQLUsers::AL_PUPIL is "1", an intenger
QSqlQuery data(QString("SELECT id FROM users WHERE iaccesslevel=%1 AND sname = 'Alex' ") .arg(CSQLUsers::AL_PUPIL), *pointer_my_database->GetDBPtr());
bool test1 = data.first();
bool test2 = data.isValid();
bool test3 = data.isSelect();
But, when I try to use the arguments of QString (something that works with integers or other sort of variables)
//Note: CSQLUsers::AL_PUPIL is "1", an intenger
QString name = 'Alex';
QSqlQuery data(QString("SELECT id FROM users WHERE iaccesslevel=%1 AND sname = %2 ") .arg(CSQLUsers::AL_PUPIL) .arg(name), *pointer_my_database->GetDBPtr());
bool test1 = data.first();
bool test2 = data.isValid();
bool test3 = data.isSelect();
the three booleans are false... why? the argument should be converted to QString properly and call the SQL :S
thanks!