Subject Re: [firebird-support] Extracting check values from domain
Author Alan J Davies
Thanks Martijn, that works perfectly. I've added some code for anyone
who finds this useful. This extracts the domain name and the
corresponding values. This can then be used anywhere; Delphi, C++ etc.
with a 'Select * from domain_extract'

create or alter procedure domain_extract
returns (
domain_name char(93),
check_values varchar(80))
as
begin
for
select r.RDB$FIELD_NAME,
substr (r.RDB$VALIDATION_SOURCE,position('value in
(',r.RDB$VALIDATION_SOURCE)+9,30)
from RDB$FIELDS r
where r.RDB$VALIDATION_SOURCE is not null
into :domain_name,
:check_values
do
suspend;
end


DOMAIN_NAME CHECK_VALUES
NO_YES ('Y','N'))
SHOP_LOCATION ('W','H'))
TICKET ('W','D','S'))

Alan J Davies
Aldis

On 08/08/2014 18:35, 'Martijn Tonies (Upscene Productions)'
m.tonies@... [firebird-support] wrote:
> Hello Alan,
>
> The domain check constraint is available, however, it is a custom
> written check constraint, like for example:
>
> CREATE DOMAIN ...
> CHECK (
> VALUE IN ('Y', 'N')
> )
>
> This source can be found in the system tables, table RDB$FIELDS
> column RDB$VALIDATION_SOURCE
>
> With regards,
>
> Martijn Tonies
> Upscene Productions
> http://www.upscene.com
>
> Download Database Workbench for Oracle, MS SQL Server, Sybase SQL
> Anywhere, MySQL, InterBase, NexusDB and Firebird!
>
> Hi, can anyone help me with the following please?
> As an example, I have a domain - YES_NO - with strangely enough only Y
> or N acceptable as input.
> I then use this domain in various tables.
> In Delphi I then check if 'Y' or 'N' is entered before trying to write
> to the database. Yes, I know the write will fail but I want to inform
> the user immediately on exit from the entry, rather than when getting to
> the final stage of data-entry, say clicking OK.
> Instead of hard-coding (paraphrasing) "If entry is not in 'Y','N' try
> again", can I get the domain and the domain constraints available to me
> with some sql code? Such as "If entry is not in YES_NO.CHECK try again"
> substituting the real values....
>
> I hope I've explained this.
>
> Alan J Davies
> Aldis
>
>