There seems to be some kind of thought transmission here, because this 
morning I was tossing this problem around (I happen to be very obsessive 
with things that logic says should work and somehow fail to) and came up 
with a solution. Talk about coincidences.

I applied the same technique you show with both a free table and a bounded 
table with no primary key and lo and behold, they work!!

The trick was to nominate a keyfield, even though it is not a primary key in 
either the free or the bound table. I figured that the only way that updates 
can ocurr is if the view or the cursor adapter (a super wrapper for a view) 
can identify the base table records. That is why you need a primary key. But 
a regular key, as long as the key is not repeated (ie, happens only once in 
the table for each record, such a a customer code), can very well serve as 
the keyfield. That way the CA can find the record to be changed. The other 
caveat is the datasource property. If the tables are VFP, you do not need to 
set it.

So here is my test program:

Use two tables, a free one called FreeTable.DBF and a bounded one, called 
BoundedTable. Both tables should have some records so you can test the 
program. You can also add records when in browse mode (control+Y) or delete 
others. After you close the browse, the tableupdate fires and then you will 
see your changes in the second browse.

Clear all

set multilocks on

** free table example

oCA=CreateObject('cursoradapter')
oCA.Tables ='freetable'
oCA.Alias='curfreetable'
oCA.SendUpdates= .T.
oCA.KeyFieldList ='code'
oCA.UpdatableFieldList ='code,descrip'
oCA.UpdateNameList ='code freetable.code,descrip freetable.descrip'
oCA.DataSourceType ="NATIVE"
oCA.BufferModeOverride = 5
oCA.SelectCmd = 'select * from freetable'
oCA.CursorFill()
Select curFreeTable
Browse                                        && open cursor, add, delete, 
modify records
TableUpdate(.t.,.t.,'curFreeTable') && commit your changes
Clear All
Use freetable                                && see changes in base table
Browse
Use


** bounded table example with no primary key

Clear All
Open Database rafael.dbc Shared

oCA=CreateObject('cursoradapter')
oCA.Tables ='BoundedTable'
oCA.Alias='curBoundedTable'
oCA.SendUpdates= .T.
oCA.KeyFieldList ='code'
oCA.UpdatableFieldList ='code,lastname'
oCA.UpdateNameList ='code BoundedTable.code,lastname BoundedTable.lastname'
oCA.DataSourceType ="NATIVE"
oCA.BufferModeOverride = 5
oCA.SelectCmd = 'select * from BoundedTable'
oCA.CursorFill()
Select curBoundedTable
Browse
TableUpdate(.t.,.t.,'curBoundedTable')
Clear All
Use BoundedTable
Browse
Use


BTW David, my name is Rafael (Raquel being a female Spanish name meaning 
Rachel)

Thanks anyways

Rafael Copquin






----- Original Message ----- 
From: "David Stevenson" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, December 08, 2006 1:42 PM
Subject: RE: cursor adapters on free tables


> Raquel,
>
> Here it is (untested). Note that the KeyFieldList property can be more 
> than
> one field, separated by commas, that uniquely identify a record. The
> information there, along with the tables, updatablefieldlist and
> updatenamelist are used in constructing the where clause of the update
> command. You DO NOT have to have a field specified as a primary key in a
> database for this to work.
>
> DEFINE CLASS caWidgets AS CursorAdapter
>
> DataSourceType = "NATIVE"
> Alias = "curWidgets"
> Tables = "Widgets"
> KeyFieldList = "code"
> SelectCmd = "select code, descrip from widgets"
> UpdatableFieldList = "code, descrip"
> UpdateNameList = code widgets.code, descrip widgets.descrip"
> SendUpdates = .T.
> WhereType = 3 && DB_KEYANDMODIFIED
> BufferModeOverride = 5 && Optimistic Table Buffering
>
> ENDDEFINE
>
> Be sure you have SET MULTILOCKS ON.
>
> That should get you most of the way there.
>
> David Stevenson
>
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
> On
> Behalf Of Rafael Copquin
> Sent: Wednesday, December 06, 2006 11:28 AM
> To: [EMAIL PROTECTED]
> Subject: cursor adapters on free tables
>
> I inherited an app written in VFP6 which I am trying to convert to VFP9.
> This app is full of updatable views, on free tables or bounded tables with
> no primary keys. I am finding it impossible to create cursor adapters
> (either in the CA builder or in code) for any of these tables.
>
> Questions:
>
> Is it possible to create updatable cursor adapters for free tables or
> bounded tables with no primary keys?
>
> If so, how?
>
> please show code to create an updatable CA for this free table:
>
>        widgets.dbf
>
>             code  C(4)       && alfanumeric field
>             descrip C(30)
>
> indexes on code and descrip, regular type
>
>
> TIA
>
> Rafael Copquin
>
>
> --- StripMime Report -- processed MIME parts ---
> multipart/alternative
>  text/plain (text body -- kept)
>  text/html
> ---
>
>
[excessive quoting removed by server]

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to