473,385 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

CREATE TRIGGER -> writing to file???

FM
Hello:

I want to create a trigger wich performs a write-action to a text file.
I'm intending to create it with:
CREATE TRIGGER TR_ALARMA_TSPRE
AFTER INSERT ON T_ALARMA_TS
FOR EACH STATEMENT
BEGIN ATOMIC
VALUES (SELECT a1,a2,a3 FROM T_TABLE >c:\TRIGGERTEST.LOG);
END

It is possible to do it???

Many thanks in advance,
Felix

Aug 28 '06 #1
8 7157
FM wrote:
Hello:

I want to create a trigger wich performs a write-action to a text file.
I'm intending to create it with:
CREATE TRIGGER TR_ALARMA_TSPRE
AFTER INSERT ON T_ALARMA_TS
FOR EACH STATEMENT
BEGIN ATOMIC
VALUES (SELECT a1,a2,a3 FROM T_TABLE >c:\TRIGGERTEST.LOG);
END
Simply define a C UDF that does the job.
I think there samples in sqllib/samples/c and IIRC developerWorks DB2
has some source code as well.

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Aug 28 '06 #2
Hi!

Go to
http://www-128.ibm.com/developerwork...0302izuha.html
There you will find put_line function that we use a lot for writing stuff
into a file from procedures.
The problem with put_line is that we experience random crashes of the
put_line DLL itself. It can work for months without a problem. And also the
problem is that there is no 64-bit version of it. And I didn't find a way
how to compile it into 64-bit version using MinGW :((( Please let me know
if you have any experience is this field.
So we are using the 32-bit version of put_line on 64-bit version DB2 like a
FENCED function. The problem with this is that after a while we have to
restart the instance, since it seem that put_line takes too much resources
and it doesn't want to cooperate anymore. :(((

My take on this is: It is great as start, but if you know how to write your
own C code do it yourself (and then share the code with me :))) ).
I've also thought about writing a little Java stored procedure for this, but
I'm not wuite sure about the performance of those. I'll have to do more
tests.

Best regards,
Kovi

FM wrote:
Hello:

I want to create a trigger wich performs a write-action to a text file.
I'm intending to create it with:
CREATE TRIGGER TR_ALARMA_TSPRE
AFTER INSERT ON T_ALARMA_TS
FOR EACH STATEMENT
BEGIN ATOMIC
VALUES (SELECT a1,a2,a3 FROM T_TABLE >c:\TRIGGERTEST.LOG);
END

It is possible to do it???

Many thanks in advance,
Felix
--
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
| Gregor Kovac | Gr**********@mikropis.si |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| In A World Without Fences Who Needs Gates? |
| Experience Linux. |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Aug 31 '06 #3
Gregor Kovač wrote:
Hi!

Go to
http://www-128.ibm.com/developerwork...0302izuha.html
There you will find put_line function that we use a lot for writing stuff
into a file from procedures.
The problem with put_line is that we experience random crashes of the
put_line DLL itself.
I had a look at the code and it might be that you run into a buffer overflow
that subsequently causes the crash. Another problem may be that null
indicators are incorrectly handled. The code just isn't robust enough and
should be reworked quite a bit... Maybe this one is more stable:
http://tinyurl.com/nfxs9

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Aug 31 '06 #4
Knut Stolze wrote:
Gregor Kovač wrote:
>Hi!

Go to
http://www-128.ibm.com/developerwork...0302izuha.html
>There you will find put_line function that we use a lot for writing stuff
into a file from procedures.
The problem with put_line is that we experience random crashes of the
put_line DLL itself.

I had a look at the code and it might be that you run into a buffer
overflow
that subsequently causes the crash. Another problem may be that null
indicators are incorrectly handled. The code just isn't robust enough and
should be reworked quite a bit... Maybe this one is more stable:
http://tinyurl.com/nfxs9
Thanks, I'll give it a try.
I've also written a Java stored procedure that writes to a file, but is five
times slower than the C version (put_line) :((

Best regards,
Kovi
--
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
| Gregor Kovac | Gr**********@mikropis.si |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| In A World Without Fences Who Needs Gates? |
| Experience Linux. |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Sep 1 '06 #5
Knut Stolze wrote:
Gregor Kovač wrote:
>Hi!

Go to
http://www-128.ibm.com/developerwork...0302izuha.html
>There you will find put_line function that we use a lot for writing stuff
into a file from procedures.
The problem with put_line is that we experience random crashes of the
put_line DLL itself.

I had a look at the code and it might be that you run into a buffer
overflow
that subsequently causes the crash. Another problem may be that null
indicators are incorrectly handled. The code just isn't robust enough and
should be reworked quite a bit... Maybe this one is more stable:
http://tinyurl.com/nfxs9
I've seen that you are using SCRATCHPAD in your functions. I'm wondering if
I use the functions in my stored procedures will they work correctly if I
run them at the same time ?

--
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
| Gregor Kovac | Gr**********@mikropis.si |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| In A World Without Fences Who Needs Gates? |
| Experience Linux. |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Sep 1 '06 #6
Gregor Kovač wrote:
I've seen that you are using SCRATCHPAD in your functions. I'm wondering
if I use the functions in my stored procedures will they work correctly if
I run them at the same time ?
Yes, they will. Each function invocation has its own scratchpad. Even if
you use the same function multiple times in the same SQL statements, the
scratchpads will not be shared between the occurrences. Of course, the
same applies to function invocations in different SQL statements.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Sep 1 '06 #7
FM

Knut Stolze wrote:
Gregor Kovac wrote:
Hi!

Go to
http://www-128.ibm.com/developerwork...0302izuha.html
There you will find put_line function that we use a lot for writing stuff
into a file from procedures.
The problem with put_line is that we experience random crashes of the
put_line DLL itself.

I had a look at the code and it might be that you run into a buffer overflow
that subsequently causes the crash. Another problem may be that null
indicators are incorrectly handled. The code just isn't robust enough and
should be reworked quite a bit... Maybe this one is more stable:
http://tinyurl.com/nfxs9

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Hello Mr.Stolze:
Thank you for this samples wich are very helpfully.
One question: Is there a posibility to dump the results in multiple
lines?

Thank you one more time for your help,
Flix Manresa Madrona
Bases de Datos (DB2/UDB)
Ciudad del Grupo Santander

Sep 4 '06 #8
FM wrote:
>
Knut Stolze wrote:
>Gregor Kovac wrote:
Hi!

Go to
http://www-128.ibm.com/developerwork...0302izuha.html
There you will find put_line function that we use a lot for writing
stuff into a file from procedures.
The problem with put_line is that we experience random crashes of the
put_line DLL itself.

I had a look at the code and it might be that you run into a buffer
overflow
that subsequently causes the crash. Another problem may be that null
indicators are incorrectly handled. The code just isn't robust enough
and
should be reworked quite a bit... Maybe this one is more stable:
http://tinyurl.com/nfxs9

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Hello Mr.Stolze:
Thank you for this samples wich are very helpfully.
One question: Is there a posibility to dump the results in multiple
lines?
Yes, there is. You can do whatever you want in the file-writing function.
So you can insert linebreaks where you like. (The current implementation
adds a line break after each function call.)

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Sep 5 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Darren | last post by:
Hello, I have some 'CREATE TRIGGER' definitions that work when cut/pasted into SQL*Plus worksheet and execute separately but fail with a 'trigger created with compilation errors' when executed...
1
by: Jack | last post by:
I created a trigger in the "source table" that will "feed" and second table. The trigger is as follows: CREATE TRIGGER ON dbo.FromUPS FOR INSERT AS Declare @Count int Select @Count =...
1
by: efinney | last post by:
Hi, I'm a newbie to sql server and this may be a really dumb question for some you. I'm trying to find some examples of sql server triggers that will set columns (e.g. the created and modified...
1
by: Ling Xiaoyu | last post by:
Hello there. Can anybody help me with Postgresql triggers? what I need is a trigger which update value of field "tables_rows.total_rows" to rows count of table "zzz" if I insert new row in table...
1
by: Barbara Lindsey | last post by:
I am a postgres newbie. I am trying to create a trigger that will put a copy of a record into a backup table before update or delete. As I understand it, in order to do this I must have a...
0
by: Yogesh | last post by:
Hello Everyone I have to create Oracle tables in my application on the fly, which have an Autonumber field. So, everytime I create a table, I have to create a corresponding sequence and trigger...
1
by: sandi | last post by:
Please Advice... I need to create SqlServer2005 trigger from C# form. so all my trigger can re-create if i push one button on my app.... i need to know how i create and delete trigger from c#...
3
by: satish | last post by:
hi, CAn i have one trigger for both Update and Delete Delete Trigger --------------------- create Trigger on . for delete as begin insert into z_user_log select * from deleted end
2
by: lakuma | last post by:
Hi, I have a table called A (say) with columns called name, place, animal and thing. I would want to write an on insert trigger on this table, which would create a table with the name of the...
3
by: Andrea MF | last post by:
Hi all, i have a problem when creating a trigger on DB2 ver 7.2 on WINDOWS. I have two tables MOVIMAG and BARCODE, the trigge when INSERT INTO MOVIMAG will be UPDATE a MOVIMAG field BARCODE...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.