Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
RLOCK()
Message
From
28/11/2000 13:06:10
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
28/11/2000 06:56:58
General information
Forum:
Visual FoxPro
Category:
FoxPro 2.x
Title:
Miscellaneous
Thread ID:
00445686
Message ID:
00446303
Views:
13
Kevin,
Retouched the code but not tested at all. I actually do not suggest the way you're doing it. Because :
-Leads to more code (not a real reason:)
-Harder to follow field names for each and every table with a PK (and different str() sizes)
-Increases the chance a user waits for lock to get PK for TableA while another is getting a PK for TableB. While usercount is very small this might not be a problem but after sometime could be worse than using Access :)
-If those siteid are specific to stations or you could support an id per station then a StationId+sys(2015) would be much more easy key generation (already using char pk and size getting near or more than stationId+9)

I really would suggest to change your NextRef table structure and code. IMHO it would be easier to do this update than to maintain the current structure and code (assuming you have a chance to update code).
Function GetRef
Private all
Restore from sysstat.mem addi
p_refType = upper(p_refType)
lnSize = 6
lcTable = ''
Do case
  Case p_refType = 'REF'
    lcField = 'nr_refer'
    lcTable = 'Referral'
  Case p_refType = 'CLI'
    lcField = 'nr_client'
    lcTable = 'Client'
  Case p_refType = 'PRO'
    lcField = 'nr_prop'
    lcTable = 'Property'
  Case p_refType = 'PAC'
    lcField = 'nr_pack'
    lnSize = 8
  Case p_refType = 'RES'
    lcField = 'nr_resour'
  Case p_refType = 'CAR'
    lcField = 'nr_care'
    lnSize = 4
  Case p_refType = 'LOG'
    lcField = 'nr_loggen'
    lnSize = 8
  Case p_refType = 'MES'
    lcField = 'nr_mess'
    lnSize = 8
  Case p_refType = 'DIA'
    lcField = 'nr_diary'
    lnSize = 8
  Case p_refType = 'PUR'
    lcField = 'nr_purch'
  Case p_refType = 'POL'
    lcField = 'nr_poline'
  Case p_refType = 'SUS'
    lcField = 'nr_susp'
  Case p_refType = 'ORD'
    lcField = 'nr_order'
    lnSize = 7
    lcPrefix = s_ordprefix
  Otherwise
    Do message with 'Invalid number type passed - phone for help'
    Return .F.
Endcase

_alias = alias()
Select 0
Use nextref
If eof()
  Append blank
  For ix = 1 to fcount()
    If type(field(ix))='N'
      Replace (field(ix)) with iif(field(ix) == upper(lcField),2,1)
    Endif
  Endfor
  _ref = lcPrefix + str(1, lnSize)
Else
  Do while !rlock()
    Start=seconds()
    Do while seconds()-start < 0.1 && Give a short delay before trying to lock again
    && Assuming set process is at its default
    Enddo
  Enddo

  *Checks that the PK doesn't exist
  lcPrefix = iif(p_refType = 'ORD', s_ordprefix, s_siteID+s_kitID)
  lcPKField = 'PKId'
  lnVal = &lcField
  If !empty(lcTable)
    Do WHILE !CheckPk(lcTable, lcPrefix + str(lnVal, lnSize), lcPKField)
      lnVal = lnVal+1
    Enddo
  Endif

  _ref = lcPrefix + str(lnVal, lnSize)
  Replace (lcField) with lnVal+1
Endif
Use
If !empty(_alias)
  Select (_alias)
Endif
Return _ref


Function CheckPk
Parameters tcTable,tcRef,tcPKField
Private all
External array arrCnt
Select cnt(*) from (tcTable) where &tcPKField = tcRef into array arrCnt
Return arrCnt[1]=0
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform