Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
VFP 6 alternative to views
Message
De
13/01/2021 18:39:34
 
 
À
12/01/2021 14:19:53
Mike Yearwood
Toronto, Ontario, Canada
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01677761
Message ID:
01677837
Vues:
109
Yupp, one of my typical strategies as well, as you see in the comment
&& or loop from 2 with more init code to eliminate memory thrashing
but here due to the if we need 2 inits, so I left the Code more as it is.

Christian knows what he is doing - the double assign probably just a leftover from first rough code, easy to debug as small pieces get added to check base idea works - and just forgotten to clean up when done. Could happen to me as well until I read my own code again...

It is his own fwk, so he has NOT the drive to aim for best code as users won't pay him for the fwk itself - were it a commercial fwk further editing would be needed to give paying fwk customers better code to read / enjoy and myself more DRY code. Then probably the doubled code would be eliminated, the field filter optionally built into a fixed string on * for next records with more speed and so on. A homegrown fwk - esp if nipping speed wise at cursoradapter heels - is good enough if it breaks out reusable code, which this clearly is.


>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
>>>
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform