Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
The most elegant and readable way (and efficient)
Message
 
 
To
10/12/2005 09:30:04
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01076714
Message ID:
01076926
Views:
16
>>Hi,
>>
>>Sergey's way is probably efficient enough, but on the asssumption that oodles
>>of records might have to be modified, I'ld prepare a replace-string
>>pseudo code
>>
>>for every field in both tables and not in exclude list
>>   tcRep = iif(empty(tcRep), "" ,tcRep + ", ") + fieldname + " with iif(empty(target.fieldname) and !empty(source.fieldname), source.fieldname,  target.fieldname)"
>>
>>and later call
>>replace all &tcRep for seek(target.PK, SourceAlias, SourceTag)
>>
>>which makes just one call to makroexpansion for the whole table.
>>Since the whole processing of empty fields is handed off to the runtime,
>>it should be faster than checking in a vfp loop after positioning via code.
>>
>>Also, it is immune against tables with different fcount() and so on -
>>but requires same field names and is a bit more work. depends on your data <g>.
>>
>>
>>
>>my 0.02 EUR
>>
>>thomas
>
>Thomas,
>Then adding another 0.01 EUR wouldn't hurt:)
>I agree building a string and doing a single pass would be better but I actually see danger in both approaches. Empty() function that is:)
>-Field(s) might be supporting null
>-Field type might be dangerous for this logic < g > ie: a logical. Is .f. empty or .t. then:)
>If these problems were not an issue Max() might be used as a shortcut with most datatypes:
>
> tcRep = iif(empty(tcRep), "" ,tcRep + ", ") + fieldname + " with iif(empty(target.fieldname) and !empty(source.fieldname), source.fieldname, target.fieldname)"
>
> tcRep = iif(empty(tcRep), "" ,tcRep + ", ") + fieldname + " with max(source.fieldname, target.fieldname)"
>
>Cetin

What if the both fields are character type and both not empty? Max would not work at all, because the rule is to replace with the old data if the old have value and the new doesn't have a value. Otherwise we need to keep new record value preserved.

Anyway, I think gather works quite nice instead of building the replace command (though I considered it as well at first).
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform