Results 1 to 4 of 4

Thread: Need ideas on how to store data in SQL-Database

  1. #1
    Join Date
    Oct 2010
    Posts
    91
    Thanks
    38

    Default Need ideas on how to store data in SQL-Database

    Hello!

    I need to store and manage some data into an SQLite-Database:

    - Customers
    - Articles
    - Invoices

    So far I created two QSqlTableModels for Customers and Articles as they are straight forward. I thought of a QSqlRelationalTableModel for the invoices to share the customers and the articles.
    But I am not really sure how to store the invoices and their children, the invoice entries (position, quantity, article name, price,...)

    Is it common in this case to create a new table for each invoice, and just fill it with the entries? This looks a bit like overkill to me, but would also be straight forward. Well, I have no idea how else this could be accomplished using a database.
    Can SQL tables have child-tables, like e.g. QStandardItems can?

    Kind regards,
    HomeR

  2. #2
    Join Date
    Nov 2010
    Posts
    97
    Thanks
    6
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Need ideas on how to store data in SQL-Database

    Quote Originally Posted by homerun4711 View Post
    Hello!

    I need to store and manage some data into an SQLite-Database:

    - Customers
    - Articles
    - Invoices

    So far I created two QSqlTableModels for Customers and Articles as they are straight forward. I thought of a QSqlRelationalTableModel for the invoices to share the customers and the articles.
    But I am not really sure how to store the invoices and their children, the invoice entries (position, quantity, article name, price,...)

    Is it common in this case to create a new table for each invoice, and just fill it with the entries? This looks a bit like overkill to me, but would also be straight forward. Well, I have no idea how else this could be accomplished using a database.
    Can SQL tables have child-tables, like e.g. QStandardItems can?

    Kind regards,
    HomeR
    No, don't do that. It's hard to say exactly what you need without knowing your full problem, including all the data you must store, but the usual way of solving problems like this, where you have one thing containing 0...* "line" entries, is to have at least two tables. Something like so:

    Customers
    id | name | ....etc....

    Articles
    id | ...?

    Invoices
    id | cust_id | single items...

    Invoice line
    invoice_id | line items...

    You then use a JOIN during your SELECT queries to merge the two tables:

    SELECT * from Invoices,Invoice_Line where Invoices.id = Invoice_Line.invoice_id;

    Or something like that...forget the exact syntax.
    This rude guy who doesn't want you to answer his questions.

    Note: An "expert" here is just someone that's posted a lot.

    "The fact of where you do the encapsulation is meaningless." - Qt Certified Developer and forum moderator

  3. The following user says thank you to nroberts for this useful post:

    homerun4711 (5th January 2011)

  4. #3
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Need ideas on how to store data in SQL-Database

    Try to search for some info on "Database normalization".

  5. The following user says thank you to stampede for this useful post:

    homerun4711 (5th January 2011)

  6. #4
    Join Date
    Oct 2010
    Posts
    91
    Thanks
    38

    Default Re: Need ideas on how to store data in SQL-Database

    Quote Originally Posted by stampede View Post
    Try to search for some info on "Database normalization".
    Very good hint into the right direction. Thanks.

    You then use a JOIN during your SELECT queries to merge the two tables:
    SELECT * from Invoices,Invoice_Line where Invoices.id = Invoice_Line.invoice_id;
    Jup, as far as I read by know, this is exactly what database normalization is about. I will solve it that way.

    Thanks for the good answers!

Similar Threads

  1. Replies: 1
    Last Post: 14th September 2009, 08:48
  2. Replies: 2
    Last Post: 14th September 2009, 08:38
  3. Replies: 2
    Last Post: 14th September 2009, 08:31
  4. Replies: 5
    Last Post: 8th April 2008, 23:10
  5. Is it possible to store pointers in a database ?
    By probine in forum General Programming
    Replies: 8
    Last Post: 5th April 2006, 21:28

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.