tags:

views:

219

answers:

3

I'm creating some events in a base object (class) in PowerBuilder, and the descendent's of this base datawindow need to know what the primary key of that table (or row) is. How would you determine the primary key in code?

+1  A: 

There doesn't appear to be a single property that you can grab via dot notation or the describe function that isolates the primary key, at least I didn't see one. I could be totally wrong here and there's a better way to do it.

But I think if you're trying to do this in Powerscript, you'll have to scan the columns in the datawindow and check the "columnname.key" property to determine the columns in the key.

I expect this is also dependent on you having defined the primary key columns in the datawindow update properties; typically these aren't defined by the developer for read-only datawindows.

If someone has a better way, please post.

Bernard Dy
A: 

What is there about your objects or code which would require you to know what a table's primary key is?? I have been using Powerbuilder since version 2.0 and I can't ever recall a situation where I would need to know.

psant
+1  A: 

You can iterate through the Column list of the datawindow and check the Key property using describe or dot notation:

<DW Control Name>.Describe("<Columnname>.Key")
or
<DW Control Name>.Object.<Columnname>.Key

This lets you know whether the column is included in the highlighted list you see in the datawindow painter under the menu item Rows->Update Properties->Unique Key Columns(s):

Here are the docs on that property:

http://infocenter.sybase.com/help/topic/com.sybase.dc37783%5F1150/html/dwref/CAIBHFGF.htm

Dougman