Category : Paradox DBMS
Archive   : OKKEY3.ZIP
Filename : AZOKKEY3.SC

 
Output of file : AZOKKEY3.SC contained in archive : OKKEY3.ZIP
;Contents : Procedure OkKey3.l and CopyFromArray3.u
;Source File : OkKey3.l.SC
;Submitted By : Alan Zenreich, Zenreich Systems
;Last revision : 6/1/89
;Description : These procedures trap for key violations in "real-time"
; during the CoEdit of a table.
; See text below for full commentary
; Also a routine for an intelligent COPYFROMARRAY that works
; with detail tables.
;-------------------------------------------------
;Call Syntax : OkKey3.l(requiredcheck.l)
;Parameters : The procedures use REQUIREDCHECK OFF to prevent a conflict
; with any Required valchecks.
; If you set requiredcheck.l to FALSE, REQUIREDCHECK
; will remain OFF.
; If requiredcheck.l is any other value, REQUIREDCHECK
; will be turned back to it's normal ON status.
; See the examples and detailed notes below.
;Examples : OkKey3.l(TRUE) ; Make sure REQUIREDCHECK is turned back on
; : OkKey3.l(FALSE) ; REQUIREDCHECK will remain off
; : OkKey3.l("") ; REQUIREDCHECK will be turned back ON
;
;Returns Value? : TRUE or FALSE
;Paradox Version : 3
;
;-------------------------------------------------
;Call Syntax : CopyFromArray3.u(arrayname.a,requiredcheck.l)
;Parameters : arrayname.a is a string of the name of an existing array
; already defined with a COPYTOARRAY
; requiredcheck.l is described above
;
;Returns Value? : No
;Paradox Version : 3
;
;-------------------------------------------------
; OkKey3.l.sc Alan Zenreich Revised 3/1/89
;
; These procedures were developed to trap for key violations in Coedit mode
; in real time.
; i.e., upon GoodDepart DEToolkit procedure, but could probably be used at
; any time.
;
; OkKey3.l(requiredcheck.l) is used to return a TRUE or FALSE that tells the
; calling program whether or not the proposed key is "OK"
;
; CopyFromArray3.u(arrayname.a,requiredcheck.l) simulates a COPYFROMARRAY,
; but will work in a detail table, where the linked fields cannot be placed
; explicitly.

; Key violation checking in real time is a somewhat complicated issue.
; I want to remain on the record, and not let it "FLY" away from me.
;
; I also want to deal with someone entering a valid key, then going back,
; changing their mind, and replacing the valid key with a conflicting key.
; The proc should trap for this occurance.
;
; Issues that need to be resolved include:
; If record is not yet posted to table (a new record) we want to keep it
; that way until ready to commit it.
; If we are editing an existing record and change the key, how does this
; affect other records that depend on it (Should the user be allowed to
; change the key in the first place)
; If it ok to change a key, and the user accidentally changes it to an existing
; key, then we have to deal with it in a special way, since we are in a
; mode that Paradox insists that we correct immediately.
; Do we want to show the user the offending key, and have them toggle?
; Do we want to tell the user that the key is already on file, and refuse the
; change?
; If we use the technique in the code below, if a key conflict exists, the
; record is deleted and then reinserted to make it an unposted record.
; What happens if the user wants to "UNDO" his or her changes?
; When does the record disappear from other nodes on the network?
; If another user attempts to edit the reocord on their node, do they get a
; "Record deleted by another user" message?
;
;
; Obviously I would prefer an ISKEYVALID() and a DETAILFROMARRAY command from
; within PAL.
;
; So..... here goes. At this writing everything appears to works ok, as it has
; undergone extensive testing under a variety of LinkTypes.
; If you experience any problems, I'd like to hear from you so that they can
; be corrected. Contact Alan Zenreich at Zenreich Systems 212-691-0170
;=====================================================================
; OkKey3.l checks for key violation in coedit mode.
;
; The proc returns a true if the key is ok, and a false if not
;
; If the record is a Master record, and a key conflict exists, that is the
; state that will remain. It is safe, because subsequent calls to Okkey3.l will
; *NOT* overwrite any existing record because it does not use a lockrecord to
; test for ability to post.
;
; If not in a Master record, the proc deletes the record and then reinserts it,
; returning it to a "not yet posted" state.
;
; This avoids a potential problem where a record is locked, and when the next
; attempt to lock or unlock the record occurs and we come up with a
; "key already exists" situation, any future LOCKRECORD or UNLOCKRECORD
; will automatically post the offending record, overriding the record that
; already has the valid key. This is not usually what we want, so the record
; is placed as not yet posted, to make it relatively harmless.
;
; A byproduct of the delete and reinsert technique is that UNDO becomes
; dangerous, as it would remove the recently inserted record. I get around
; this by always doing a copytoarray on a record to be edited, so when the
; user wants to "Undo" changes, is issue a copyfromarray to restore the record's
; original state.
;
; Note that this routine ONLY works with Paradox version 3, as it uses the
; ReSyncKey to pseudo-post the record without letting it fly away.
;

PROC OkKey3.l(requiredcheck.l)
; requiredcheck.l ; determines if required fields should be reinstated
; ; when leaving the proc
; should be TRUE if you want to make sure that
; REQUIREDCHECK ON is in effect when exiting
; Copyfromarray3.u, called by this proc
; If requiredcheck.l is any value other than FALSE,
; REQUIREDCHECK will be set back to the normal ON status
PRIVATE
field.a, ; current field name
r, ; temporary array
ok.l ; is record ok (no key conflict)

