[allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => BKBK [ip] => webforumsuser@m [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 3 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> Looping over a Query with locking - Coldfusion - Advanced Techniques

Looping over a Query with locking - Coldfusion - Advanced Techniques

Hi, I need to output a query with about 30 rows into an table, and on every row I have to read several values from an Stucture of Arrays. This Struct is an application variable, so I need to lock it for readonly (I'm on CF5 on this box). Would you put locks around the whole output like this: <cflock name="MyName" timeout="3" type="readonly"> <cfoutput qury="MyQuery"> ....... </cfoutput> </cflock> Or would you lock it for every output like this: <cfoutput qury="MyQuery"> <cflock name="MyName" timeout="3" type="readonly"> ....... </cflock> </cfoutput> What is fastest and safest? Thanks in advance, Trygve...

Sponsored Links
  1. #1

    Default Looping over a Query with locking

    Hi,

    I need to output a query with about 30 rows into an table, and on every row I
    have to read several values from an Stucture of Arrays. This Struct is an
    application variable, so I need to lock it for readonly (I'm on CF5 on this
    box).

    Would you put locks around the whole output like this:

    <cflock name="MyName" timeout="3" type="readonly">
    <cfoutput qury="MyQuery">
    .......
    </cfoutput>
    </cflock>

    Or would you lock it for every output like this:

    <cfoutput qury="MyQuery">
    <cflock name="MyName" timeout="3" type="readonly">
    .......
    </cflock>
    </cfoutput>

    What is fastest and safest?

    Thanks in advance, Trygve

    Sponsored Links
    Trygve Guest

  2. #2

    Default Re: Looping over a Query with locking

    Hi,

    thanks,

    does that apply even if the lock is readonly? As I have understood, when you
    use readonly, more than one thread can access the content of the lock, and
    there isn't much of a performance problem.

    The named lock is also locked exclusively some places, but not that often.

    I'm just thinking that it must be more work for the server to set 30 locks in
    a lopp than one while the code executes?

    Trygve Guest

  3. #3

    Default Re: Looping over a Query with locking

    >... What is fastest and safest?
    You could play this trick. Pass the shared-scope variable temporarily
    into Request scope, which you don't need to lock!

    <cflock type="readonly" etc.>
    <cfset Request.myReqVar="#Application.myAppVar#"
    </cflock>
    <cfoutput query="MyQuery">
    <!---In this code you may replace all occurrences of Application.myAppVar by
    Request.myReqVar --->
    </cfoutput>


    BKBK Guest

  4. #4

    Default Re: Looping over a Query with locking

    That is really good advice, but the trouble it's a Structure of arrays, and
    then I have to use StructCopy.

    The structure is filled with 20 000 keys with arrays, an the structcopy takes
    to long.

    I found that accessing a structure key is much, much faster than accessing the
    database, and that's why I want to keep it in memory - with 4 GB ram, I don't
    think it'a big problem, exept for the locking issue:-)


    Trygve Guest

  5. #5

    Default Re: Looping over a Query with locking

    >... but the trouble it's a Structure of arrays, and then I have to use
    StructCopy
    It's no trouble at all. A variable is a variable, be it a structure of an
    array of of
    structurs in the Application scope. Just write the Application variable into
    the
    request scope. Use Duplicate() instead of StructCopy(). Duplicate returns a
    clone
    of the original variable, i.e. a "standalone" copy with no references to the
    original.

    BKBK Guest

  6. #6

    Default Re: Looping over a Query with locking

    Well, the trouble is that making the clone using structCopy takes almost a
    second. That's too much. I guess it's because it's a really big variable with
    20 000 arrays.

    You can actually use StructCopy on structures and get a clone without
    referense to the original as long as the structure do not contain other
    structures or objects. Arrays in structures are copied by value, not by
    reference.

    Trygve Guest

  7. #7

    Default Re: Looping over a Query with locking

    >... making the clone using structCopy
    Duplicate makes the clone
    BKBK Guest

  8. #8

    Default Re: Looping over a Query with locking

    >... You can actually use StructCopy on structures and get a clone without 
    That argument becomes complicated when there is a shared scope. Hence, the
    need for locks which, among other things, ensure referential integrity.

    You are right. The time factor is too demanding. You have to weigh 1 second
    against the slight, but real, chance that a query within a lock or lock within
    a
    query might take forever. This is where it becomes much like a lottery. What
    will
    the CPU do? I'll go for the solution I've given. However, your guess is as good
    as mine. Yeh puts yer money and yeh makes yer choice.


    BKBK Guest

Similar Threads

  1. Locking A Query?
    By JoeD in forum Coldfusion Database Access
    Replies: 4
    Last Post: February 23rd, 05:13 PM
  2. Looping an update query
    By Yannovich in forum Coldfusion - Getting Started
    Replies: 2
    Last Post: September 22nd, 07:51 AM
  3. generating a query by looping through a list
    By bdee2 in forum Macromedia ColdFusion
    Replies: 13
    Last Post: July 21st, 06:35 PM
  4. looping over a query object
    By fu-meng in forum Coldfusion - Advanced Techniques
    Replies: 6
    Last Post: March 24th, 04:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •