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. Class to read and save different objects in SQL database!!!
Forum Updated to NodeBB v4.3 + New Features

Class to read and save different objects in SQL database!!!

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 393 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.
  • V Offline
    V Offline
    VincentWesley
    Banned
    wrote on last edited by VincentWesley
    #1

    I am trying to create a class that is capable of saving and reading objects of different type in a SQL database. The goal is to avoid redundancy of methods in each object class ( I could, for simplicity write my sql database methods in each object class that I want to save and read and it would work). The strategy I tried is to inherit my object classes with a class containing static methods. Additionnaly different object type have to be saved in different database.

    As the database class contains static methods, I am obliged to use static member variables in order to save the database name and path. This is the point that is bothering me. Static variables can be initialized just once. Hence, the database name and path cannot be different for different objects.
    https://trackeasy.fun/usps/ https://showbox.tools/ https://speedtest.vet/
    My question is the following: what strategy should I use, if I want to have a single class that is capable of saving and reading different object types in different databases according to the object type.

    Below I provide a minimal example of what I did and that is not the good strategy:

    Pl45m4P jsulmJ 2 Replies Last reply
    0
    • V VincentWesley

      I am trying to create a class that is capable of saving and reading objects of different type in a SQL database. The goal is to avoid redundancy of methods in each object class ( I could, for simplicity write my sql database methods in each object class that I want to save and read and it would work). The strategy I tried is to inherit my object classes with a class containing static methods. Additionnaly different object type have to be saved in different database.

      As the database class contains static methods, I am obliged to use static member variables in order to save the database name and path. This is the point that is bothering me. Static variables can be initialized just once. Hence, the database name and path cannot be different for different objects.
      https://trackeasy.fun/usps/ https://showbox.tools/ https://speedtest.vet/
      My question is the following: what strategy should I use, if I want to have a single class that is capable of saving and reading different object types in different databases according to the object type.

      Below I provide a minimal example of what I did and that is not the good strategy:

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

      @VincentWesley

      This might be helpful
      https://doc.qt.io/qt-5/model-view-programming.html


      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
      • V VincentWesley

        I am trying to create a class that is capable of saving and reading objects of different type in a SQL database. The goal is to avoid redundancy of methods in each object class ( I could, for simplicity write my sql database methods in each object class that I want to save and read and it would work). The strategy I tried is to inherit my object classes with a class containing static methods. Additionnaly different object type have to be saved in different database.

        As the database class contains static methods, I am obliged to use static member variables in order to save the database name and path. This is the point that is bothering me. Static variables can be initialized just once. Hence, the database name and path cannot be different for different objects.
        https://trackeasy.fun/usps/ https://showbox.tools/ https://speedtest.vet/
        My question is the following: what strategy should I use, if I want to have a single class that is capable of saving and reading different object types in different databases according to the object type.

        Below I provide a minimal example of what I did and that is not the good strategy:

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

        @VincentWesley said in Class to read and save different objects in SQL database!!!:

        class containing static methods

        Why static methods?

        What you're describing sounds like ORM. Take a look at existing libs like https://www.qxorm.com/qxorm_en/home.html

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

        1 Reply Last reply
        4

        • Login

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