Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Remove elements from an array
Message
 
 
À
09/12/2020 14:55:09
Lutz Scheffler
Lutz Scheffler Software Ingenieurbüro
Dresden, Allemagne
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01677490
Message ID:
01677496
Vues:
52
>>>>>>Hi,
>>>>>>
>>>>>>The way to populate an array from a current cursor is as follows:
>>>>>>
>>>>>>local array aDbfStruct[1]
>>>>>>afields( aDbfStruct )
>>>>>>
>>>>>>
>>>>>>But if you are using a SQL Server Native Client, some fields (e.g. Varchar(MAX) fields) will have the length 0.
>>>>>>So, I need to remove these elements from the array aDbfStruct. Or exclude these elements when creating another cursor using the code:
>>>>>>
>>>>>>create cursor CUR_MYCURSOR from array aDbfStruct
>>>>>>
>>>>>>
>>>>>>How do you remove all elements from the above array which have element 3 equal to 0 (zero)? Or, can the above CREATE CURSOR be modified to ignore the "bad" fields?
>>>>>>
>>>>>>UPDATE: I can scan the array and check each element 3 for a value of 0 and delete it. But I thought maybe there is a more efficient way to delete those elements.
>>>>>>
>>>>>>TIA
>>>>>like this?
>>>>>
>>>>>COPY STRUCTURE EXTENDED to TabXYZ
>>>>>sele cur1.* from TabXYZ as Cur1 into array aDbfStruct where FIELD_LEN=0
>>>>>use in TabXYZ
>>>>>dele TabXYZ.*
>>>>>
>>>>>
>>>>>and
>>>>>
>>>>>COPY STRUCTURE EXTENDED to TabXYZ
>>>>>dele from TabXYZ where FIELD_LEN=0
>>>>>create newtable from TabXYZ
>>>>>use in TabXYZ
>>>>>dele TabXYZ.*
>>>>>
>>>>>should work w/o array
>>>>
>>>>I will try this. Thank you. Although I am thinking if this is more efficient that deleting elements from the array.
>>>
>>>It should be better then looping through the array
>>>No FOR .. ALEN() to 1 step -1, no IF, no ADEL, no DIMENSION.
>>>Faster, less complex code.
>>>The need to create a file and delete it is odd, but that can't be helped. Try to target GETENV('temp') dir
>>>update: consider to use some unique name like sys(2015) too. Much fun if two process create the same file .... SYS(2015) is not fool prove, but less likely.
>>
>>With my luck, the less likely will turn out to be :) I will consider your approach. Thank you.
>
>Then you must create a UUID and name the file like that. This is fool prove. (But, given the extra time to create the UUID a FOR NEXT loop might be finished in this time too) ;)

I think I will stick with scanning the array and deleting the "bad" columns. One approach vs the other could be a few millisecond difference. The customer will have to wait :)
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform