Qt-interest Archive, May 2008
[4.4.0] QSqlQuery error on ODBC Access database
Message 1 in thread
Hi,
I am running into a problem, and I don't see what I'm doing wrong. Considder
the following piece of code:
QString sql = QString("SELECT [%1].[ID] FROM [%1] WHERE [%1].[Name] =
\"%2\";")
.arg(m_groupsTable)
.arg(leGroupName->text());
QSqlQuery query(QSqlDatabase::database("bibtechmondb"));
query.prepare(sql);
query.exec();
if (query.lastError().type() != QSqlError::NoError) {
qDebug() << query.lastError().text();
qDebug() << sql;
}
It runs a simple query on an MS Access database, that has been connected
through ODBC. The connection itself works. m_groupsTable contains the name
of the table I am interested in, and leGroupName the string. I would have
expected no errors, but I get the following error printed to my output by
the qDebug() statements:
QODBCResult::exec: Unable to execute statement: [Microsoft][ODBC Microsoft
Access-stuurprogramma] Er zijn te weinig parameters. Het verwachte aantal
is: 1.
" [Microsoft][ODBC Microsoft Access-stuurprogramma] Er zijn te weinig
parameters. Het verwachte aantal is: 1. QODBC3: Unable to execute statement"
"SELECT [BibTechMon selection groups].[ID] FROM [BibTechMon selection
groups] WHERE [BibTechMon selection groups].[Name] = "test";"
The first is the error, the second is the query that was executed.
Translated, that error reads: "There are not enough parameters. The expected
number is: 1". The query looks good to me, and if I copy/paste it into
Access, it runs just fine.
Can anyone please point me to what this missing parameter might be?
Thanks,
André
--
[ signature omitted ]
Message 2 in thread
"André Somers" <andre@xxxxxxxxxxxxxxxx> wrote in message
news:g0uglp$dfd$1@xxxxxxxxxxxxxxxx
> Hi,
>
> I am running into a problem, and I don't see what I'm doing wrong.
> Considder the following piece of code:
>
> QString sql = QString("SELECT [%1].[ID] FROM [%1] WHERE [%1].[Name] =
> \"%2\";")
> .arg(m_groupsTable)
> .arg(leGroupName->text());
> QSqlQuery query(QSqlDatabase::database("bibtechmondb"));
> query.prepare(sql);
> query.exec();
> if (query.lastError().type() != QSqlError::NoError) {
> qDebug() << query.lastError().text();
> qDebug() << sql;
> }
>
> It runs a simple query on an MS Access database, that has been connected
> through ODBC. The connection itself works. m_groupsTable contains the name
> of the table I am interested in, and leGroupName the string. I would have
> expected no errors, but I get the following error printed to my output by
> the qDebug() statements:
>
> QODBCResult::exec: Unable to execute statement: [Microsoft][ODBC
> Microsoft Access-stuurprogramma] Er zijn te weinig parameters. Het
> verwachte aantal is: 1.
>
> " [Microsoft][ODBC Microsoft Access-stuurprogramma] Er zijn te weinig
> parameters. Het verwachte aantal is: 1. QODBC3: Unable to execute
> statement"
>
> "SELECT [BibTechMon selection groups].[ID] FROM [BibTechMon selection
> groups] WHERE [BibTechMon selection groups].[Name] = "test";"
>
> The first is the error, the second is the query that was executed.
> Translated, that error reads: "There are not enough parameters. The
> expected number is: 1". The query looks good to me, and if I copy/paste it
> into Access, it runs just fine.
>
> Can anyone please point me to what this missing parameter might be?
OK: I finally found the problem. Instead of using double quotes, use single
quotes around the Name value in the SQL statement and it works just fine.
André
--
[ signature omitted ]