Subject Re: [firebird-support] can i trim (or upper) value in check constraint ?
Author Helen Borrie
At 09:42 AM 18/03/2004 +0530, you wrote:
>Thanks For Reply
>
>can i trim (or upper) value in check constraint ?

No, you can't use check constraints to change values, only to validate them.

e.g.

create domain trimmedvartext as varchar(20)
check (value = upper(value) and value = f_lrtrim(value))

will throw an exception if someone tries to enter ' eastereggs '


>actually all i want is to trim field value and make it upper or proper and i
>have many fields which required such kind of operation and i want to do
>that( trim it and then checking ) in check constraint at domain level. so
>that i dont have to write same code in all triggers.

You have got it all wrong about check constraints. "Check" means "compare
the input with the predicate and reject it if it doesn't fit". If you want
to modify inputs, you have to use triggers.


>so i wrote following udf which does both
>(as parameter passes by ref, it trims & propers the same CString (buffer) )
>and return length

I'm not going there, sorry. There are already well-tested UDFs that do
those things and I sure don't have time to play about with your UDFs. This
support list is about database stuff, not for debugging your code. Maybe
someone would like to help you with it **off-list**.

^heLen