1. Berka Frenfert
  2. PowerBuilder
  3. Monday, 14 January 2019

A PowerBuilder datawindow has some parameters and those parameters are obviously matched with columns in query of the datawindow. The query is too complex. In my script i get the query syntax in a string variable. Also i get parameters list defined in the datawindow. Now i want to get the list of columns from the query syntax where columns are being compared with retrieval arguments. I do not need those columns where column is not compared with retrieval argument.

for example query string has in its text "product_price >= :prod_price AND SupplierID is null AND store_id = :storeID"

I want to get all the columns names excluding supplierID because supplierID is not compared with any retrieval argument. The Query is too complex with many case statements and operators.

Is there any easy way to get columns list from the query string without involving complex string parsing script?

Sivaprakash BKR Accepted Answer Pending Moderation
0
Votes
Undo

Won't creating a temporary datastore, using SyntaxFrom SQL, for this purpose solve this issue ?

 
ls_present_str = "style(type=tabular)"
ls_syntax_str  = SQLCA.SyntaxFromSQL(as_query, ls_present_str, as_msg)
If ls_syntax_str = "" Then
 Return -1 
End If
ds_store.Create(ls_syntax_str, as_msg)
ds_store.SetTransObject(Sqlca)
ds_store.Retrieve()

Retrieving this datastore will give you all resultant columns.
 
Happiness Always
BKR Sivaprakash
 
Comment
Thanks for the effort to help. Datastore is no help anyway. If the query is in a string variable then next thing is the extraction of required columns from it. That is all i need to do.
  1. Berka Frenfert
  2. Wednesday, 29 May 2019
There are no comments made yet.
  1. Saturday, 19 January 2019
  2. PowerBuilder
  3. # 1
Miguel Leeuwe Accepted Answer Pending Moderation
0
Votes
Undo

Not sure if this would help you:

What if you could make your extraction of the columnames with the parameters easier by introducing them as a comment in the dw's SQL?

Like 

/*parmfields=product_price,storeID*/
select product_price, supplierID, store_id
from table
where product_price >= :prod_price AND
SupplierID is null AND
store_id = :storeID"

 

Of course this would mean you have to manually adapt all of your datawindows to include that comment, but maybe might be of any use to you?

regards

 

Comment
Thank you Miguel but you are right there will be need to add comments in every DataWindow object and there are thousands which makes it impossible for me.
  1. Berka Frenfert
  2. Wednesday, 29 May 2019
There are no comments made yet.
  1. Friday, 18 January 2019
  2. PowerBuilder
  3. # 2
Olan Knight Accepted Answer Pending Moderation
-1
Votes
Undo

Theeasist way to get this in the IDE is to EDIT SOURCE on the DW.

Scroll down until you get to the "RETRIEVE" statement.

Copy that block into the text editor of your choice and look for what you want.

 

If you need to do this in RUNTIME, the you need to capture the SQL in the SQLPRIEVIEW event. Once you have the SQL in a variable, then begins the fun process of finding what you need in that string!

 

Good Luck -

Olan

Comment
There is no need to edit source because GetSQLSyntax() function returns the query.

And the fun part of the solution you suggested is in fact the real question. And i know there is no easy way to do that. I am already having fun coding in PowerBuilder. Thanks but no thanks.
  1. Berka Frenfert
  2. Wednesday, 16 January 2019
Hi Berka;

FWIW: The GetSQLSyntax and SQLPreview event argument are functionally the same. The only benefit of the SQLPreview is that can be more accurate, as its at the point where the real SQL is being generated to be sent over to the DBMS. If your App has performed Modify ( ) commands that may alter the SQL generation, the SQLPreview event will show them. Depending on when you use the GetSQLSelect (old PB feature before the SQLPreview), the SQL may not be as accurate.

Food for thought .... Just my $0.02.

Regards ... Chris
  1. Chris Pollach
  2. Wednesday, 16 January 2019
Thank you Chirs. That is good point.
  1. Berka Frenfert
  2. Wednesday, 29 May 2019
There are no comments made yet.
  1. Monday, 14 January 2019
  2. PowerBuilder
  3. # 3
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies. Learn More