Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. A Strange Behaviour with my ORACLE Database
Qt 6.11 is out! See what's new in the release blog

A Strange Behaviour with my ORACLE Database

Scheduled Pinned Locked Moved General and Desktop
7 Posts 5 Posters 4.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maxoreli
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • H Offline
      H Offline
      Hostel
      wrote on last edited by
      #2

      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()?

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        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?

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on last edited by
          #4

          [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!

          1 Reply Last reply
          0
          • F Offline
            F Offline
            fluca1978
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • M Offline
              M Offline
              maxoreli
              wrote on last edited by
              #6

              [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?

              1 Reply Last reply
              0
              • F Offline
                F Offline
                fluca1978
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved