pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedError handling in pltcl
3+ messages / 2 participants
[nested] [flat]
* Error handling in pltcl
@ 2005-04-18 03:50 Dinesh Pandey <dpandey@secf.com>
2005-04-18 04:32 ` Re: Error handling in pltcl Michael Fuhr <mike@fuhr.org>
0 siblings, 1 reply; 3+ messages in thread
From: Dinesh Pandey @ 2005-04-18 03:50 UTC (permalink / raw)
To: pgsql-sql
Hi,
Can any one tell me how to handle error in PL/TCL language.
On Error/Exception,
In the exception block I want to call a FUNCTION (written in PL/pgSQL).
Thanks
Dinesh Pandey
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Error handling in pltcl
2005-04-18 03:50 Error handling in pltcl Dinesh Pandey <dpandey@secf.com>
@ 2005-04-18 04:32 ` Michael Fuhr <mike@fuhr.org>
2005-04-18 04:40 ` Re: Error handling in pltcl Dinesh Pandey <dpandey@secf.com>
0 siblings, 1 reply; 3+ messages in thread
From: Michael Fuhr @ 2005-04-18 04:32 UTC (permalink / raw)
To: Dinesh Pandey <dpandey@secf.com>; +Cc: pgsql-sql
On Mon, Apr 18, 2005 at 09:20:37AM +0530, Dinesh Pandey wrote:
>
> Can any one tell me how to handle error in PL/TCL language.
What kind of error? Have you tried using catch?
> On Error/Exception,
> In the exception block I want to call a FUNCTION (written in PL/pgSQL).
You could use spi_exec to SELECT the function.
If you still have trouble, then please post a simple example that
shows what you're trying to do.
BTW, pgsql-sql probably isn't the best place to ask PL/Tcl questions
since its description is "Discussion for users on SQL related
matters." pgsql-general or pgsql-interfaces might be more appropriate.
--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Error handling in pltcl
2005-04-18 03:50 Error handling in pltcl Dinesh Pandey <dpandey@secf.com>
2005-04-18 04:32 ` Re: Error handling in pltcl Michael Fuhr <mike@fuhr.org>
@ 2005-04-18 04:40 ` Dinesh Pandey <dpandey@secf.com>
0 siblings, 0 replies; 3+ messages in thread
From: Dinesh Pandey @ 2005-04-18 04:40 UTC (permalink / raw)
To: 'Michael Fuhr' <mike@fuhr.org>; +Cc: pgsql-sql
I have attached below an e-mail program.
I want to log messages into a table from a function written in 'plpgsql'
whenever any exception occurs (like unable to connect/invalid email etc..)
Pls update the code attached below
Thanks
Dinesh Pandey
========================
CREATE OR REPLACE FUNCTION PGMAIL(text, text, text, text, text, text)
RETURNS INT4 AS '
set mailfrom $1
set mailto $2
set mailcc $3
set mailserver $4
set mailsubject $5
set mailmessage $6
# Mail Server
set myHost $mailserver
# Mail Server SMTP Port
set myPort 25
set mySock [socket $myHost $myPort]
# Mail To Address
set toemailaddress_start [string first "<" $mailto]
if {$toemailaddress_start != -1} {
set toemailaddress_finish [string first ">" $mailto]
set toemailaddress_start [expr $toemailaddress_start + 1]
set toemailaddress_finish [expr $toemailaddress_finish - 1]
set toemailaddress [string range $mailto
$toemailaddress_start $toemailaddress_finish]
} else {
set toemailaddress $mailto
}
# Mail Cc Address
set ccemailaddress_start [string first "<" $mailcc]
if {$ccemailaddress_start != -1} {
set ccemailaddress_finish [string first ">" $mailcc]
set ccemailaddress_start [expr $ccemailaddress_start + 1]
set ccemailaddress_finish [expr $ccemailaddress_finish - 1]
set ccemailaddress [string range $mailcc
$toemailaddress_start $ccemailaddress_finish]
} else {
set ccemailaddress $mailcc
}
# Mail From Address
set fromemailaddress_start [string first "<" $mailfrom]
if {$fromemailaddress_start != -1} {
set fromemailaddress_finish [string first ">" $mailfrom]
set fromemailaddress_start [expr $fromemailaddress_start +
1]
set fromemailaddress_finish [expr $fromemailaddress_finish -
1]
set fromemailaddress [string range $mailfrom
$fromemailaddress_start $fromemailaddress_finish]
} else {
set fromemailaddress $mailfrom
}
fileevent $mySock writable [list svcHandler $mySock]
fconfigure $mySock -buffering none
puts $mySock "helo $mailserver"
gets $mySock name
puts $mySock "mail from: $fromemailaddress"
gets $mySock name
puts $mySock "rcpt to: $toemailaddress"
gets $mySock name
puts $mySock "rcpt cc: $ccemailaddress"
gets $mySock name
puts $mySock "data"
gets $mySock name
puts $mySock "To: $mailto"
puts $mySock "Cc: $mailcc"
puts $mySock "From: $mailfrom"
puts $mySock "Subject: $mailsubject"
puts $mySock ""
puts $mySock "$mailmessage"
puts $mySock "."
gets $mySock name
close $mySock
return 1'
#Exception handling
LANGUAGE 'pltclu';
========================
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2005-04-18 04:40 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-04-18 03:50 Error handling in pltcl Dinesh Pandey <dpandey@secf.com>
2005-04-18 04:32 ` Michael Fuhr <mike@fuhr.org>
2005-04-18 04:40 ` Dinesh Pandey <dpandey@secf.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox