Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to make cursor read/write ?
Message
From
03/01/2001 03:46:07
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
31/12/2000 10:18:24
General information
Forum:
Visual FoxPro
Category:
Troubleshooting
Miscellaneous
Thread ID:
00458184
Message ID:
00458818
Views:
13
>Hi,
> I am working with the grid and populating the grid with a cursor. But i found that the cursor only can be read only when i try to update the fields.
> When i use SQL statement to select some needed fields into cursor to display on grid, i wish to add in new records into the grid(cursor), but it show me the error that the fields is read only. So, i am change to Select Into table, then it allow me to update and add records.
> Is it posible to make it read/write ? how ?
> And whats different if i use cursor and table ?
> thanks
>
>regard,
>kengwen

Chang,
1) To make a cursor readwrite first you should make it a true cursor. In VFP 'nofilter' clause lets you create a true cursor (prior versions need having a nonexistant field or expression forcing it like '..where .t. ...') :
select ... from myTbale into cursor Temp NOFILTER
use dbf('temp') in 0 again alias crsRW
use in 'temp'
select crsRW
2) Actually answer is hidden in your question :) Select into a table.
It's not true that a cursor is kept in memory and table is written to disk. Both are written to disk (even if the cursor just have 1 record with 1 logical field). A cursor is volatile because as you close it VFP does the cleanup for you and that's the difference. If cleanup is not a much concern for you than use a table.
Another difference, in normal circumstances you might think of cursors as tables belonging to a session only. Think of this, in 2 private datasessions you select into cursor 'myCursor'. The 2 myCursor are different because their actual tablenames on disk are generated uniquely (that's what dbf('myCursor') returns). One session cannot access the data in other session unless session is changed or actual name is provided.
Actual disk files being generated uniquely means that if you'd use table then you should also generate a unique name (lcTable=sys(2015)+'.tmp' for example). Otherwise in a multiuser app you'd get into trouble (or multipl data sessions).
You could do so with a strategy like this :
* Grid.init
this.tag = sys(2015)
select ... into table (this.Tag)
index on ....
this.RecordSource = (this.Tag)
*Grid.destroy
use in (this.tag)
erase (this.tag+'.*') && Cleanup
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