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. How to use ODB with QT
QtWS25 Last Chance

How to use ODB with QT

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 275 Views
  • 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.
  • A Offline
    A Offline
    ATE-ENGE
    wrote on last edited by
    #1

    Hello all, as a bit of background, I'm a mechanical engineer trying to become a software developer and I'm running into a bit of an issue setting up tools for a database manager.

    I know/understand that ODB is a great tool for managing databases (in my case sqlite) and looking at their downloads page:
    https://www.codesynthesis.com/products/odb/download.xhtml
    I believe I need to get the following zip files for my application:

    • odb-2.5.0-x86_64-windows10.
    • libodb-2.5.0-x86_64-windows10-msvc17.10
    • libodb-sqlite-2.5.0-x86_64-windows10-msvc17.10
    • libodb-qt-2.5.0-x86_64-windows10-msvc17.10

    Now that I have the zip files, what do I do next? I found a guide online here:
    https://codesynthesis.com/products/odb/doc/install-windows.xhtml
    That discusses how to install ODB for use with Visual Studio. However I do not have VS on this computer.

    Could someone walk me through the next steps? Any help would be greatly appreciated.

    Pl45m4P 1 Reply Last reply
    0
    • A ATE-ENGE

      Hello all, as a bit of background, I'm a mechanical engineer trying to become a software developer and I'm running into a bit of an issue setting up tools for a database manager.

      I know/understand that ODB is a great tool for managing databases (in my case sqlite) and looking at their downloads page:
      https://www.codesynthesis.com/products/odb/download.xhtml
      I believe I need to get the following zip files for my application:

      • odb-2.5.0-x86_64-windows10.
      • libodb-2.5.0-x86_64-windows10-msvc17.10
      • libodb-sqlite-2.5.0-x86_64-windows10-msvc17.10
      • libodb-qt-2.5.0-x86_64-windows10-msvc17.10

      Now that I have the zip files, what do I do next? I found a guide online here:
      https://codesynthesis.com/products/odb/doc/install-windows.xhtml
      That discusses how to install ODB for use with Visual Studio. However I do not have VS on this computer.

      Could someone walk me through the next steps? Any help would be greatly appreciated.

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @ATE-ENGE

      Hi and welcome :)

      Regarding your topic title:
      Qt provides drivers to connect to various SQL databases, including ODB via ODB Connector

      • https://doc.qt.io/qt-6/sql-driver.html

      That discusses how to install ODB for use with Visual Studio. However I do not have VS on this computer.

      If you want to use these libraries in your Qt program you need Microsoft Visual Compiler v17 anyway (comes with Microsoft Visual Studio 22) since they were pre-built for/with msvc17 as the filenames tell.

      When you already use QtCreator and a Qt Framework installation with MinGW, use the MinGW libraries.

      But what is your ultimate goal?
      Do you want to connect your Qt app to a SQL Database? Do you want to build your own driver?
      I'm not 100% sure whether you need to build all this yourself to use Qt SQL, for example.


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      0
      • A Offline
        A Offline
        ATE-ENGE
        wrote on last edited by
        #3

        Thanks!

        The ultimate objective is to use an ORM to connect to what is now a sqlite database. However, it is very likely that the database will change from sqlite to something else.

        As such I would like an abstraction layer that minimizes the rework required when I need to make the switch. I believe I need an ORM like ODB to do this, but if not, I'm happy to hear that.

        jsulmJ 1 Reply Last reply
        0
        • A ATE-ENGE

          Thanks!

          The ultimate objective is to use an ORM to connect to what is now a sqlite database. However, it is very likely that the database will change from sqlite to something else.

          As such I would like an abstraction layer that minimizes the rework required when I need to make the switch. I believe I need an ORM like ODB to do this, but if not, I'm happy to hear that.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @ATE-ENGE Qt already provides an abstraction layer, see https://doc.qt.io/qt-6/qtsql-index.html
          When switching to another database you just need to change https://doc.qt.io/qt-6/qsqldatabase.html#addDatabase call.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • A Offline
            A Offline
            ATE-ENGE
            wrote on last edited by
            #5

            Ok, the program I inherited uses the QSqlDatabase::addDatabase to connect. However when interacting with the database, code like the following is used:

            QList<QString> Ps;
                QString selectQuery = QString(
                    "SELECT DISTINCT column.name "
                    "FROM table "
                    "WHERE col = :value"
                    );
                QSqlQuery query;
                query.prepare(selectQuery);
                query.bindValue(":value", value);
                if (query.exec()) {
                    while (query.next()) {
                        QString P;
                        P = query.value("Properties.name").toString();
                        Ps.append(P);
                    }
                }
            

            My understanding is that ODB and other ORMs would allow me to instead write something more like:

            using table_query = ODBquery<table>;
            for (QString& P: db.query<P> (table_query::value ="value);
            
            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