Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Append from Array with default value(primary key)
Message
From
10/10/2003 05:33:44
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
09/10/2003 15:33:07
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00837014
Message ID:
00837305
Views:
32
>>>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.)

View ??? Was there a view :) If then changing nothing (removing NewID from default if existed in view) and setting pkfield as not updatable would do it. It's already what you've done I think in a different way.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform