Andrewgaven
13th January 2013, 05:06
Greetings, I'm sending this query to a third party program database using an ODBC driver
"SELECT table FROM Column WHERE DESCRIPCION = 'SOMETHING'"
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
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
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);
}
Does anyone see the problem with this code, or maybe a work around?
Thank in advance.
"SELECT table FROM Column WHERE DESCRIPCION = 'SOMETHING'"
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
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
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);
}
Does anyone see the problem with this code, or maybe a work around?
Thank in advance.