Hi to all,
I'm having some problems binding values in a "SELECT" statement on a table, maybe the code will explain better:
void frmLogin::submit()
{
strQuery = "SELECT * FROM tbUtente WHERE utenteName=':name';"; //doesn't work
//strQuery = "SELECT * FROM tbUtente;"; //it works
strName = ui.lneUser->text();
strPass = ui.lnePwd->text();
/*
qDebug() << "Nome: " << strName;
qDebug() << "Pass: " << strPass;
*/
queryUser.prepare(strQuery);
queryUser.bindValue(":name", strName); //doesn't work
// without bind a value it works
queryUser.exec();
while (queryUser.next())
{
qDebug() << "Nome: " << queryUser.value(1).toString();
qDebug() << "Pass: " << queryUser.value(2).toString();
}
if (rec.count() >= 1)
{
this->accept();
qDebug() << "Ok submit!";
}
else
{
ui.lneUser->clear();
ui.lnePwd->clear();
ui.lneUser->setFocus();
}
userName = ui.lneUser->text();
}
void frmLogin::submit()
{
QString strQuery;
QString strName;
QString strPass;
strQuery = "SELECT * FROM tbUtente WHERE utenteName=':name';"; //doesn't work
//strQuery = "SELECT * FROM tbUtente;"; //it works
strName = ui.lneUser->text();
strPass = ui.lnePwd->text();
/*
qDebug() << "Nome: " << strName;
qDebug() << "Pass: " << strPass;
*/
QSqlQuery queryUser;
queryUser.prepare(strQuery);
queryUser.bindValue(":name", strName); //doesn't work
// without bind a value it works
queryUser.exec();
while (queryUser.next())
{
qDebug() << "Nome: " << queryUser.value(1).toString();
qDebug() << "Pass: " << queryUser.value(2).toString();
}
QSqlRecord rec = queryUser.record();
if (rec.count() >= 1)
{
this->accept();
qDebug() << "Ok submit!";
}
else
{
ui.lneUser->clear();
ui.lnePwd->clear();
ui.lneUser->setFocus();
}
userName = ui.lneUser->text();
}
To copy to clipboard, switch view to plain text mode
so, if I use the "//doesn't work" instrutcions (line 7 and line 18) it doesn't return a value, instead, if I comment line 7 and 18 and run line 8 it returns all the values!!!
Why it happens?!
thanks in advance
PS: I'm using Qt 4.5.0, Sqlite3 database and WinXP.
Bookmarks