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. Design patern for correct use of database and Qt views link
QtWS25 Last Chance

Design patern for correct use of database and Qt views link

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 613 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.
  • jerome_isAviableJ Offline
    jerome_isAviableJ Offline
    jerome_isAviable
    wrote on last edited by
    #1

    Ok, i have a QDialog box who serve to create a new "project" of the application. this project is référenced inisde a table named "projects". Then, from this dailog box, i have some view customized linked to some other tables.
    a project can contain many binders, and can be link to some other location and/or structure objects.
    Also, binders of the project contain many files (documentations, sheets, client files, etc... for exemple).
    So, a view is linked to the table "binders", each binder inside this table has to be lonk to table "binders_linker", this table link each binder to a project.. or a structure... or a location... etc...
    so, if i customize my model for the view of bonders tree... and also for files tree... and all so...
    what i can do for use database transactions ?
    because... i can not have id of a new row of binder before commit the insertion... same for the project new id row... so i can not have all necessary data for input inside the new binders_linker row.
    so... is ther any design patern to use for do that or the best way coudl be to use variable data form for embed trees views ?

    1 Reply Last reply
    0
    • jerome_isAviableJ Offline
      jerome_isAviableJ Offline
      jerome_isAviable
      wrote on last edited by
      #2

      ok, my question was not clear, i try to ask clearly:

      from database:

      • table name: "binder" fields name and type: "id / int and primary key auto incremented", "name / varchar", "comment / varchar", "id_tree / int", "id_tree_parent / int" * table name: "binder_linker"
        fields name and type:
        "id / int primary key auto incremented"
        "id_binder / int and foreign key"
        "id_project / int and foreign key"
        "id_structure / int and foreign key"
        "id_location / int and foreign key"
        * table name: "projects"
        fields name and type:
        "id / int primary key auto incremented"
        "name / varchar"
        "comment / varchar"
        "date_create / timestamp"
        "date_close /timestamp"
        * table name: "files"
        "id / int primary key auto increment"
        "name / varchar"
        "directory / varchar"
        * table name: "files_linker"
        "id / int primary key auto increment"
        "id_file / int foreign_key"
        "id_binder /int foreign key"

      the dialog box for the "new project":

      it serve to create a new project after give all information about name, comment, binder to link with, and content of files inside each binder.
      so for the view of binders, i have a treeview with custom model frome QAbstractItemModel and promoted treeview class and "binder" class (the items element are binders...)
      for the files, i have also a treeview with promoted treeview class and QAbstractItemModel
      

      so, the binder tree view is linked to the files treeview...

      the problem:

      at this time, in my code, i add a binder inside from the view by right click inside and from the popup menu, i choose to add (if empty or if right click on invalid index) or add a child or delete when from menu popup when right clicked on a valid index...
      when i add a binder, i put datas inside a QMultiHash<int, QHash<int, QVectror<QVariant>>> variable (where first int is id_tree_parent, second int is id_tree and then QVaraiant are name and comment and eventually the id from the binder table...
      so, if i delete or update a data, i work on this variable to remove, update, re-arrange id_tree numbers and own parent id_tree_parent (who are the hirearchy organisation). It is heavy...
      I would like to try to use transactions from SQL (open transaction and at the end, commit) for not use the data form variable... BUT:

      the question:

      is it possible to do it by the fact that there is many links (foreign keys) to pass to relationnal tables ?
      an other form of this question could be:
      when i do a "INSERT INTO binder ..... RETURNING id ;" does it return me the id (because sure... i need it for add a new binders_linker row to be able to link binders and project...) before i commit the transaction ?

      If this works, so i not need to use variuable to form all datas before manipulate the database.

      OR... which could be the best way to do ?

      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