Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Updatable Cursors:
Message
From
17/05/2001 16:27:08
David Fluker
NGIT - Centers For Disease Control
Decatur, Georgia, United States
 
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00508483
Message ID:
00508503
Views:
23
>>More anomalies?
>>
>>Is there any way to get the results of a SQL statment into an updatable cursor? We've noticed that if you use SELECT ..... INTO CURSOR, the resultant cursor is read only and can't be updated with INSERT or UPDATE statements.
>>
>>Cursors created with CREATE CURSOR behave just like tables and can be UPDATED, ALTERED, or INSERTED.
>>
>>The problem I'm trying to get beyond is the whole issue of temporary files when creating elaborate queries. Ideally, I'd like to use cursors instead of creating tables for queries requiring multiple intermediate steps.
>>
>>--- L
>Assume the cursor that is the result of your query is named "query". You can write to this cursor by issuing the following command:
>
>USE AGAIN DBF('query') ALIAS whatever

Use caution with this method. If your SELECT was fully optimized it might not have created a real cursor, but a filter on the original table. This method will create an editable alias of the original table. I wrote a little program I have used for years that makes a cursor from a SQL Select editable.

Syntax MkEditbl([cExp])
cExp = The alias of the Read-Only cursor.
-If you don't pass it an alias, it will attempt to use the current work area.
-It will not work on a DBF, only a cursor.
-It returns .T. if successful.
*:     Program:	MkEditbl
*:		David Fluker February 1995
*:
*: Description:	Converts read only cursor into an editable cursor
*:
*: Parameter:	cAlias - Alias of Read-Only cursor
*:*************************************************************
PARAMETER cAlias
PRIVATE TempArea, CurAlias

*: Check parameter

*: If no cAlias passed, use current workarea
IF TYPE('cAlias') != 'C'	
   cAlias = SELECT()	
ENDIF

*: If an empty alias was passed, use the current workarea
IF EMPTY('cAlias') 					
   cAlias = SELECT()				
ENDIF
	
DO CASE
   CASE NOT USED(cAlias)	
   *: Alias is not in use - Quit.
      RETURN .F.

   CASE '.DBF' $ dbf(ALIAS(cAlias)) 
   *: Not a real cursor, but a filter - Quit.
      RETURN .F.
ENDCASE
		
*: Variables

TempArea = SELECT(1)	  && Empty cAlias for temporary use
CurAlias = ALIAS(cAlias)  && Alias of cAlias

USE dbf(cAlias) AGAIN IN (TempArea)
USE dbf(TempArea) AGAIN ALIAS (CurAlias) IN (cAlias)
USE IN (TempArea)
David.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform