PowerBuilder ‘Gotcha’ – Datawindow.Create function

Posted on Tuesday, July 13th, 2010 at 8:20 pm in

I’m working in a custom report application and a tester who is auditing the changes is getting an syntax error when she tries to run her report. The report generator takes the list of columns chosen by the user and builds a SQL statement which is then fed through the SyntaxFromSQL function to generate the string from which the report datawindow is generated via the Create function. The error is being generated by the Create and takes the form of ‘Syntax error, line 25, column 174).

However, the source code generated from the SyntaxFromSQL is being appended to to create groups and other nice things and this is where the actual problem arose. Example code is:

ls_group_syntax += " text(band=foreground alignment='0' text='" + ls_rpt_title + "' border='0'...
ls_group_syntax += " text(band=foreground alignment='0' text='" + string(today(), 'mm/dd/yyyy') +...
ls_group_syntax += " compute(band=footer alignment='1' expression=~'"Page " + page() + " of "...

Notice the variable ls_rpt_title. As it turns out the user was naming the report Ann’s Report which messed up the string making up the group syntax. One change would be to switch single and double quotes in the building of the string. Another change is to put in your documentation for the users to not use quotes in report titles. A third option would be to parse through the user input and escape the single quote.

 

Updated March 2010

You might also be interested in

Top