Cursor and lock methods in database operations in ASP

Source: Internet
Author: User
In general, the following is a typical process of opening a database.
<%
'Cursor type
Const adOpenForwardOnly = 0
Const adOpenKeyset = 1
Const adOpenDynamic = 2
Const adOpenStatic = 3
'Lock type
Const adLockReadOnly = 1
Const adLockPessimistic = 2
Const adLockOptimistic = 3
Const adLockBatchOptimistic = 4
%>
<% Set Conn = Server. CreateObject ('adodb. Connection') %>
<% Set RSMov = Server. CreateObject ('adodb. Recordset') %>
<% Conn. Open 'soc ', '','' %>
<% RSMov. Open sqlMov, Conn, adOpenKeyset, adLockReadOnly %>
Cursors are flexible in use. They are sometimes used to describe a record set and sometimes to describe a pointer to a record in the current record set. Cursors are mainly used to establish a row/column relationship in a relational database. The technical term related to the cursor is also called Bookmark. If the cursor method you select supports Bookmarks. The database provides powerful functions related to the number of records. AdOpenDynamic is not very useful in writing so many cursors above, although it provides the function of displaying all update operations of records in the database in real time, however, not all databases support the cursor method. The no-portability cursor method is of little use to the complicated database. In actual programming, I believe that the adOpenStatic method is the most frequently used. Of course, the disadvantage of this method is that it cannot reflect the changes in the database content in real time. If you want to see the database changed by other users, you can use the adOpenKeyse method (but it can only reflect the changed situation, that is to say, it cannot reflect the changes to the newly added or deleted records .)
In fact, the above content can be found in Microsoft's technical reference materials. The following describes how to use these cursors.
Methods and locking methods should be noted.
1. The first thing to note is that the two methods are used in hybrid mode, that is, you can set both the cursor mode and the lock mode.
Unless you are using an Access database, generally you cannot obtain the expected cursor and lock modes when using them in combination. For example, if you set the cursor to the adOpenStatic mode and set the lock to the adLockOptimistic mode, you will not get the cursor in the adOpenStatic mode.
AdOpenKeyset, that is, if you use ADO, it will return the cursor of adOpenKeyset.
2. Second, the combination of the cursor and the lock will also cause the ADO to return not the desired locking method, ADO will change your locking method
Method. For example, in the default state, the cursor mode is adOpenForwardOnly.
The locking method you use is-1 (that is, let the data source determine the locking method) or adLockReadOnly. Therefore, this hybrid method basically does not support any RecordSet method, that is to say, any method of RecordSet will return False.
(Your recordcount, absoultpage, addnew, delete, update, and so on will return-1,-1 indicates that this attribute is not supported ), however, if you use a combination of adOpenForwardOnly and other locking methods, it supports adding, deleting, and updating.

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.