Results 1 to 2 of 2

Thread: Fetch default values from MySQL?

  1. #1
    Join Date
    Dec 2010
    Posts
    3
    Qt products
    Qt4

    Question Fetch default values from MySQL?

    Hello guys...

    One question of faith... :P

    I wrote an application that uses QSqlTableModel to access MySQL, add, insert, delete, update records in several tables etc etc etc...

    How do I get the default values for each table after I use the insertRow() to insert new records
    AS THEY ARE specified in MySQL...

    In other words:
    I need to read those values from MySQL, NOT to set them programmatically
    within Qt (i.e setData)....

    Does this functionality even exist???

    Thanks
    Aris

  2. #2
    Join Date
    Dec 2010
    Posts
    3
    Qt products
    Qt4

    Default Re: Fetch default values from MySQL?

    ok.. so query the db for default values...

    Qt Code:
    1. desc <table name>;
    To copy to clipboard, switch view to plain text mode 

    should also work then..
    THANKS!


    Added after 25 minutes:


    SOLUTION :


    Qt Code:
    1. QSqlQuery query("desc "+TableName);
    2. int i = 0;
    3. while (query.next()) {
    4. if(i)
    5. {
    6. QString val = query.value(4).toString();
    7. if( val!= "")
    8. {
    9. myDataModel->setData(DataModel->index(DataModel->rowCount()-1 , i ) , val , Qt::EditRole);
    10. }
    11. }
    12. i++;
    13. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by arimaniac; 1st February 2011 at 20:36.

Similar Threads

  1. Default values in QXmlSchemaValidator
    By mortalisk in forum Qt Programming
    Replies: 0
    Last Post: 3rd September 2010, 16:11
  2. How to QTableWidget default values on insertion?
    By RawArkanis in forum Qt Programming
    Replies: 1
    Last Post: 20th April 2010, 07:02
  3. Replies: 0
    Last Post: 9th March 2010, 13:02
  4. Replies: 4
    Last Post: 3rd May 2009, 18:32
  5. C++ and default values for functions
    By guestgulkan in forum General Programming
    Replies: 4
    Last Post: 2nd January 2007, 22:53

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.