Object Programmer
Object Programmer

Reputation: 1

column table in datawindow in powerbuilder

  1. How to access column name and underlying table name of that column in a datawindow in powerbuilder. I could get the column name by having an instance variable and assigning dwo.name to this instance variable in itemfocuschanged event. But how to get the table name of this column.

  2. If I have multiple datawindow controls in a window how to get the name of the selected datawindow control.

Upvotes: 0

Views: 2160

Answers (2)

Marc Vanhoomissen
Marc Vanhoomissen

Reputation: 395

Question 1: Use dw_a.Describe("<yourcolumn>.dbName") This will give you the database name of the colum, in the form tablename.columnname. You can then parse it.

Question 1: Not sure what you mean. If you want to know which one of the datawindows has received focus lastly, you could define a window instance variable (type datawindow) and use the GetFocus event of the various datawindows by putting :

idw_datawindowfocue = this

I wonder though why you need this. Could you explain the rationale?

Upvotes: 0

Shenn Sellers
Shenn Sellers

Reputation: 172

First get the SQL Statement for the DW by using the code below...

ls_sql = this.dw_report.Object.DataWindow.Table.SQLSelect

OR

ls_sql = dw_report.Describe("DataWindow.Table.Select")

Then I use this custom function to return the Table name...

ls_table = f_get_table_name(ls_sql)

Code of the "f_get_table_name()" function...

//Obtains the main Table name from the passed SQL string

long ll_pos1
long ll_pos2
string ls_table = ""

ll_pos1 = PosA(Upper(as_sql), "FROM")
ll_pos1 = PosA(as_sql, '"', ll_pos1 + 1)
ll_pos2 = PosA(as_sql, '~~', ll_pos1 + 1)
ls_table = MidA(as_sql, ll_pos1 + 1, ll_pos2 - ll_pos1 - 1)

if (ls_table = "" OR isNull(ls_table)) then
    ll_pos1 = PosA(Upper(as_sql), "SELECT")
    ll_pos1 = PosA(as_sql, ' ', ll_pos1 + 1)
    ll_pos2 = PosA(as_sql, '.', ll_pos1 + 1)
    ls_table = MidA(as_sql, ll_pos1 + 1, ll_pos2 - ll_pos1 - 1)
end if

if (ls_table = "" OR isNull(ls_table)) then
    ll_pos1 = PosA(Upper(as_sql), "WHERE")
    ll_pos1 = PosA(as_sql, ' ', ll_pos1 + 1)
    ll_pos2 = PosA(as_sql, '.', ll_pos1 + 1)
    ls_table = MidA(as_sql, ll_pos1 + 1, ll_pos2 - ll_pos1 - 1)
end if

if (ls_table = "" OR isNull(ls_table)) then
    ll_pos1 = PosA(Upper(as_sql), "FROM")
    ll_pos1 = PosA(as_sql, ' ', ll_pos1 + 1)
    ll_pos2 = PosA(as_sql, ' ', ll_pos1 + 1)
    ls_table = MidA(as_sql, ll_pos1 + 1, ll_pos2 - ll_pos1 - 1)
end if

return Trim(ls_table)

Upvotes: 1

Related Questions