Subject Re: [firebird-support] Zero prefix results in primary key constraint violation
Author Ivan Přenosil E.
> > I am executing the following SQL code:
> >
> > CREATE DATABASE 'keytest.fdb' user 'sysdba' password 'masterkey';
> >
> > CREATE TABLE test
> > (
> > Id VARCHAR(16) CHARACTER SET OCTETS NOT NULL,
> > PRIMARY KEY (Id)
> > );
> >
> > COMMIT;
> >
> > INSERT INTO test VALUES (ASCII_CHAR(1));
> > INSERT INTO test VALUES (ASCII_CHAR(1) || ASCII_CHAR(0));
> >
> > The second INSERT gives me a:
> >
> > Statement failed, SQLCODE = -803
> > violation of PRIMARY or UNIQUE KEY constraint "INTEG_2" on table "TEST"
> >
> > Why is that? The octet strings 01hex and 0100hex are clearly two
> > different keys.
>
> Per SQL standard trailing blanks are not accounted at strings comparison. I.e. 'a' == 'a '.
> Character set OCTETS have defined 0x00 as blank character, so {0x01} == {0x01, 0x00}

It also depends on whether build in ascii_char() is used (only for Fb>=2.1), or its UDF version.
Result of UDF is declared as CSTRING (=PChar), so it can't return binary zero at all.

Ivan