A Strange Behaviour with my ORACLE Database



  • Hi; i am working on Qt application which uses ORACLE database and i meet a strange problem.
    First part i compile the OCI driver like recommended in documentation and i finish without errors.I got the useful (.dll) and copied to
    ..\Qt\4.7.4\plugins\sqldrivers.
    Second part i have tested if my OCI plugin is available with "QSqlDatabase::drivers()" and that is OK!
    Now i have connected to ORACLE with the following code
    @
    QSqlDatabase db=QSqlDatabase::addDatabase("QOCI");
    db.setDatabaseName("TestData");
    db.setUserName("SYSTEM");
    db.setPassword("aurilers");
    db.setHostName("localhost");
    db.setPort(1521);

    if( db.open()){
    QMessageBox::information(0,"INFO","Connected to database");
    }else
    QMessageBox::information(0,"ERROR",db.lastError().text());
    @
    After i have really connected to database and database have opened!!.
    Now I started SQL Plus and i have executed the following queries:
    i created a table nammed "Student" with 2 fields(id and name),
    I inserted into table 3 rows and everything is fine
    Now i come back in my Qt application and i executed this code
    @
    if( db.open()){
    QSqlQuery q("select * from Student");

    while( q.next())
          QMessageBox::information(0,"RESULTS",q.value(1).toString() );
    

    }
    @
    Normally i must to see the names of my 3 rows but nothing appears......
    Thereafter when i tried to execute the insertions's queries in my Qt application ,the code works fine and with the SELECT Statement i retrieved rows of my table successfully.

    What can cause this?
    When i execute queries(create,delete,insert ,update) from my Qt application,that works fine and i retrieve data successfully,but when i execute this queries from ORACLE database that also works fine but i can't to retrieve the data in my Qt application.
    Thanks for advance



  • Call a
    @
    q.lastError();
    @
    after you create a QSqlQuery - maybe in communication is error.

    What value you have from q.size() and what values you see in QMessageBox from q.value(1).toString()?



  • Using user "SYSTEM" for the regular Oracle work is really a bad idea. Create a dedicated user for your schema!

    Also, make sure that all involved users can read your data.

    And last: do you connect as the same user on sqlplus?



  • [quote author="Volker" date="1316472774"]Using user "SYSTEM" for the regular Oracle work is really a bad idea.[/quote]

    I guess posting system credentials on public available forums is even worse. Please always anonymize your examples so they do not contain any real world usernames, passwords and/or host/port combinations!



  • Are you sure you have committed your oracle sqlplus transaction? If not you will not be able to see the results from your qt application, and this is a normal behaviour for Oracle (and other RDBMS).

    And yes, pasting credentials into public code snippet is a bad idea, but at least you pointed to localhost, which is not so easy to find....



  • [quote author="Volker" date="1316472774"]Using user "SYSTEM" for the regular Oracle work is really a bad idea. Create a dedicated user for your schema!

    Also, make sure that all involved users can read your data.

    And last: do you connect as the same user on sqlplus?[/quote]

    Thanks Volker,i think that i solve my problem.
    In fact ,when i was working on Qt application, i had also connected in the same time on sqlplus.
    therefore,when i disconnected on sqlpus before to retrieving my data from Qt application,that works fine.
    Do you think that it was this the problem?



  • Probably the problem is a commit not done. When acting in parallel on the data, independently from the users you are connect as, the database does not make all the data immediately visible until you commit. This is a behavior required to avoid dirty reads, phantom reads, and so on. Moreover, if a user is performing a locking operation (e.g., select for update) the other user (in the other transaction) is locked. When the first user ends (commit/abort) his work, the other user is unlocked and can access the data. So you problem could be either data uncommitted or a lock on the data you are trying to get from the database.


Log in to reply
 

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