Book a Demo

Author Topic: Get PK/FK via scripting  (Read 3675 times)

Christian Ehrlicher

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Get PK/FK via scripting
« on: May 21, 2015, 09:21:42 pm »
Hi,

I want to export my db schema to a custom xml file. Exporting the table attributes works fine. The only thing I can't get to work is to retrieve the informations about my primary/foreign keys. I tried to get them through Connector -> TaggedValues but it's always empty.

So my question - what's the best way to get the PK/FK informations via scripting?

/edit: Found out that PK and index informations are available through Element -> Methods -> Parameter but for FK I need the target table and column name ...
« Last Edit: May 21, 2015, 09:40:17 pm by chehrlic »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Get PK/FK via scripting
« Reply #1 on: May 22, 2015, 12:29:42 am »
Look into t_connector.styleex. You'll find something like
Code: [Select]
FKINFO=SRC=t_metrictypest_objectmetrics:DST=PrimaryKey:
q.
« Last Edit: May 22, 2015, 12:30:03 am by qwerty »

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: Get PK/FK via scripting
« Reply #2 on: May 22, 2015, 11:37:10 am »
Look in Connector.StyleEx to get the name of the foreign key operation.
E.g. FKINFO=SRC=[FKOpName]

Get the element at the opposite end of the FK Connector to find the name of the other related Table.  E.g.
parentTable = Repository.GetElementByID( fkConnector.SupplierID )

To get the name of the columns, you should be able to check the parameters on the FK operation in the Methods collection (operation should have the same name as found in StyleEx).

Christian Ehrlicher

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Get PK/FK via scripting
« Reply #3 on: May 22, 2015, 03:46:34 pm »
Thanks, this helped. After the first reply I took a look into t_connection and found SourceRole / DestRole which also contains the two methods needed - this looks easier to me (although I need some sql, but this is provided by EAScriptLib.JScript-Database) instead parsing the styleex string  :)