473,224 Members | 1,598 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,224 software developers and data experts.

help with TCL function

Hello everybody,

Someone helped me earlier with this TCL trigger function:

create or replace function tlow() returns trigger as '
set NEW($1) [string tolower $NEW($1)]
return [array get NEW]'
language 'pltcl';

I use it to force lowercase of values inserted in the db. There is one
problem though, if the parameter is absent, the function will give an
error message. I would like it to rather check for null before tolower
is applicated. In semicode:

if ($1 <> NULL) {
set NEW($1) [string tolower $NEW($1)]
}
return [array get NEW]'

but I have no idea how to do this in TCL. Can somebody please tell me?
Thanks a lot!

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 11 '05 #1
11 3902
Op 10 Sep 2003 (15:27), schreef Jules Alberts <ju***********@arbodienst-limburg.nl>:
Hello everybody,

Someone helped me earlier with this TCL trigger function:

create or replace function tlow() returns trigger as '
set NEW($1) [string tolower $NEW($1)]
return [array get NEW]'
language 'pltcl';

I use it to force lowercase of values inserted in the db. There is one
problem though, if the parameter is absent, the function will give an
error message. I would like it to rather check for null before tolower
is applicated. In semicode:

if ($1 <> NULL) {
set NEW($1) [string tolower $NEW($1)]
}
return [array get NEW]'

but I have no idea how to do this in TCL. Can somebody please tell me?
Thanks a lot!


I found argisnull, but I can't run it, apparently it cannot be used in
triggers :-( Does anybody know a solutions for this problem? Thanks!

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 11 '05 #2
On Wednesday 10 September 2003 14:27, Jules Alberts wrote:

I use it to force lowercase of values inserted in the db. There is one
problem though, if the parameter is absent, the function will give an
error message. I would like it to rather check for null before tolower
is applicated. In semicode:

if ($1 <> NULL) {
set NEW($1) [string tolower $NEW($1)]
}
return [array get NEW]'

but I have no idea how to do this in TCL. Can somebody please tell me?
Thanks a lot!


According to the manuals:

$NEW

An associative array containing the values of the new table row for
INSERT/UPDATE actions, or empty for DELETE. The array is indexed by field
name. Fields that are NULL will not appear in the array!

Is that any use?

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 11 '05 #3
On Wednesday 10 September 2003 14:27, Jules Alberts wrote:

I use it to force lowercase of values inserted in the db. There is one
problem though, if the parameter is absent, the function will give an
error message. I would like it to rather check for null before tolower
is applicated. In semicode:

if ($1 <> NULL) {
set NEW($1) [string tolower $NEW($1)]
}
return [array get NEW]'

but I have no idea how to do this in TCL. Can somebody please tell me?
Thanks a lot!


According to the manuals:

$NEW

An associative array containing the values of the new table row for
INSERT/UPDATE actions, or empty for DELETE. The array is indexed by field
name. Fields that are NULL will not appear in the array!

Is that any use?

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 11 '05 #4
ljb
ju***********@arbodienst-limburg.nl wrote:
Op 10 Sep 2003 (15:27), schreef Jules Alberts <ju***********@arbodienst-limburg.nl>:
Hello everybody,

Someone helped me earlier with this TCL trigger function:

create or replace function tlow() returns trigger as '
set NEW($1) [string tolower $NEW($1)]
return [array get NEW]'
language 'pltcl';

I use it to force lowercase of values inserted in the db. There is one
problem though, if the parameter is absent, the function will give an
error message. I would like it to rather check for null before tolower
is applicated. In semicode:

if ($1 <> NULL) {
set NEW($1) [string tolower $NEW($1)]
}
return [array get NEW]'

but I have no idea how to do this in TCL. Can somebody please tell me?
Thanks a lot!


I found argisnull, but I can't run it, apparently it cannot be used in
triggers :-( Does anybody know a solutions for this problem? Thanks!


I think you're missing something. When you use a Tcl function as a trigger,
any arguments (like $1) are explicitly supplied in the CREATE TRIGGER
command. You either define the trigger to call the function with a
constant argument or not; there is no issue of NULL here or an optional
argument. Show us your CREATE TRIGGER command.
Nov 11 '05 #5
ljb
ju***********@arbodienst-limburg.nl wrote:
Op 10 Sep 2003 (15:27), schreef Jules Alberts <ju***********@arbodienst-limburg.nl>:
Hello everybody,

Someone helped me earlier with this TCL trigger function:

create or replace function tlow() returns trigger as '
set NEW($1) [string tolower $NEW($1)]
return [array get NEW]'
language 'pltcl';

I use it to force lowercase of values inserted in the db. There is one
problem though, if the parameter is absent, the function will give an
error message. I would like it to rather check for null before tolower
is applicated. In semicode:

if ($1 <> NULL) {
set NEW($1) [string tolower $NEW($1)]
}
return [array get NEW]'

but I have no idea how to do this in TCL. Can somebody please tell me?
Thanks a lot!


I found argisnull, but I can't run it, apparently it cannot be used in
triggers :-( Does anybody know a solutions for this problem? Thanks!


I think you're missing something. When you use a Tcl function as a trigger,
any arguments (like $1) are explicitly supplied in the CREATE TRIGGER
command. You either define the trigger to call the function with a
constant argument or not; there is no issue of NULL here or an optional
argument. Show us your CREATE TRIGGER command.
Nov 11 '05 #6
Op 11 Sep 2003 (0:45), schreef ljb <lb****@mindspring.com>:
I think you're missing something. When you use a Tcl function as a
trigger, any arguments (like $1) are explicitly supplied in the CREATE
TRIGGER command. You either define the trigger to call the function with
a constant argument or not; there is no issue of NULL here or an
optional argument. Show us your CREATE TRIGGER command.


-- This is the function

create or replace function tlow() returns trigger as '
set NEW($1) [string tolower $NEW($1)]
return [array get NEW]'
language 'pltcl';

-- Now the table on which I use it

create table bedrijf (
code varchar unique not null check (code <> ''),
kvk_nummer varchar,
) with oids;

-- And two triggers

create trigger tlow
before insert or update
on bedrijf for each row
execute procedure tlow('code');

create trigger tlowkvk_nummer
before insert or update
on bedrijf for each row
execute procedure tlow('kvk_nummer');

--

As you can see, the column kvk_nummer is allowed to be null. But /if/
it gets a value, that value should be converted to lowercase. So a sql
statement like this should be allowed:

insert into bedrijf (code) values ('FUBAR');

However this will fail because the trigger tlowkvk_nummer will call
tlow() without an argument. So I want to program tlow() defensively,
after all my DB logic should work, independenlty of anything that goes
on in the frontend.

I think it's a valid thing to expect from a DB or programming language.
Workarounds could be traversing all the frontend code to make sure no
NULL values are used or not using this kind of constraint at all. Not
really options IMO.

Thanks for any help!

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 11 '05 #7
Am Donnerstag, 11. September 2003 08:59 schrieben Sie:
Op 11 Sep 2003 (0:45), schreef ljb <lb****@mindspring.com>: .... -- This is the function

create or replace function tlow() returns trigger as '
set NEW($1) [string tolower $NEW($1)]
return [array get NEW]'
language 'pltcl';

....

You could either test with info exists or catch the error
create or replace function tlow() returns trigger as '
if [info exists NEW($1)] {
set NEW($1) [string tolower $NEW($1)]
}
return [array get NEW]'
language 'pltcl';

create or replace function tlow() returns trigger as '
catch {
set NEW($1) [string tolower $NEW($1)]
}
return [array get NEW]'
language 'pltcl';

--
Rolf Jentsch
Produktentwicklung EDV-Anwendungen für Mitglieder
ElectronicPartner GmbH & Co. KG
Düsseldorf
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 11 '05 #8
Op 11 Sep 2003 (0:45), schreef ljb <lb****@mindspring.com>:
I think you're missing something. When you use a Tcl function as a
trigger, any arguments (like $1) are explicitly supplied in the CREATE
TRIGGER command. You either define the trigger to call the function with
a constant argument or not; there is no issue of NULL here or an
optional argument. Show us your CREATE TRIGGER command.


-- This is the function

create or replace function tlow() returns trigger as '
set NEW($1) [string tolower $NEW($1)]
return [array get NEW]'
language 'pltcl';

-- Now the table on which I use it

create table bedrijf (
code varchar unique not null check (code <> ''),
kvk_nummer varchar,
) with oids;

-- And two triggers

create trigger tlow
before insert or update
on bedrijf for each row
execute procedure tlow('code');

create trigger tlowkvk_nummer
before insert or update
on bedrijf for each row
execute procedure tlow('kvk_nummer');

--

As you can see, the column kvk_nummer is allowed to be null. But /if/
it gets a value, that value should be converted to lowercase. So a sql
statement like this should be allowed:

insert into bedrijf (code) values ('FUBAR');

However this will fail because the trigger tlowkvk_nummer will call
tlow() without an argument. So I want to program tlow() defensively,
after all my DB logic should work, independenlty of anything that goes
on in the frontend.

I think it's a valid thing to expect from a DB or programming language.
Workarounds could be traversing all the frontend code to make sure no
NULL values are used or not using this kind of constraint at all. Not
really options IMO.

Thanks for any help!

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 11 '05 #9
Am Donnerstag, 11. September 2003 08:59 schrieben Sie:
Op 11 Sep 2003 (0:45), schreef ljb <lb****@mindspring.com>: .... -- This is the function

create or replace function tlow() returns trigger as '
set NEW($1) [string tolower $NEW($1)]
return [array get NEW]'
language 'pltcl';

....

You could either test with info exists or catch the error
create or replace function tlow() returns trigger as '
if [info exists NEW($1)] {
set NEW($1) [string tolower $NEW($1)]
}
return [array get NEW]'
language 'pltcl';

create or replace function tlow() returns trigger as '
catch {
set NEW($1) [string tolower $NEW($1)]
}
return [array get NEW]'
language 'pltcl';

--
Rolf Jentsch
Produktentwicklung EDV-Anwendungen für Mitglieder
ElectronicPartner GmbH & Co. KG
Düsseldorf
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 11 '05 #10
Ok you can user the info exists function that is part of TCL

i.e. if { [info exists NEW($1)] } {

or if 1 is the problem do
if { [info exists 1] } {

This will allow you to determine if it exists.

If you want to see what variables exist at this level elog [info vars] and
it will show you all variables currently accessable

Also you can array names or array get the contents or the NEW array then
foreach id value (if using array get) you can put them lower.

HTH
Darren

On Thu, 11 Sep 2003, Jules Alberts wrote:
Op 11 Sep 2003 (0:45), schreef ljb <lb****@mindspring.com>:
I think you're missing something. When you use a Tcl function as a
trigger, any arguments (like $1) are explicitly supplied in the CREATE
TRIGGER command. You either define the trigger to call the function with
a constant argument or not; there is no issue of NULL here or an
optional argument. Show us your CREATE TRIGGER command.


-- This is the function

create or replace function tlow() returns trigger as '
set NEW($1) [string tolower $NEW($1)]
return [array get NEW]'
language 'pltcl';

-- Now the table on which I use it

create table bedrijf (
code varchar unique not null check (code <> ''),
kvk_nummer varchar,
) with oids;

-- And two triggers

create trigger tlow
before insert or update
on bedrijf for each row
execute procedure tlow('code');

create trigger tlowkvk_nummer
before insert or update
on bedrijf for each row
execute procedure tlow('kvk_nummer');

--

As you can see, the column kvk_nummer is allowed to be null. But /if/
it gets a value, that value should be converted to lowercase. So a sql
statement like this should be allowed:

insert into bedrijf (code) values ('FUBAR');

However this will fail because the trigger tlowkvk_nummer will call
tlow() without an argument. So I want to program tlow() defensively,
after all my DB logic should work, independenlty of anything that goes
on in the frontend.

I think it's a valid thing to expect from a DB or programming language.
Workarounds could be traversing all the frontend code to make sure no
NULL values are used or not using this kind of constraint at all. Not
really options IMO.

Thanks for any help!

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html


--
Darren Ferguson
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 11 '05 #11
Ok you can user the info exists function that is part of TCL

i.e. if { [info exists NEW($1)] } {

or if 1 is the problem do
if { [info exists 1] } {

This will allow you to determine if it exists.

If you want to see what variables exist at this level elog [info vars] and
it will show you all variables currently accessable

Also you can array names or array get the contents or the NEW array then
foreach id value (if using array get) you can put them lower.

HTH
Darren

On Thu, 11 Sep 2003, Jules Alberts wrote:
Op 11 Sep 2003 (0:45), schreef ljb <lb****@mindspring.com>:
I think you're missing something. When you use a Tcl function as a
trigger, any arguments (like $1) are explicitly supplied in the CREATE
TRIGGER command. You either define the trigger to call the function with
a constant argument or not; there is no issue of NULL here or an
optional argument. Show us your CREATE TRIGGER command.


-- This is the function

create or replace function tlow() returns trigger as '
set NEW($1) [string tolower $NEW($1)]
return [array get NEW]'
language 'pltcl';

-- Now the table on which I use it

create table bedrijf (
code varchar unique not null check (code <> ''),
kvk_nummer varchar,
) with oids;

-- And two triggers

create trigger tlow
before insert or update
on bedrijf for each row
execute procedure tlow('code');

create trigger tlowkvk_nummer
before insert or update
on bedrijf for each row
execute procedure tlow('kvk_nummer');

--

As you can see, the column kvk_nummer is allowed to be null. But /if/
it gets a value, that value should be converted to lowercase. So a sql
statement like this should be allowed:

insert into bedrijf (code) values ('FUBAR');

However this will fail because the trigger tlowkvk_nummer will call
tlow() without an argument. So I want to program tlow() defensively,
after all my DB logic should work, independenlty of anything that goes
on in the frontend.

I think it's a valid thing to expect from a DB or programming language.
Workarounds could be traversing all the frontend code to make sure no
NULL values are used or not using this kind of constraint at all. Not
really options IMO.

Thanks for any help!

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html


--
Darren Ferguson
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 11 '05 #12

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

Similar topics

7
by: Alan Bashy | last post by:
Please, guys, In need help with this. It is due in the next week. Please, help me to implement the functions in this programm especially the first three constructor. I need them guys. Please, help...
2
by: Jackson Yap | last post by:
can someone kind enough to help me look at the attached html and js file? Why is it that the javascript menu could not work at www.apchosting.net but could work at...
5
by: Craig Keightley | last post by:
Please help, i have attached my page which worksin IE but i cannnot get the drop down menu to fucntion in firefox. Any one have any ideas why? Many Thanks Craig ...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
1
by: Michael D. Reed | last post by:
I am using the help class to display a simple help file. I generated the help file using Word and saving it as a single page Web page (.mht extension). I show the help file with the following...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
4
by: Stef Mientki | last post by:
I'm making special versions of existing functions, and now I want the help-text of the newly created function to exists of 1. an extra line from my new function 2. all the help text from the old...
22
by: Amali | last post by:
I'm newdie in c programming. this is my first project in programming. I have to write a program for a airline reservation. this is what i have done yet. but when it runs it shows the number of...
1
by: Bob | last post by:
Hi, Hope you can help me with this one. I'm at my wits end. I'm trying to create an intelligent edit-box like the excellent "Customer" one at the URL: ...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.