Results 1 to 3 of 3

Thread: Get primary and foreign keys from tables

  1. #1
    Join Date
    Apr 2008
    Posts
    196
    Thanked 8 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    1

    Default Get primary and foreign keys from tables

    Hey @all,

    did anybody know a way to get the primary and foreign keys from a table?

    so when I have a table 'A'
    Qt Code:
    1. id integer primary key
    2. cid integer foreign key (foreign key for table 'B' column 'id')
    To copy to clipboard, switch view to plain text mode 
    and table 'B'
    Qt Code:
    1. id integer primary key
    To copy to clipboard, switch view to plain text mode 

    I want to know that in table 'A' a primary key 'id' exists and there is a foreign key 'cid' which is in table 'B' defined.

    Regards

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Get primary and foreign keys from tables

    You can use QSqlTableModel::primaryKey() to get the primary key.
    Foreign key detection is, afaic, not supported by Qt and has to be done in a database-dependant manner.

    HTH

  3. #3
    Join Date
    Apr 2008
    Posts
    196
    Thanked 8 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    1

    Default Re: Get primary and foreign keys from tables

    Ok, thanks

    I had thought there are Qt ways to do this for all available Databases.

    Regards

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.