Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Best method for SQL updates
Message
From
08/09/2003 02:11:07
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
07/09/2003 07:48:06
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00826743
Message ID:
00826975
Views:
14
For the pubs sample pulling all records were no problem and thus I didn't include any filter. Normally you'd work with parameters to get subset or just the structure (1=0). 1=0 means .f. so you could directly say 'where .F.' :)
I don't strictly prefer creating updatable cursor to make inserts. It depends. ie: If I'd insert records where I'd only set 2 of the fields and leave rest at their defaults then I might choose to simply call :

lcName = 'myName'
ldDate = date()
SQLExec(lnHandle, 'insert into myTable (name,date) values (?lcName,?ldDate)')

or if I was doing that from a local cursor named crsTemp :

SQLExec(lnHandle, 'insert into myTable (name,date) values '+;
'(?crsTemp.Name,?crsTemp.Date)')

OTOH if I'm doing this for a lot of records each insert would count as a separate atomic operation and would slow down the whole process (+ parameter binding slows down). Creating an updatable cursor and calling a single tableupdate() would be better.

Cetin
>Cetin,
>
>Thanks for the reply and the code sample. I have a few questions if you don't mind. Do you find that you prefer the method of creating the updatable cursor to doing an insert from values? Also, since you created the cursor with no filter, will it pull "all" the records from the server? Would it be better to add something like "where 1=0 " to the string so that the cursor would be empty? For this project, I am stuck using VFP 7 because it is a commercial accounting application and I have to run within the system so I will have to wait on the cursoradapters.
>
>Thanks,
>Bill
>>I don't believe it should be so hard either :) Search for SPT and you'll find tons of samples. For a quick sample check this one that updates pubs.dbo.authors (what it does is to make an SPT cursor an updatable cursor) :
>>
>>
>>lnHandle=Sqlstringconnect('DRIVER=SQL Server;'+;
>>  'SERVER=servername;DATABASE=pubs;Trusted_Connection=Yes')
>>SQLExec(lnHandle,'select * from dbo.authors','v_authors')
>>CursorSetProp('KeyFieldList','au_id','v_authors')
>>CursorSetProp('WhereType',1,'v_authors')
>>CursorSetProp('Tables','authors','v_authors')
>>
>>CursorSetProp("UpdateNameList", ;
>>  "au_id    authors.au_id,"+;
>>  "au_lname authors.au_lname,"+;
>>  "au_fname authors.au_fname,"+;
>>  "contract authors.contract",'V_authors')
>>
>>CursorSetProp('UpdatableFieldList','au_fname,au_lname,contract','v_authors')
>>CursorSetProp('SendUpdates',.T.,'v_authors')
>>CursorSetProp('Buffering',5,'v_authors')
>>Browse title "You're allowed to update lname, fname, contract"
>>Tableupdate(2,.T.,'v_authors')
>>SQLExec(lnHandle,'select * from dbo.authors','afterupdate')
>>SQLDisconnect(lnHandle)
>>Select afterupdate
>>Browse
>>
>>
>>PS: VFP8 cursoradapter makes this much easier.
>>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