Greetings, I'm sending this query to a third party program database using an ODBC driver
"SELECT table FROM Column WHERE DESCRIPCION = 'SOMETHING'"
"SELECT table FROM Column WHERE DESCRIPCION = 'SOMETHING'"
To copy to clipboard, switch view to plain text mode
my funtion should return a Stringlist with the values of column "o" where the value of column "k" match "pointer"
Let's say, for example that my table is like
code name lastname description
code name lastname description
To copy to clipboard, switch view to plain text mode
if i set o="0" it return the codes fine, but any value diferent that "0" return the error "QODBCResult::data: column # out of range".
This is the same funtion that I use for a Postgres database but for some reason it doesn't work with the ODBC driver
{
conectdbisam();
int h;
h=0;
if(db.open())
{
if(qry.exec("SELECT * FROM "+table))
{
columna = rec.fieldName(k);
}
if(qry.exec("SELECT "+columna+" FROM "+table+" WHERE "+columna+" = '"+pointer+"'"))
{
while(qry.next())
{
line2 =qry.value(o).toString().simplified();
lista.append(line2);
h++;
if (h==500)
break;
}
}
else
{
qDebug() << "Error =" << db.lastError().text();
}
qry.clear();
}
else
{
qDebug() << "Error =" << db.lastError().text();
}
}
QStringList conecta2::leedb(QString table, int k, int o, QString pointer)
{
conectdbisam();
QString line;
QString line2;
QStringList lista;
int h;
h=0;
if(db.open())
{
QSqlQuery qry;
if(qry.exec("SELECT * FROM "+table))
{
QSqlRecord rec = qry.record();
columna = rec.fieldName(k);
}
if(qry.exec("SELECT "+columna+" FROM "+table+" WHERE "+columna+" = '"+pointer+"'"))
{
while(qry.next())
{
line2 =qry.value(o).toString().simplified();
lista.append(line2);
h++;
if (h==500)
break;
}
}
else
{
qDebug() << "Error =" << db.lastError().text();
}
qry.clear();
}
else
{
qDebug() << "Error =" << db.lastError().text();
}
return QStringList(lista);
}
To copy to clipboard, switch view to plain text mode
Does anyone see the problem with this code, or maybe a work around?
Thank in advance.
Bookmarks