Connection Information

To perform the requested action, WordPress needs to access your web server. Please enter your FTP credentials to proceed. If you do not remember your credentials, you should contact your web host.

Connection Type

Technique #4: eliminating recursive embedded SQLs – PB Docs 2022 – PowerBuilder Library

Technique #4: eliminating recursive embedded SQLs – PB Docs 2022

Technique #4: eliminating recursive embedded SQLs

It is actually quite common to find embedded SQL in a loop,
especially Select and Insert statements. As explained previously,
server calls that are recursive in nature are quite dangerous,
potentially generating tremendous number of server calls. If your
application requires loops or recursive functions, it would be best to
replace any code resulting in server calls with code that does
not.

For this technique, we will assume we have Select and Insert SQL
statements in a loop. The general idea is to first create a
DataWindow/DataStore using the SQL. Then replace the SQL statements
contained in the loop with PowerScript modifying the
DataWindow/DataStore, which does not result in server calls. If the
SQL statement contained in the loop is an Insert statement, we would
want to replace that with PowerScript that would insert data into the
DataWindow/DataStore. Once all the data has been inserted, then in one
shot we would update the DataWindow/DataStore to the database (outside
the loop), resulting in only one server call. If the SQL statement
contained in the loop is a Select statement, we would retrieve data
into a DataWindow/DataStore before executing the loop, and then write
PowerScript in the loop to select the desired data from the
DataWindow/DataStore.

The following is a code example that increases the price of a
specific order by 20%, where embedded SQL is used to update the change
row-by-row (hence the loop), and then save those changes to the
database:

Now we will replace the embedded SQL with a DataWindow.
Specifically, we will cache the data in a DataWindow and update the
database with a single DataWindow Update, resulting in just one server
call:

With this technique we have just eliminated server calls from
inside the loop, reduced the number of server calls to just one, and
created a data caching mechanism at the client-side that can be used
to feed data to other controls of the PowerBuilder client.


Document get from Powerbuilder help
Thank you for watching.
Was this article helpful?
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x