IF NKeyFields(TABLE())=0 THEN
ok.l = TRUE ; no key fields, cannot possibly be a key conflict
ELSE ; there must be key fields
REQUIREDCHECK OFF ; helps deal with required valcheck and empty fields
CopyToArray r ; for safekeeping
ImageRights ; make sure that we have rights to do this
DEL ; attempt to remove the current record
SWITCH
CASE SEARCH("Can't delete master", WINDOW())=1 : ; must be a master
field.a=FIELD() ; just in case resynckey manages to jump
; us to another page in a multi page form
Resynckey
; shows a key conflict without unlocking/ records won't fly away
MOVETO FIELD field.a ; Paradox3 sometimes jumps to another field or page
ok.l = ERRORCODE() <> 53 ; True if errorcode is not equal to 53
OTHERWISE: ; detail record, or not a master with details
Ins ; insert a blank, unposted record
; now copy from the array to create a complete unposted record
Copyfromarray3.u("r",requiredcheck.l)
KeyLookup ; attempt toggle to possible offending key
ok.l = errorcode() = 56 ; if it can't find lookup, then key is ok
IF ok.l THEN ; lookupkey not found
LockRecord ; record posts, and cursor remains with it
ELSE
KeyLookup ; return to record values as operator entered
ENDIF
ENDSWITCH
ENDIF
IF NOT ok.l THEN
; place whatever error message or procedure you like to use here, i.e
topmsg.u("A record with this key already exist","C",1000)
ENDIF
IF requiredcheck.l<>FALSE THEN
REQUIREDCHECK ON
ENDIF
RETURN ok.l
ENDPROC
WRITELIB libname.a OkKey3.l
RELEASE PROCS OkKey3.l
;========================================================================

; This proc must be used in CoEdit mode only, as it needs to determine the
; number of keyfields. It cannot be used reliably in Edit mode because as
; soon as any field in a table is changed in Edit mode, the primary index
; is flagged as obsolete, and nKeyfields would equal 0.
; In Detail tables there are a few things worth mentioning:
; If tiebreaker keys are regular fields on the form, all will work well
; If there is one tiebreaker field, it may be regular or display only
; If there is more than one tiebreaker, the last one may be regular or
; display only, the rest must be regular.
; In short, the proc will work properly in detail records as long as
; there is not more than one display-only tiebreaker key.


PROC Copyfromarray3.u(arrayname.a, requiredcheck.l)
; arrayname.a ; name of array to copy from, a string
; requiredcheck.l ; should REQUIREDCHECK status be reinstated after the proc

PRIVATE
fields.n, ; number of fields in the table
n1, ; linked field counter
n2, ; field assignment counter
field.a, ; current field name
window.a ; Paradox window message

REQUIREDCHECK OFF ; just in case we have any required fields
IF LINKTYPE()="None" THEN
EXECUTE "COPYFROMARRAY " + arrayname.a ; not in a detail record
ELSE ; we must be in a detail record
; now let's attempt to find the first field that actually
; appears in the form or table view.
; This lets us check for linked keys that cannot be explicitly assigned
field.a=FIELD() ; save the name of the current field
fields.n=NFields(TABLE()) ; how many fields are there in the table?
Menu {Image}{zoom}{Field} ; luckily not sensitive to rotations
; first we need to see which field is the first unlinked key
FOR n1 FROM 1 to NKEYFIELDS(TABLE())
ENTER ; will Paradox let us land on the field?
; We'll check window()
window.a = WINDOW() ; must assign to a variable or else it won't work
; properly. Combining zwindo with an ECHO off
ECHO OFF ; is necessary because of some problems with
; the Window() function in Paradox 3.00
IF window.a <> "" THEN ; must be telling us that this is not a placed field
RIGHT ; let's go on tho the next field
ELSE
QUITLOOP ; n1 is the # of the first field that was placed on the form
ENDIF
ENDFOR
; zoom choices are still on the workspace
n1 = min(n1,nkeyfields(table()))
; just in case the last tiebreaker was a display only field

; at this point, n1 is equal to the field number of the first tiebreaker
; key placed on the form, or the last key field that is a display only
; field on the form.

Menu {Image}{zoom}{Field} ; luckily not sensitive to rotations
; now let's place all available fields (non-linked)
FOR n2 FROM 1 TO fields.n ; get all the fields in the table
IF n2 >= n1 THEN ; let's assign the field with its array value
EXECUTE "[" + MENUCHOICE() + "]=" + arrayname.a + "[n2+1]"
ENDIF
Right
ENDFOR

CtrlBreak ; back out of the zoom/field
MOVETO FIELD field.a ; back to the original field
ENDIF
;in the event that the requiredcheck.l has been set to anything bu FALSE
;let's reinstate the required check status.
;If requiredcheck.l is set to *anything* other than FALSE, requiredcheck will
;remain off
IF requiredcheck.l<>FALSE THEN
REQUIREDCHECK ON
ENDIF
ENDPROC
WRITELIB libname.a Copyfromarray3.u
RELEASE PROCS Copyfromarray3.u




  3 Responses to “Category : Paradox DBMS
Archive   : OKKEY3.ZIP
Filename : AZOKKEY3.SC

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/