Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CFLOCK & unique ID update

Status
Not open for further replies.

LongHorn

Programmer
Jun 20, 2001
30
US
I want to make sure that the key_value is unique for each user who accesses this application. Do I put a CFLOCK tag around the Select Query and another CFLock tag around the Update SQL statement? But I don't know what the scope should be? Application, server or Session?


<CFLOCK TIMEOUT=&quot;30&quot;
THROWONTIMEOUT=&quot;YES&quot;
NAME=&quot;#Session.Session_ID#> What should be the name?
TYPe=&quot;Exclusive&quot;>

<CFQUERY NAME=&quot;GETPERMIT&quot; DATASOURCE=&quot;#DSNAME#&quot;>

SELECT key_value
FROM gen_key
WHERE table_name = 'NSR_PERMIT'
AND field_name = 'PERMIT_ID'
</CFQUERY>

<CFSET session.permit_id= GetPermit.key_value + 1>

</CFLOCK>

<CFQUERY NAME=&quot;updategenkey&quot; DATASOURCE=&quot;#DSNAME#&quot;>

UPDATE gen_key
SET key_value = #session.permit_id#
WHERE table_name = 'NSR_PERMIT'
AND field_name = 'PERMIT_ID'

</CFQUERY>

Please help.

Longhorn
 
Session.sessionID is built in variable that is unique to each session. It is combination of the application name, the CFID, and CFTOKEN variables. It appears as AppName_50_25239742 (where 50 is the CFID and 25239742 is the CFTOKEN). You can use this variable in conjunction with CFLOCK to secure read/write access to your session variables.
All built in variables are stored in the server's RAM, and are tied to a specific CFID and CFTOKEN.
ColdFusion have following built-in variables:
-session.CFID,
-session.CFTOKEN, and
-session.URLToken


CFLOCK Usage

ColdFusion Server is a multi-threaded web application server that can process multiple page requests at any given time. Use cflock to guarantee that multiple concurrently executing requests do not manipulate shared data structures, files, or CFXs in an inconsistent manner. Note the following:

Using cflock around CFML constructs that modify shared data ensures that the modifications occur one after the other and not all at the same time.
Using cflock around file manipulation constructs can guarantee that file updates do not fail due to files being open for writing by other applications or ColdFusion tags.
Using cflock around CFX invocations can guarantee that CFXs that are not implemented in a thread-safe manner can be safely invoked by ColdFusion. This usually only applies to CFXs developed in C++ using the CFAPI. Any C++ CFX that maintains and manipulates shared (global) data structures will have to be made thread-safe to safely work with ColdFusion. However, writing thread-safe C++ CFXs requires advanced knowledge. A CFML custom tag wrapper can be used around the CFX to make its invocation thread-safe.

CFSCOPE Scope

Whenever you display, set, or update variables, in one of the shared scopes, use the SCOPE attribute to identify the scope as Server, Application or Session.

Within the ColdFusion Administrator, the Locking page, under the Server section, allows you to set different characteristics of the locking schema according to scope.The following table shows which features are available for Server, Application, and Session scope.


Features Server Application Session
No automatic checking or locking Yes Yes Yes
Full checking Yes Yes Yes
Automatic read locking Yes Yes Yes
Single Threaded Sessions Yes


Each feature that you select has tradeoffs.

No automatic checking or locking. If you select this button, no reads or writes are locked or checked for correct protection. You should select this only after you have run with full checking and know that there are no errors to handle and that all locking is handled programmatically. Selecting this button provides the fastest performance.
Full checking. If you select this button, all unlocked accesses will be detected. You should select this when you are in debug mode. Selecting this button slows performance.
Automatic read locking. If you select this button, all reads are locked and unlocked writes cause an error. Selecting this button also slows down performance considerably.
Single-threaded sessions: If you select this button, the whole request has to finish before another request for the same session is processed. Selecting this button may have an effect on performance depending on the request pattern. For example, the total response time may increase if an application has multiple frames that can be refreshed at once, thus causing multiple requests to have to queue up and wait to be processed. Sylvano
dsylvano@hotmail.com

&quot;every and each day when I learn something new is a small victory...&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top