Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Replace in non current alias
Message
De
05/07/2013 02:38:32
 
 
À
04/07/2013 23:38:02
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01577831
Message ID:
01577836
Vues:
75
>To my knowledge long time ago
>
>select xyz && current
>replace xyz1.f1 with xyz2.f2 in xyz1 
>* or 
>replace f1 with xyz2.f2 in xyz1 
>
>but "in xyz1" was required in both cases to make it happen in xyz1.
>It turned out at least in VFP9
>
>replace xyz1.f1 with xyz2.f2  && implicit  in xyz1
>
>does work. If I am not mistaken in thinking that "in non_current_alias" was required long time ago, just wondering, when did this change happen ?

There is a "feature" in xBASE where the above code will not work if the record pointer is at EOF( ) in work area "xyz" OR there is no table open in the current work area. Repro code:
SET TALK OFF
CLEAR

CREATE CURSOR Cursor1 ;
	( Col C( 1 ) )

INSERT INTO Cursor1 ;
	( Col ) ;
	VALUES ;
		( "1" )

SELECT ;
	* ;
	FROM Cursor1 ;
	INTO CURSOR Cursor2 ;
	NOFILTER READWRITE

SELECT ;
	* ;
	FROM Cursor1 ;
	INTO CURSOR Cursor3 ;
	NOFILTER READWRITE

REPLACE Cursor2.Col WITH "2" IN Cursor2
REPLACE Cursor3.Col WITH "3" IN Cursor3

* At this point none of the cursors are at EOF( )
SELECT Cursor1

REPLACE Cursor2.Col WITH Cursor3.Col
? "Cursor2.Col: " + Cursor2.Col && "3"

* Set it back:
REPLACE Cursor2.Col WITH "2" IN Cursor2

* Go to EOF( ) in Cursor1:
SKIP 1 IN Cursor1

REPLACE Cursor2.Col WITH Cursor3.Col
? "Cursor2.Col: " + Cursor2.Col && "2"
* Above REPLACE did nothing because currently selected work area is at EOF( ) and IN clause not specified

REPLACE Cursor2.Col WITH Cursor3.Col IN Cursor2
? "Cursor2.Col: " + Cursor2.Col && "3", as "expected"

* Set it back:
REPLACE Cursor2.Col WITH "2" IN Cursor2

* Now select an empty work area:
SELECT 0
REPLACE Cursor2.Col WITH Cursor3.Col && fails, generates Error 52

REPLACE Cursor2.Col WITH Cursor3.Col IN Cursor2
? "Cursor2.Col: " + Cursor2.Col && "3", as "expected"

USE IN Cursor3
USE IN Cursor2
USE IN Cursor1
The EOF( ) "feature" was present in dBASE III/III+ if not earlier. Legend has it that Fox Software, when creating FoxBASE+ thought about fixing it, but they made a conscious decision to retain it because the overriding product requirement was 100% ironclad compatibility with dBASE III+. So, it has persisted in xBASE to this day.

So, with those 2 issues in mind it's an excellent habit to get into to always include the IN clause whenever you use REPLACE.
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform