Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QODBC in QML? Not Able to find tables
Qt 6.11 is out! See what's new in the release blog

QODBC in QML? Not Able to find tables

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 4 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    I am currently trying to make a few simple queries through js in a qml file. I am working on a Windows XP machine where I have an ODBC connection to an Oracle RDB. In my main.cpp I was able to figure out how to get connected to the database but the connection doesn't seem to be reachable in my knowledge in the QML file. This is what I have so far.

    main.cpp
    @ #define DB_DRIVER "QODBC"
    // you need to replace the following macros with the values relevant to
    // your DSN.
    // DB_DBNAME = the name of the DSN.
    #define DB_DBNAME "level2dave"
    // DB_USER = a username valid for your database
    #define DB_USER ""
    // DB_PASSWD = password for DB_USER
    #define DB_PASSWD "
    "
    // DB_HOST is not relevant to DSNs
    #define DB_HOST ""

       QSqlDatabase level2 = QSqlDatabase::addDatabase(DB_DRIVER);
       level2.setDatabaseName(DB_DBNAME);
       level2.setUserName(DB_USER);
       level2.setPassword(DB_PASSWD);
       level2.setHostName(DB_HOST);
    
       if (!level2.open()) {
           QMessageBox::critical(0, qApp->tr("Cannot open database"),
               qApp->tr("Unable to establish a database connection.\n"
                        "Click Cancel to exit."), QMessageBox::Cancel);
           return false;
       }
    

    @

    I am 99% sure this is working because I don't get the QMessageBox anymore. That took a good long while, but now over in the qml file it seems that I can't get access to the database that I just linked to. This what I have there.

    @ function linkthedb() {
    var level2 = openDatabaseSync("level2", "1.0", "ODBC Connect", 10000000000000);

            level2.transaction(
                        function(tx) {
                            // Show all
                            var rs = tx.executeSql('SELECT * FROM knowntable');
    
                        }
                        )
        }
    

    @

    When I run all of this it just tells me the knowntable is not there. I know it is. I must not be really connecting to the database in the qml file. I thought that the addDatabase would put the ODBC database on the same level as the SqLite ones that are on the device. If anyone can help I would love a hand.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      minimoog77
      wrote on last edited by
      #2

      Database API is for offline storage, it's SQLite database.

      So at the moment I don't think it's possible to connect to ODBC database, you will need to provide bridge in C++. Shouldn't be that hard.

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        I am no good at C++, which why I wanted to do it in QML in the first place, but oh well. Thanks for the reply. I guess i might have to get my hands a little dirtier.

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          Is it still not possible do this without c++?

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            [quote author="shullw" date="1314391681"]I am currently trying to make a few simple queries through js in a qml file. I am working on a Windows XP machine where I have an ODBC connection to an Oracle RDB. In my main.cpp I was able to figure out how to get connected to the database but the connection doesn't seem to be reachable in my knowledge in the QML file. This is what I have so far.

            main.cpp
            @ #define DB_DRIVER "QODBC"
            // you need to replace the following macros with the values relevant to
            // your DSN.
            // DB_DBNAME = the name of the DSN.
            #define DB_DBNAME "level2dave"
            // DB_USER = a username valid for your database
            #define DB_USER ""
            // DB_PASSWD = password for DB_USER
            #define DB_PASSWD "
            "
            // DB_HOST is not relevant to DSNs
            #define DB_HOST ""

               QSqlDatabase level2 = QSqlDatabase::addDatabase(DB_DRIVER);
               level2.setDatabaseName(DB_DBNAME);
               level2.setUserName(DB_USER);
               level2.setPassword(DB_PASSWD);
               level2.setHostName(DB_HOST);
            
               if (!level2.open()) {
                   QMessageBox::critical(0, qApp->tr("Cannot open database"),
                       qApp->tr("Unable to establish a database connection.\n"
                                "Click Cancel to exit."), QMessageBox::Cancel);
                   return false;
               }
            

            @

            I am 99% sure this is working because I don't get the QMessageBox anymore. That took a good long while, but now over in the qml file it seems that I can't get access to the database that I just linked to. This what I have there.

            @ function linkthedb() {
            var level2 = openDatabaseSync("level2", "1.0", "ODBC Connect", 10000000000000);

                    level2.transaction(
                                function(tx) {
                                    // Show all
                                    var rs = tx.executeSql('SELECT * FROM knowntable');
            
                                }
                                )
                }
            

            @

            When I run all of this it just tells me the knowntable is not there. I know it is. I must not be really connecting to the database in the qml file. I thought that the addDatabase would put the ODBC database on the same level as the SqLite ones that are on the device. If anyone can help I would love a hand.[/quote]

            you will need to provide bridge in C++

            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