locate lcString=something skip scan rest lcString=lcString+','+something endscan>nice clean code - still I cannot turn off that weird optimizer between my ears even for old code...
>*-- init >lcKommaFlipFirst = "" >lcValueFlipFirst = "?" >.... > for... > if.... > lcFieldList = m.lcFieldList + m.lcKommaFlipFirst + m.lcFieldName > lcValueList = m.lcValueList + m.lcValueFlipFirst + m.lcFieldName > lcUpdateList = m.lcUpdateList + m.lcKommaFlipFirst + m.lcFieldName + "= ?" + m.lcFieldName > * > if m.lcKommaFlipFirst=="" && or loop from 2 with more init code to eliminate memory thrashing > lcKommaFlipFirst = "," > lcValueFlipFirst = ",?" > endif > endif > next >>
>>LPARAMETERS toBusiness AS ccntBusinessData OF aBasicGen >>* >>LOCAL llFirstRecord, lcFieldlist, lnFields, lcValueList, lcUpdateList, lcFieldName >>LOCAL lnNr, lcKeyFieldValue, llRetVal, lcQuery >>* >>*-- Compare the alias with the table. >>SELECT (THIS.AliasName) >>* >>lcKeyFieldValue = EVALUATE(This.AliasName + "."+ THIS.KeyFieldName) >>* >>llFirstRecord = .T. >>lcFieldList = "(" >>lcValueList = "(" >>lcUpdateList = "" >>lnFields = 0 >>* >>IF THIS.cFieldList = "*" >> * >> *-- If we selected all fields to be updated, create the field list from all fields >> *-- in the current cursor. >> lnFields = FCOUNT(THIS.AliasName) >> * >> FOR lnNr = 1 TO m.lnFields >> * >> lcFieldName = UPPER(FIELD(m.lnNr, THIS.AliasName)) >> * >> IF UPPER(m.lcFieldName) $ UPPER(toBusiness.cForeignFieldList) >> *-- The foreign field list with field names that should or cannot be updated. >> LOOP >> ENDIF >> * >> IF m.lcFieldName == UPPER(THIS.KeyFieldName) ; >> OR INLIST(GETFLDSTATE(m.lcFieldName,THIS.AliasName),2,4) >> * >> lcFieldList = m.lcFieldList + IIF(m.llFirstRecord,"",",") + m.lcFieldName >> lcValueList = m.lcValueList + IIF(m.llFirstRecord,"",",") + "?" + m.lcFieldName >> * >> lcUpdateList = m.lcUpdateList + IIF(m.llFirstRecord,"",",") + m.lcFieldName >> lcUpdateList = m.lcUpdateList + "= ?" + m.lcFieldName >> * >> llFirstRecord = .F. >> ENDIF >> * >> ENDFOR >>ELSE >> * >> *-- Only use the fields that are specified in the field list. >> lnFields = ALINES(laFields, THIS.cFieldList,.T.,",") >> FOR lnNr = 1 TO lnFields >> * >> lcFieldName = UPPER(laFields[lnNr]) >> * >> IF lcFieldName == UPPER(THIS.KeyFieldName) ; >> OR INLIST(GETFLDSTATE(m.lcFieldName,THIS.AliasName),2,4) >> * >> lcFieldList = m.lcFieldList + IIF(m.llFirstRecord,"",",") + m.lcFieldName >> lcValueList = m.lcValueList + IIF(m.llFirstRecord,"",",") + "?" + m.lcFieldName >> * >> lcUpdateList = m.lcUpdateList + IIF(m.llFirstRecord,"",",") + m.lcFieldName >> lcUpdateList = m.lcUpdateList + "= ?" + m.lcFieldName >> * >> llFirstRecord = .F. >> * >> ENDIF >> ENDFOR >>ENDIF >>* >>lcFieldList = m.lcFieldList + ")" >>lcValueList = m.lcValueList + ")" >>* >>IF THIS.NewRecord >> * >> TEXT TO lcQuery TEXTMERGE NOSHOW >> INSERT INTO <<THIS.TableName>> >> <<lcFieldList>> VALUES <<lcValueList>> >> ENDTEXT >> * >>ELSE >> *-- Update the record. >> TEXT TO lcQuery TEXTMERGE NOSHOW >> UPDATE <<THIS.TableName>> >> SET <<lcUpdateList>> >> WHERE <<THIS.KeyFieldName>> = ?pcRecordKey >> ENDTEXT >> * >> PRIVATE pcRecordKey >> pcRecordKey = THIS.RecordKey >> * >>ENDIF >>* >>SELECT(THIS.AliasName) >>llRetVal = THIS.DoSQL(m.lcQuery) >>* >>IF m.llRetVal >> =TABLEUPDATE(.F.,.T.,THIS.AliasName) >>ENDIF >>* >>RETURN llRetVal >>