Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Update cursor from array
Message
 
 
À
15/08/2019 05:24:19
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01670075
Message ID:
01670099
Vues:
56
Thank you for this suggestion. As I mentioned to Martina, the array was (in my draft work) created from a cursor since I thought of passing the array from one method to another. Martina showed that it is fairly simple to update one cursor from another using the SET RELATION and REPLACE. I tried it in a test and it works well. Both cursors are within scope of the form and therefore will make the process much simpler (and fewer lines).

>You can use Update SQL. ie:
>
>
>create cursor newValues (PK I, WEEK_NO I, WEEK_FR  I, WEEK_TO  i)
>insert into newValues from array aSchedule
>
>update myTable set ;
>   WEEK_NO = src.WEEK_NO, ;
>   WEEK_FR  = src.WEEK_FR, ;
>   WEEK_TO = src.WEEK_TO ;
>from newValues src ;
>where myTable.PK = src.PK;
>
>
>However, this question might be related to your other question of passing array. If so, you could first use the 'pass a table' sample to pass needed data and you simply update the results as:
>
>
>select myTable
>local ix, oData
>for ix = 1 to m.loData.Rows
>   oData = m.loData.Data[m.ix]
>   if seek(m.oData.PK, 'myTable', 'PK') and ;
>       ( m.oData.WEEK_NO != myTable.WEEK_NO or ;
>         m.oData.WEEK_FR != myTable.WEEK_FR or ;
>         m.oData.WEEK_TO != myTable.WEEK_TO ) 
>         gather name m.oData 
>   endif 
>endfor
>
>
>This interestingly works very well (you can even remove the check except PK).
>
>>Hi,
>>
>>I need to update a cursor based on the values in an array. I know I can do it by scanning through the cursor or scanning through the array and checking each element. But I was wondering if there is SQL command to do it. The following are the structure and sample of the cursor and the array:
>>
>>
>>*-- cursor
>>*-- strucutre
>>column        value
>>*-- record 1
>>PK                333
>>WEEK_NO    12
>>WEEK_FR      1
>>WEEK_TO     52
>>*-- record 2
>>PK                4
>>WEEK_NO    45
>>WEEK_FR      2
>>WEEK_TO     23
>>*-- and so on
>>
>>*-- array
>>local array aSchedule[2,4]
>>*-- element 1
>>aSchedule[1,1]  = 333   && corresponding to the column PK in the cursor
>>aSchedule[1,2]  = 3       && corresponding to the column WEEK_NO in the cursor
>>aSchedule[1,3]  = 1       && corresponding to the column WEEK_FR in the cursor
>>aSchedule[1,4]  = 45       && corresponding to the column WEEK_TO in the cursor
>>*-- element 2
>>aSchedule[1,1]  = 4        && corresponding to the column PK in the cursor
>>aSchedule[1,2]  = 3       && corresponding to the column WEEK_NO in the cursor
>>aSchedule[1,3]  = 1       && corresponding to the column WEEK_FR in the cursor
>>aSchedule[1,4]  = 45      && corresponding to the column WEEK_TO in the cursor
>>
>>
>>TIA
"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
Répondre
Fil
Voir

Click here to load this message in the networking platform