Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP 6 alternative to views
Message
From
12/01/2021 14:19:53
Mike Yearwood
Toronto, Ontario, Canada
 
 
To
11/01/2021 18:40:33
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01677761
Message ID:
01677820
Views:
57
I very often grab the first of a set into a beginning string and then all the rest concat without conditions.
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...
>2 hints to get closer to ca perf: in both for loops
>
>replace 2 lines concatenating lcUpdateList into a single line to eliminate temp storage memory creation
>
>switch all concats of IIF(m.llFirstRecord,"",",") to memvars lcKommaFlipFirst and lcValueFlipFirst
>initialized where you set llFirstRecord = .T.
>and changed everywhere you flip llFirstRecord = .f.
>
>
>*-- 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
>
>
>IMO easier to read, minimally better perf realized only on 100+ fields ;-)
>
>regards
>thomas
>
>>It's a little bit old and rusty, but could be a workaround. Interestingly performance is nearly identical to CA.
>>
>>
>>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
>>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform