Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Send updates to the MSSQL server VFP6.0
Message
From
21/02/2004 05:11:51
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
20/02/2004 23:25:26
Suhas Hegde
Dental Surgeon
Sirsi, India
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00879545
Message ID:
00879582
Views:
15
This message has been marked as the solution to the initial question of the thread.
>HI,
>I have a few problems.
>
>I have at table in the Sqlserver
>
>CREATE TABLE [dbo].[test_guid] (
> [test_guid_id] uniqueidentifier ROWGUIDCOL NOT NULL ,
> [a] [char] (10) NULL ,
> [b] [char] (10) NULL ,
> [bit1] [bit] NOT NULL ,
> [timestamp_column] [timestamp] NULL
>) ON [PRIMARY]
>
>and a few values in it with bit1 .f.
>
>i make a cursor with a valid handle like
>
>cursorsetprop("buffering",5,0)
>
>sqlexec(handle,'select * from test_guid','test1') && returns 1 and i get the cursor with the records.
>** so far so good. Then
>sqlexec(handle,'select top 0 test_guid_id,bit1 from test_guid','test2') && returns 1 and i get an empty cursor
>
>insert into test2 values(test1.test_guid_id,.t.) && value gets inserted locally.
>skip in test1
>insert into test2 values(test1.test_guid_id,.t.) && value gets inserted locally.
>
>** NOW how to update test2 ??? thats bugging me for days. I tried a lot with cursorsetprop. But the error returned was 1491. No update tables as specified.Use the tables property of the cursor.
>
>Can any one tell me if it works this way and if so how ? If not how should i modify this ?
>
>thanx in advance.

Suhas,
Hi again :) Pasting my reply on EE here as is for others' benefit :

Suhas,
Missing piece is the cursor is not an updatable one (check CursorSetProp() commands in sample) :
( PS: I've problems in sending email - temporary I hope :)
*********************************************************************
Local lnHandle, lcDatabaseName, lcCommand,ix
lcDatabaseName = "myTestData"
lnHandle=Sqlstringconnect('DRIVER=SQL Server;SERVER=servername;Trusted_connection=Yes')
If SQLExec(m.lnHandle, "create database "+m.lcDatabaseName) < 0
 Do errHand
 Return
Endif
mySQLExec(m.lnHandle, "use "+m.lcDatabaseName)

TEXT to m.lcCommand noshow
CREATE TABLE [dbo].[test_guid] (
 [test_guid_id] uniqueidentifier ROWGUIDCOL NOT NULL ,
 [a] char(10) NULL ,
 [b] char(10) NULL ,
 [bit1] bit NOT NULL ,
 [timestamp_column] timestamp NULL
) ON [PRIMARY]
ENDTEXT
mySQLExec(m.lnHandle, m.lcCommand)



mySQLExec(m.lnHandle,'select top 0 test_guid_id,bit1 from test_guid','v_test') 
&& returns 1 and i get an empty cursor. same if used where 1=2 instead of top 0

* Make SPT cursor an updatable cursor    <---------------------------- Check these part
CursorSetProp('KeyFieldList','test_guid_id','v_test')
CursorSetProp('WhereType',1,'v_test')
CursorSetProp('Tables','test_guid','v_test')
CursorSetProp("UpdateNameList", ;
 "test_guid_id test_guid.test_guid_id,"+;
 "bit1  test_guid.bit1",'v_test')
CursorSetProp('UpdatableFieldList','test_guid_id,bit1','v_test')
CursorSetProp('SendUpdates',.T.,'v_test')
CursorSetProp('Buffering',5,'v_test')
* Make SPT cursor an updatable cursor    <---------------------------- Check these part

* Generate 5 GUID using SQL server's NewID() function
mySQLExec(m.lnHandle,"select top 5 NewID() as cGUID from pubs..authors","GUIDVal")
Select GUIDVal
Scan
 Insert Into v_test Values (GUIDVal.cGUID,.T.) && value gets inserted locally.
Endscan
? Tableupdate(2,.T.,'v_test') && Tableupdate to send updates

mySQLExec(m.lnHandle,'select * from test_guid','CheckResult')
SQLDisconnect(m.lnHandle)
Select CheckResult
Browse Title 'After Update'


Function mySQLExec
Lparameters tnHandle, tcSQL, tcCursorName
tcCursorName = Iif(Empty(tcCursorName),'',tcCursorName)
If SQLExec(tnHandle,tcSQL,tcCursorName) < 0
 Do errHand With tcSQL
Endif

Function errHand
Lparameters tcSQL
lcError=tcSQL+Chr(13)
Aerror(arrCheck)
For ix=1 To 7
 lcError = lcError+Trans( arrCheck [ix])+ Chr(13)
Endfor
Messagebox(lcError,0,'Error def.')
********************************************************************* 
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
Next
Reply
Map
View

Click here to load this message in the networking platform