Subject can i trim (or upper) value in check constraint ?
Author Kamlesh
Thanks For Reply

can i trim (or upper) value in check constraint ?

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.

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

the problem is when i test it in normal application it works well, but with
fb value remains unchanged, actually with fb function works with out any
error but value of field remains unchanged.

it seems it is not updating the parameter value (passes to it by reference
?)

// my udf code

Function TrimProper(ACString:PChar):Integer; cdecl; export;
Var
i,vLen:Integer;
Begin
Result := 0;
i:=Strlen(ACString);
If (ACString <> Nil) And (ACString[0] <> #0) Then
Begin
vLen := StrLen(ACString);
i := 0;
While (i < vLen) And (ACString[i] = ' ') Do Inc(i);

StrMove(ACString,@ACString[i],vLen-i);
ACString[vLen-i] := #0;

vLen := vLen-i;

If vLen <= 0 Then Exit;

StrLower(ACString);

If ACString[0] in ['a'..'z'] Then Dec(ACString[0], Ord('a') -
Ord('A'));

i := 1;

While i < vLen Do
Begin
If (ACString[i-1] = ' ') And (ACString[i] in ['a'..'z']) Then
Dec(ACString[i], Ord('a') - Ord('A'));
Inc(i);
End;

i := vLen-1;

While (i > 0) And (ACString[i] = ' ') Do Dec(i);

ACString[i+1] := #0;
Result := i+1;
Kmsg(ACString);
End;
End;

// following works without any error, but does not change value

CREATE DOMAIN CODENAME VARCHAR(50) CHECK (TrimProper(Value) > 0);

even if i try to update field value in triggers it remains unchanged

// insert or update trigger code

vlen = TrimProper(New.GroupCode);

New.GroupCode remains unchanged.(even if i modify the same buffer).


any idea


Thanks
Kamlesh