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();
//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();
To copy to clipboard, switch view to plain text mode
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
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();
//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();
To copy to clipboard, switch view to plain text mode
the three booleans are false... why? the argument should be converted to QString properly and call the SQL :S
thanks!
Bookmarks