Doug, Tables, TMOBJS (version 2.57 with OSX 8.1 build)
hi Das.
if you are looking for TMobjs… try www2.artsman.com/omnis/Software/TMObjs257.zip <www2.artsman.com/omnis/Software/TMObjs257.zip>
— it has a test library in it so you can see how to use some functions
— it has studio 8.1 Mac in it (thats fairly new)
As for how do we tell if a field is updated…… this is our $update method that over rides
look for TMOBJS.$prepareupdate in the code.
its a way to look at the current row and figure out what vars have changed in the statement.
using this … we can update against query classes.. super useful, since its not a normal omnis ability.
its mostly documented. Some statement calls may make sense bu the gist is
— get the prefix for the fields in the table (eg client file has prefix names of C_)
— update fields that get updated in all tables (eg date updated, data entered)
— update fields that get updated only in this table if there are exceptions
— set the where clause
— use $prepareupdate to get the new update statement
— add a returning clause for the key (discussed earlier on the list a month or so ago)
— run the statement
— fetch data from the returning clause (like the new record edit num)
— stick into the current list
— do any post updates to the record — if we want to do cascading of data from this table to another
— done.
; Check the Data unless “pCheckDataYN” is kFalse.
; Increment the “EditNum” column value by 1
; Add the constraint “AND EditNum=pRowOLD.EditNum” to the update SQL to make sure we don’t overwrite
; an update done by another user. Then proceed with the $update Do default.
; After the update, check the Status to make sure at the update was successful.
; If the update fails, check the EditNum to see if another user updated the record ahead of us.
; If that was the problem, analyze what has been changed. Compare the user’s current row and old row
; with the saved row in the data file. If the other user made changes, prompt the user with a list
; showing what changed and ask them to decide what to do.
;
; ->pRowOLD ;; Old Row, needed for matching the primary key. It is possible to send “current Row”.
; ->pDisableWhereNY ;; Disable the “Where” clause in the default SQL statement. Default is kFalse.
; ->pCheckDataYN ;; If the calling method says kFalse, skip calling $CheckData
; <-Return ;; Flag
If isclear($cinst.$getUniqueKey)
; Trying to update a row with a Primary Key # of 0? That's not gonna work very well, may want to check your code
Breakpoint
Quit method kFalse
End If
Calculate pDisableWhereNY as kFalse ;; Do NOT allow the programmer to disable the where clause. Too dangerous!
Do $cinst.$setRecordChangedSettings ;; Update the Standard Column values.
Do $cinst.$preUpdateSettings ;; Update the record with any final settings before saving. Will never fail. can refer to iRowOld to see old info
; V81000 DM - Totally changed this to always use the unique key and optionally the editnum. Took out old unused functionality as well.
If isclear(iFieldNamePrefix)
Breakpoint
Calculate WhereClause as $cinst.$wherenames
Else
Calculate WhereClause as con('WHERE ',iFieldNamePrefix,'_SEQ=',$cinst.[iFieldNamePrefix]_SEQ) ;; s
End If
; add editnum if it is found in the column table (and we should use it -- rare programmer choice not to)
If iSetEditNum
If pUseEditNum
Do tStringFields.$appendString(con(iFieldNamePrefix,'_EDITNUM=',$cinst.[iFieldNamePrefix]_EDITNUM),WhereClause,' and ') ;; was pRowOld xx_editnum
End If
Else
; V80000 DM - Patron Statistics and Daily Sales Summary don't have an edit num, so we don't need to watch for this. V90800 TicketTrove tables don't have them either
If iFieldNamePrefix<>‘CS’&iFieldNamePrefix<>‘S’&iFieldNamePrefix<>‘WP’&left(iFieldNamePrefix,3)<>‘ITT’
Breakpoint {there is no edit num in the table. Might be wise to add it}
End If
End If
; pass field name prefix to let external know if its our table. Only fields with the prefix are included. If no prefix, then its daylite table and al fields are included
; columns will never have changed, so wouldn’t be picked up. just look at CD_ for safety.
Calculate tempPrefix as con(iFieldNamePrefix,pick(iFieldNamePrefix=’CD’,”,’_’))
Do TMOBJS.$prepareupdate(statement,otherThanStandardField,nam(iRowOld),”DATE_UPDATED`DATE_ENTERED`EDITNUM`CHANGED_BY_E_SEQ”,tempPrefix)
If len(statement)=0|otherThanStandardField=kFalse
; V100737 nothing to update, so send trace log entry instead and it won’t interrupt flow
Send to trace log (Diagnostic message) {tablebase: did not update [iTableDesc] seq #[$cinst.[iFieldNamePrefix]_SEQ], no updatable fields [statement]}
Quit method kTrue
End If
; build the statement using the servertable names
If len(iFieldNamePrefix)
; if TM table (vs else is for any system table or daylite table), then use the prefix to get servertable. allows updates based on queries
; add in edit num if not there and we’ll substitute with xx_EDITNUM=xx_EDITNUM+1 in $replaceUpdateDefaults
Do $cinst.$addEDITNUMtoUpdate(statement)
Calculate statement as con(‘update ‘,$ctask.tStringFields.$getFileNameFromField($cinst.$getUniqueKeyField),’ set ‘,statement,’ ‘,WhereClause)
Else
Calculate statement as con(‘update ‘,$cinst.$servertablenames,’ set ‘,statement,’ ‘,WhereClause)
End If
Do $cinst.$replaceUpdateDefaults(statement,ReturnCols)
If len(ReturnCols)
Calculate statement as con(statement,’ RETURNING ‘,ReturnCols)
End If
;
Do $cinst.$sendSQLDirect(statement) Returns UpdateOK
; If the update was OK return true.
If UpdateOK
If iSetEditNum|len(ReturnCols)>0
Do iStatementRef.$fetch(returnValuesRow,1)
If returnValuesRow.$linecount=0
; should always be a return row … even if empty .. so this shouldn’t happen
Calculate UpdateOK as kFalse
Else If iSetEditNum&pUseEditNum ;; V100300 do we ignore editnum
; V100737 if no edit num in return row, then we didn’t update anything and thats a problem
If isclear(returnValuesRow.[iFieldNamePrefix]_EDITNUM)
Breakpoint
Calculate UpdateOK as kFalse
End If
End If
; V81000 DM – Add condition to check when another user beat you to the punch at updating
If not(UpdateOK)
Calculate editNumCurrent as $cinst.[iFieldNamePrefix]_EDITNUM
Calculate editNumExpected as $cinst.[iFieldNamePrefix]_EDITNUM+1
If tStringFields.$isFullVersion
Breakpoint {Didn’t update for some reason, verify edit numbers}
End If
Calculate employeeName as tEditCheck.$getEmployeeNameFromSeq(tDatabase.$getRecordField(con(iFieldNamePrefix,’_CHANGED_BY_E_SEQ’),con(iFieldNamePrefix,’_SEQ=’,pRowOLD.[iFieldNamePrefix]_SEQ),0))
; V82500 Use msgSqlError instead so that user can email stuff to us or copy to clipboard
Calculate message as con(‘The ‘,iTableDesc,’ record you were editing was changed by ‘,employeeName,’ before you confirmed your changes.’,kCr,kCr,’Try what you were doing again.’,kCr,kCr,’This usually happens for one of 3 reasons:’,kCr,kCr,I_BULLET_CHARACTER,’ Another employee changed it while you were looking at it’,kCr,I_BULLET_CHARACTER,’ You were editing the same record in two separate windows’,kCr,I_BULLET_CHARACTER,’ Or is a slight change it may be a program issue.’,kCr,kCr,’Please take a snaphot and send to ‘,gSupportEmail,’ if ‘,employeeName,’ was not editing the record.’,kCr,kCr,kCr,kCr,’Current editnum: ‘,editNumCurrent,’, expected editnum: ‘,editNumExpected,kCr,kCr,’Where: ‘,WhereClause,kCr,kCr,’Statement:’,statement,kCr,kCr)
; Do $cinst.$msgSqlError($cinst.$ref,TMObjs.$makeparamrow(‘Sound’,kTrue,’Message’,message,’TitleText’,’Error: UPDATE did not occur’,’AllowQuit’,kFalse,’Subject’,’TM Editnum’)) ;; $msgSqlError
Open window instance wMsgOk/*/CEN ($cinst.$ref,TMObjs.$makeparamrow(‘Sound’,kTrue,’Message’,message,’TitleText’,con(‘UPDATE did not occur – ‘,iTableDesc),’OkText’,’Continue’)) ;; $msgSqlError
Quit method kFalse
End If
If returnValuesRow.$colcount>0 ;; V100005 any returned values for any reason, stick into current row
Do $cinst.$assignrowTM(returnValuesRow,kTrue) ;; Merge data from the update row back into the list
End If
End If
Do $cinst.$setVariablesWhenRecordUpdated ;; only called on update
Do $cinst.$postUpdateSettings ;; called on insert and update
; V100677 set the cache after updating the record
If iSetCacheAfterUpdate¬(tUpgradeInProgress) ;; see if we poke the cache record (never when update in progress)
Do tDataCache.$UpdateCacheRecord($cinst.$getUniqueKeyField,$cinst.$getUniqueKey,$cinst) Returns #F
If flag false
Breakpoint {what happened}
End If
End If
Quit method kTrue
End If
; Update was not OK?
; Was the update caused because another user updated the record, changing the EditNum?
; Find out by fetching the record and comparing it’s EditNum to the pRowOLD.EditNum.
Breakpoint {if you get here… its cause update failed for some reason. Let doug Know you ran into this event}
; and then figure out why the old code read things into row, and does not put it back into $cinst.
; Select and fetch the record which has the matching primary key.
Do iRow.$getExactRecord(con(iFieldNamePrefix,’_SEQ’),iRowOld.[iFieldNamePrefix]_SEQ,kFetchAll,kFalse,0) Returns Flag ;; since getting existing record, dept of 0 is ok
If not(Flag)
; Open window instance wMsgOk/*/CEN ($cinst.$ref,TMObjs.$makeparamrow(‘Sound’,kTrue,’Message’,con(‘Error: It appears that another employee has deleted this record while you were editing it.’,kCr,kCr,’Try locating the record to see if it still exists.’)))
Send to trace log (Diagnostic message) {Did not update [iTableDesc] record #[$cinst.[iFieldNamePrefix]_SEQ] because another user edited it}
Quit method kFalse
End If
If tStringFields.$isFullVersion
; Open window instance wMsgOk/*/CEN ($cinst.$ref,TMObjs.$makeparamrow(‘Sound’,kTrue,’Message’,con(‘Developer Message:’,kCr,kCr,’Update of record has failed. We need to complete a generic method for giving the user more information about why the update failed.’)))
Do $cinst.$msgOk($cinst.$ref,TMObjs.$makeparamrow(‘Sound’,kTrue,’Message’,con(‘Developer Message:’,kCr,kCr,’Update of record has failed. We need to complete a generic method for giving the user more information about why the update failed.’)))
Breakpoint
End If
Quit method kFalse
Doug Easterbrook
Arts Management Systems Ltd.
mailto:doug@artsman.com
www.artsman.com
Phone (403) 650-1978
see you at the third annual users conference
tickets.proctors.org/TheatreManager/95/online?performance=29086 <tickets.proctors.org/TheatreManager/95/online?performance=29086>
> On Mar 2, 2018, at 2:03 PM, Das Goravani <das@goravani.com> wrote:
>
>
> I found a link using Google and downloaded TMOBJS I believe I got the unicode version, this was the link I found and used:
>
> www2.artsman.com/omnis/Software/ TMObjs253.zip
>
> Is there documentation for it somewhere? I’ll look on Google, but ask anyways in case.
>
>
>>>
>>> it is for that reason, the TMOBJS xcomp thats out there in the wild and free to all has a static method that will provide you with the update statement containing only changed fields. Its useful.
>>
>> Please explain what you mean by Provide you with the update statement…. Does it use info returned from somehow and build you a SQL command that you paste into place? Does it work on the fly behind the scenes? Do you know where to download it and is it cross platform?
>>
>>
>> _____________________________________________________________
>> Manage your list subscriptions at lists.omnis-dev.com
>> Start a new message -> mailto:omnisdev-en@lists.omnis-dev.com
>
> _____________________________________________________________
> Manage your list subscriptions at lists.omnis-dev.com
> Start a new message -> mailto:omnisdev-en@lists.omnis-dev.com
_____________________________________________________________
Manage your list subscriptions at lists.omnis-dev.com
Start a new message -> mailto:omnisdev-en@lists.omnis-dev.com