The progress and interruption are displayed during the update process of datawindow.

Source: Internet
Author: User

Recently, csdn has frequently encountered issues similar to the issue of service interruption:

Http://topic.csdn.net/u/20090805/10/c9270a8b-2ac1-4beb-b59a-7d89dc6c4e07.html? 58492

Http://topic.csdn.net/u/20090806/03/5227d73b-4300-4c20-b353-5bbba45a50a6.html? 8869

 

So I decided to start studying this problem.

At first, I thought about using multi-threaded methods, but it was hard to achieve the desired effect no matter how I wrote them. So I started to start with the datawindow and datastore events, it can be done on the sqlpreview event of datawindow.

Commit is the final commit, and the program cannot interrupt this operation. However, we basically write an update first and then commit. Therefore, it seems slow to submit the database. In fact, it is slow to execute the UPDATE function, so we can interrupt the update to prevent commit.

View the Pb help, which clearly says:

Description

Occurs immediately before a SQL statement is submitted to the DBMS. Methods that trigger DBMS activity are retrieve, update, and reselectrow.

Return Value

Set the return code to affect the outcome of the event:

0 continue processing
1 stop processing
2 skip this request and execute the next request

For information on setting the return code in a particle environment, see "about return values for datawindow events ".

 

As a result, we can know that the row-by-row commit process of datawindow can interrupt yield on this event, and the CPU time can be allocated to execute other code.

The following is a result of the study:

Example 1: How to terminate the update operation

1. sqlpreview event:

Yield ()
If ib_stopcommit then return 1 // ib_stopcommit instance variable

2. Add a button to write
Ib_stopcommit = ture

3. Add the dberror event
Return 1

Example 2: The progress prompt and GIF animation running are displayed during database submission.

1. sqlpreview event:

W_wait.wf_setcurrentposition (ROW) // sets the scroll bar progress of the wait window.
Yield ()
If ib_stopcommit then return 1 // stop

2. submit button:

Wf_openwait () opens the progress Prompt window
Wf_update () datawindow submit
Wf_closewait () Close progress Prompt window

Wf_openwait () function:

Open (w_wait)
W_wait.wf_setmaxposition (dw_1.rowcount ())

 

Wf_update () function:

If dw_1.update () = 1 then
If ib_stopcommit then
Return 1
End if
Commit;
MessageBox ('System prompt ', 'saved successfully ')
Else
If ib_stopcommit then
Return 1
End if
Rollback;
MessageBox ('System prompt ', 'Save failed ')
End if

 

Wf_closewait () function:

Close (w_wait)

 

 

Code attachment:

Http://download.csdn.net/source/1566944

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.