Results 1 to 4 of 4

Thread: Insert, update database record using OOP

  1. #1
    Join Date
    Sep 2009
    Location
    Kranj, Slovenia
    Posts
    25
    Thanks
    10
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Question Insert, update database record using OOP

    Hi!

    I am learning object oriented programming and would like a few pointers from the wiser. I would like to make changes to make changes to the table in the database (insert, update, delete record). I am wondering if that is possible to achieve via a class? To have class student and inside defined functions selectStudent, insertStudent and updateStudent(id). The benefit would obviously be to have only one place to look up for the changes in the table structure and not the whole code.

    I have seen it done in some examples, but only the result => John.setAge = 23, John.updateStudent(2).

    Can you give me some pointers, examples, tutorials, ...? Thank you!

  2. #2
    Join Date
    Nov 2014
    Posts
    32
    Thanked 1 Time in 1 Post
    Qt products
    Platforms
    Windows

    Default Re: Insert, update database record using OOP

    You can read the nest article http://www.tonymarston.net/php-mysql...seobjects.html and you'll good information about your question.

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

    omci (28th January 2015)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Insert, update database record using OOP

    Quote Originally Posted by omci View Post
    Hi!

    I am learning object oriented programming and would like a few pointers from the wiser. I would like to make changes to make changes to the table in the database (insert, update, delete record). I am wondering if that is possible to achieve via a class? To have class student and inside defined functions selectStudent, insertStudent and updateStudent(id). The benefit would obviously be to have only one place to look up for the changes in the table structure and not the whole code.

    I have seen it done in some examples, but only the result => John.setAge = 23, John.updateStudent(2).

    Can you give me some pointers, examples, tutorials, ...? Thank you!
    There is a number of design patterns you could use. For example the Strategy pattern or the Visitor pattern. Both of them let you separate the algorithm from the data. That is you implement "insert", "update" and other algorithms not in the Student class but rather in a separate class (or rather set of classes) that accept your data object (i.e. Student instance) as an argument. However whether any of those approaches fit your use-case, it depends on that use-case.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    omci (28th January 2015)

  6. #4
    Join Date
    Sep 2009
    Location
    Kranj, Slovenia
    Posts
    25
    Thanks
    10
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Insert, update database record using OOP

    Thank you both, just the information I was looking for but could not find it on my own!

Similar Threads

  1. Update View when deteting record the Model
    By aguleo in forum Newbie
    Replies: 5
    Last Post: 5th December 2013, 17:41
  2. Qtablewidget insert Record from Qtableview
    By advseo32 in forum Qt Programming
    Replies: 1
    Last Post: 22nd August 2013, 11:26
  3. Replies: 4
    Last Post: 10th May 2011, 13:19
  4. Fast insert record into MySql
    By weixj2003ld in forum Qt Programming
    Replies: 3
    Last Post: 15th July 2010, 10:08
  5. Replies: 2
    Last Post: 13th April 2010, 17:50

Tags for this Thread

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.