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


  • Qt Champions 2016

    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."



  • Have you noticed the end of th query:

    INSERT INTO ... VALUES(?, ?, ?, ?, ?)
    
    

    I aks, because there is no line break and it's not visible.



  • @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



  • Qt docu says:
    QString stores a string of 16-bit QChars, where each QChar corresponds one Unicode 4.0 character.

    Informix is old and I suppose cannot handle Unicode.
    Try toStdString() or toLocal8Bit() to bind values.



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.