Problem with Query - QODBC, Informix
-
Hi,
I've got problem with Query and bindvalue.Here is the code:
void pacjenci_window::on_dodaj_clicked()
{
QSqlQuery uQuery = QSqlQuery(db);
uQuery.prepare("INSERT INTO pacjent(nr_ubezpieczenia, imie_pacjenta, nazwisko_pacjenta, adres_pacjenta, telefon_pacjenta) VALUES(:nr_ub, :imie, :nazwisko, :adres, :telefon)");
uQuery.bindValue(":nr_ub",ui->nr_ub->text());
uQuery.bindValue(":imie",ui->imie->text());
uQuery.bindValue(":nazwisko",ui->nazwisko->text());
uQuery.bindValue(":adres",ui->adres->text());
uQuery.bindValue(":telefon",ui->nr_tel->text());
if(!uQuery.exec()){
qDebug() << db.lastError().text();
qDebug() << uQuery.lastError().text() << " DODAJ BUTTON error";
}
else {
qDebug() << "Przeszlo";
}
sQuery.prepare("SELECT * FROM pacjent");
if(!sQuery.exec()){
qDebug() << uQuery.lastError().text() << " DODAJ BUTTON select error";
}
sQuery.last();
FillForm();
}
When executing I'm getting this error:
QODBCResult::exec: Unable to execute statement: "[Microsoft][Menedżer sterowników ODBC] Błąd sekwencji funkcji"
" "
"[Microsoft][Menedżer sterowników ODBC] Błąd sekwencji funkcji QODBC3: Unable to execute statement"
I searched lot's of topic in others forum's and I think its problem with ui->nr_ub->text(). When I try execute Query with values like 'abcdef' writing in Query everything is fine. I guess that problem is with text() - I mean QString look's like "abcdef" and my Query only response on variable looking like 'abcdef'. Could anyone help me with this :)?Sorry for my English, I'm Student and I'm still learning :D
-
hi and welcome
You english is very fine.Can you maybe post the part where u create this table/db.
As its hard to say anything without knowing the underlying fields. -
Yes of course, I hope If paste link from PasteBin is fine.
pacjenci_window.h:
http://pastebin.com/BVs0WrRd
pacjenci_window.cpp:
http://pastebin.com/AH2G3DhC@edit other's action's button's and table action not work corretly too :) but step by step for solve all problem's :)
@old pastebin, sorry, now changed to the newest code. -
Maybe the following helps:
uQuery.prepare("INSERT INTO pacjent(nr_ubezpieczenia, imie_pacjenta, nazwisko_pacjenta, adres_pacjenta, telefon_pacjenta) VALUES(?, ?, ?, ?, ?)"); uQuery.bindValue(0 ,ui->nr_ub->text()); uQuery.bindValue(1 ,ui->imie->text()); uQuery.bindValue(2 ,ui->nazwisko->text()); uQuery.bindValue(3 ,ui->adres->text()); uQuery.bindValue(4 ,ui->nr_tel->text());
-
@ObiWan
No, still not working :(@edit I changed some options in IBM Informix ODBC driver setup, now it looks like:
https://img42.com/AGfcv
And now I'm getting this error:
QODBCResult::exec: Unable to execute statement: "[Informix][Informix ODBC Driver][Informix]CURSOR not on SELECT statement." -
@ObiWan
Yes, I just copied your code to mine.
void pacjenci_window::on_dodaj_clicked()
{
QSqlQuery uQuery = QSqlQuery(db);
uQuery.prepare("INSERT INTO pacjent(nr_ubezpieczenia, imie_pacjenta, nazwisko_pacjenta, adres_pacjenta, telefon_pacjenta) VALUES(?, ?, ?, ?, ?)");
uQuery.bindValue(0 ,ui->nr_ub->text());
uQuery.bindValue(1 ,ui->imie->text());
uQuery.bindValue(2 ,ui->nazwisko->text());
uQuery.bindValue(3 ,ui->adres->text());
uQuery.bindValue(4 ,ui->nr_tel->text());
uQuery.exec();
sQuery.prepare("SELECT * FROM pacjent");
if(!sQuery.exec()){
qDebug() << uQuery.lastError().text() << " DODAJ BUTTON select";
}
sQuery.last();
FillForm();
}
@added qDebug to uQuery too, new error:
QODBCResult::exec: Unable to execute statement: "[Informix][Informix ODBC Driver][Informix]CURSOR not on SELECT statement."
"[Informix][Informix ODBC Driver][Informix]CURSOR not on SELECT statement. QODBC3: Unable to execute statement" DODAJ BUTTON insert -
toStdString() - error:
C:\Users\michu\Documents\przychodnia_projekt\pacjenci_window.cpp:60: błąd: no matching function for call to 'QSqlQuery::bindValue(int, std::string)'
uQuery.bindValue(1 ,ui->imie->text().toStdString());
^
Trying to add additional variables with toStdString() and then add them to bindvalue by name but dont work too.toLocal8bit() - the same error as on begin:
QODBCResult::exec: Unable to execute statement: "[Informix][Informix ODBC Driver][Informix]CURSOR not on SELECT statement."
"[Informix][Informix ODBC Driver][Informix]CURSOR not on SELECT statement. QODBC3: Unable to execute statement" DODAJ BUTTON insert@edit:
trying with toUtf8() - same error like above.
with toWCharArray() - same error like toStdString()@edit
for toStdString() & toUtf8 I added data() but now error is the same like for others...uQuery.bindValue(1 ,ui->imie->text().toUtf8().data());
error:
QODBCResult::exec: Unable to execute statement: "[Informix][Informix ODBC Driver][Informix]CURSOR not on SELECT statement."
"[Informix][Informix ODBC Driver][Informix]CURSOR not on SELECT statement. QODBC3: Unable to execute statement" DODAJ BUTTON insert -
Yes! I found solution. Its simply uncheck option Insert Coursor in ODBC IBM driver config...
Like on picture:
https://img42.com/r4DZU
Thanks guys for support. -
hi,@Mich-Q ,i'm new about qt and informix, i need informix driver,can you sent it to me.if it is win32,it is better,can you?my english is terrible-.-。thank you.
-
Hi and welcome to the forums
you can use ODBC for connecting Qt to informix server.
As far as i know there is no native Qt driver for informix.https://www.ibm.com/developerworks/data/library/techarticle/dm-1108odbcdrivermanager/index.html
Sorry I dont its download link.
-
@mrjj hi,i know there is no native qt driver for informix.when i saw this topic ,i find https://img42.com/r4DZU,there is a dialog which title is "ibm informix odbc driver setup", i think you have the informix odbc driver...
i guess you dont have informix odbc driver,is that right? -
@erick-joshua
Yes, Qt do not come with ODBC drivers. They are supplied by the vendors or microsoft.
Oddly i cannot find a download link at IBM.
Even other pages mention it
http://www.ciscounitytools.com/Applications/CxN/InformixODBC/InformixODBC.html
This seems to be the SDK
http://www.ciscounitytools.com/Applications/CxN/InformixODBC/clientsdk.4.10.TC7DE.WIN.zip
but i have no idea what version of the actual server it works with etc.