Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Append from Array with default value(primary key)
Message
From
09/10/2003 15:33:07
 
 
To
09/10/2003 13:14:30
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00837014
Message ID:
00837080
Views:
35
This message has been marked as the solution to the initial question of the thread.
>>I have a table with a primary key index. The default value for the field is a newid() function. I have a local view of the table, and want to append to the view from an array, and I can't get it to work.
>>
>There are multiple ways to workaround. I think array processing is well fast and efficient :

I went to append from array because cycling through the business objects' add()s repeatedly was slow enough to count when it added ~300 records.


>
>select 0x7FFFFFFF as Pkfield, ... into ... array aRecs
>for ix=1 to alen(aRecs,1)
>  aRecs[ix,1] = NewID('myTable')
>endfor
>select myTable
>append from array aRecs
>PS: You might even make NewID() call part of SQL.

Using NewID() at this point binds the code to the specific table, something I was trying to avoid. It also forces me to remember to deal with the primary keys, something I'd prefer to let APPEND deal with.

When I started working and thinking through your suggestion, I found the answer.

Arrange the local view so the Primary Key is the last field.
Exclude the Primary Key from the (Select SQL into) array.
Append from array into the view.
(Save and requery the view if you want to continue to use it. In the view, the Primary Keys are all zeroes, but NewID() is called automagically when written back to the table.)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform