Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Deleted rows
Message
From
05/10/2005 10:09:36
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
05/10/2005 07:48:31
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Environment versions
Database:
MS SQL Server
Miscellaneous
Thread ID:
01056195
Message ID:
01056257
Views:
24
This message has been marked as the solution to the initial question of the thread.
>Hi
>
>I wish to retreive deleted rows from a remote database (eg SQL Server or VFP).
>
>Can I do this via a view?
>
>If not what would the passthrough SQL be?
>
>Regards
>Geoff Scott

Geoff,
It depends on server. If from VFP then using SPT you could "set deleted off" command and query for deleted(). ie:
lcDBC = 'd:\cetin\ddrive\temp\testdata.dbc'
lcConStr = 'Driver={Microsoft Visual FoxPro Driver};UID=;PWD=;'+;
  'SourceDB='+m.lcDBC+';SourceType=DBC;Exclusive=No;Collate=Machine;'

cSQLSelect1 = "select cust_id,company,contact," +;
  "iif(deleted(),'Deleted',space(len('Deleted'))) as DelStat from customer"

cSQLSelect2 = "select cust_id,company,contact" +;
  " from customer where DELETED()"

lnHandle = Sqlstringconnect(m.lcConStr)
? m.lnHandle
If lnHandle > 0
  SQLExec(m.lnHandle,'set deleted off')
  SQLExec(m.lnHandle,m.cSQLSelect1,'myResult1')
  SQLExec(m.lnHandle,m.cSQLSelect2,'myResult2')
  SQLDisconnect(m.lnHandle)
  Select myResult1
  Browse
  Select myResult2
  Browse
Endif
In SQL server things are a little different. You should get it from within a trigger if you really need, after that deleted records are gone. ie:
lcDatabaseName = "myTestData"
* Create Db and borrow data from Northwind
TEXT to m.lcSQLDbCreate textmerge noshow
IF EXISTS (SELECT name FROM master.dbo.sysdatabases
	WHERE name = N'<<m.lcDataBaseName>>')
	DROP DATABASE [<<m.lcDataBaseName>>]

Create Database [<<m.lcDataBaseName>>]
ENDTEXT

TEXT TO m.lcBorrowData TEXTMERGE noShow
SELECT * Into [<<m.lcDataBaseName>>]..[Customers]
		from [NorthWind]..[Customers]
ENDTEXT

TEXT TO m.lcTrigger TEXTMERGE noshow
CREATE TRIGGER delTrigger ON [Customers]
 For Delete as
 	SELECT * FROM deleted
ENDTEXT

*Delete
TEXT TO m.lcDelete TEXTMERGE noshow
DELETE FROM [<<m.lcDataBaseName>>]..[Customers]
  	where Country like 'U%'
ENDTEXT
* Check records
m.lcSQL = Textmerge('SELECT * from [<<m.lcDataBaseName>>]..[Customers]')

lnHandle = Sqlstringconnect('DRIVER=SQL Server;'+;
  'SERVER=cetin;Trusted_connection=Yes')

SQLExec(m.lnHandle, m.lcSQLDBCreate) && Create db
SQLExec(m.lnHandle, m.lcBorrowData) && Get test data
SQLExec(m.lnHandle, Textmerge('USE [<<m.lcDataBaseName>>]')) && Make it default db
SQLExec(m.lnHandle, m.lcTrigger) && Create trigger
SQLExec(m.lnHandle, m.lcSQL,'crsBefDel') && show records before deletion
SQLExec(m.lnHandle, m.lcDelete,'crsDelList') && Delete and get deleted - same batch
SQLExec(m.lnHandle, m.lcSQL,'crsAftDel') && Records after deletion
SQLDisconnect(m.lnHandle)


Select crsBefDel
Browse Title 'Before delete'
Select crsDelList
Browse Title 'Deleted records'
Select crsAftDel
Browse Title 'After delete'
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