dbTalk Databases Forums  

Re: Triggers for backing up rows - ASA7.0.4 win32

sybase.public.sqlanywhere.general sybase.public.sqlanywhere.general


Discuss Re: Triggers for backing up rows - ASA7.0.4 win32 in the sybase.public.sqlanywhere.general forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Breck Carter [TeamSybase]
 
Posts: n/a

Default Re: Triggers for backing up rows - ASA7.0.4 win32 - 12-04-2003 , 04:22 PM






OK, I've read it twice and still don't see a question asked

Breck May Be Having A Senior Moment

On 4 Dec 2003 08:29:55 -0800, "Russell J Morgan"
<russell (AT) careervision (DOT) co.uk> wrote:

Quote:
ASA7.0.4 WIN32

Hello,

I'm trying to create a trigger that converts a before delete on a row into a
valid SQL statement. The SQL statement would return the delete action made
on the row. So far, I have come up with a trigger that fakes up an SQL
insert to return the record if delete. I store the sql statement in text
data type in a table somewhere. At the moment the statement is printed on
screen

alter trigger DBA.Test_archive before delete order 1 on
DBA.MASTER
referencing old as old_name
for each row
begin

declare SQLVar char(128);
set SQLVar=(select LIST('"' || Syscolumn.column_name || '"') as
Column_list from systable join
syscolumn on systable.table_id = syscolumn.table_id where table_name =
'MASTER');
print 'INSERT INTO MASTER(' || SQLVar || ')\x0A'+'VALUES(' ||
old_name."Ref no" || ', ''' || Old_name.name || ''');'
end

TIA

Russell J Morgan

--
bcarter (AT) risingroad (DOT) com
Mobile and Distributed Enterprise Database Applications
www.risingroad.com


Reply With Quote
  #2  
Old   
Russell J Morgan
 
Posts: n/a

Default Re: Triggers for backing up rows - ASA7.0.4 win32 - 12-11-2003 , 05:52 AM






Hi,



Sorry for my ambiguity.



Essentially I was trying to capture the row before it is deleted. I
construct an INSERT Statement around the deleted row, which can be stored
into separate table for deleted transactions as text. This keeps an archive
of any deleted rows. If the customer ever wants to recover the deleted
transaction we can return the record without much effort. I can do all of
this, however I was trying to make my life a lot easier by referencing the
whole row as one variable. This would essentially make my life a lot easier
when in comes to constructing the SQL statement for returning the record if
so desired.



So my question is: Using a trigger, is there a container for holding the
whole row that I may collect and construct an SQL statement around it.



Thanks



Reply With Quote
  #3  
Old   
Breck Carter [TeamSybase]
 
Posts: n/a

Default Re: Triggers for backing up rows - ASA7.0.4 win32 - 12-11-2003 , 06:49 AM



No, there isn't. If you were willing to create "shadow tables"
(perhaps with an additional timestamp column added to the primary key)
you could insert the deleted rows in a statement-based after delete
trigger via a simple INSERT SELECT, as in...

INSERT shadow_xxx
SELECT CURRENT TIMESTAMP,
deleted_xxx.*
FROM deleted_xxx;

Another possibility is to ask for the following feature, in the
product_futures_discussion newsgroup: Allow the UNLOAD SELECT
statement to put the resulting formatted string data into a local LONG
VARCHAR variable as well as an external file. Then you could do what
you want with the string.

Breck

On 11 Dec 2003 03:52:21 -0800, "Russell J Morgan"
<russell (AT) careervision (DOT) co.uk> wrote:

Quote:
Hi,



Sorry for my ambiguity.



Essentially I was trying to capture the row before it is deleted. I
construct an INSERT Statement around the deleted row, which can be stored
into separate table for deleted transactions as text. This keeps an archive
of any deleted rows. If the customer ever wants to recover the deleted
transaction we can return the record without much effort. I can do all of
this, however I was trying to make my life a lot easier by referencing the
whole row as one variable. This would essentially make my life a lot easier
when in comes to constructing the SQL statement for returning the record if
so desired.



So my question is: Using a trigger, is there a container for holding the
whole row that I may collect and construct an SQL statement around it.



Thanks

--
bcarter (AT) risingroad (DOT) com
Mobile and Distributed Enterprise Database Applications
www.risingroad.com


Reply With Quote
  #4  
Old   
Russell J Morgan
 
Posts: n/a

Default Re: Triggers for backing up rows - ASA7.0.4 win32 - 12-18-2003 , 04:12 AM



ASA7.04 win32



Hello,



I have managed to store the deleted record in CSV format in a column long
binary, so that all deleted records can be recovered at any chosen moment. I
'm now working on the recovery procedures. The problem is at the minute,
unfortunately I have to dump out to disk to be able to read it back in. I
suppose that's ok, but it would be nice just to collect the field, and read
it back in without going to the disk.



My current approach: (The field transaction contains the CSV)



Export the contents of "transaction" to d:\data.txt and insert into table1.



Select xp_write_file('d:\data.txt', "transaction") from archive_data where
Pkey = 10;

INPUT INTO TABLE1

from d:\data.txt

format ascii;



Now, with a little formatting on the field I can read the column containing
CSV into a

Variable and all I need to do then is insert it.this is where I'm stuck



Populate SQLVar with the contents of "transaction" stripping off the end of
line characters:



CREATE VARIABLE SQLVar Long Varchar;

SET SQLVar = (Select LEFT("Transaction", LENGTH("Transaction") -2) AS
"Transaction" from archive_data where "pkey" = 5);



--fails here

INSERT INTO TABLE1 VALUES(SQLVar);



--Looks like : INSERT INTO TABLE1 VALUES(1734,'7','Y',,,)

DROP VARIABLE SQLVar;



For the insert to work all the columns need populating where there are null
values.



Any ideas how I can do this



TIA



Russell J Morgan













Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.