Subject Re: [Firebird-Java] Jaybird problems using hibernate
Author Mark Rotteveel
On 27-10-2013 22:29, Danny García Hernández wrote:
> I change this code in FBWorkaroundStringField.java, if data is greater
> than sqllen but minor or equal than sqllen + 2, and have a begining or
> ending '%', i consider the value as good.
>
> public void setString(String value) throws SQLException {
> byte[] data = setStringForced(value);
>
> if (value == STRING_NULL_VALUE)
> return;
> if (data.length > field.sqllen && !isSystemTable(field.relname)) {
> // special handling for the LIKE ? queries with CHAR(1) fields
> if (!(value.length() <= field.sqllen + 2 &&
> (value.charAt(0) == '%' || value.charAt(value.length() - 1) == '%')))
> throw new DataTruncation(-1, true, false, data.length,
> field.sqllen);
> }
> }
>
> But this only disallow the exception, select don't return any result,
> maybe because server can´t read the correct value from parameters
> structure passed from jaybird.

The server only receives up to the declared length of the column.

> My initial idea was extract % character from de data value if value
> length was greater than field legnth:
>
> Field Length: varchar(4).
> Search for: 11 (%11%). OK. (Containing)
> Search for: 111 (%111%). ERROR. Extract first % (111%). OK. (Starting)
> Search for: 1111 (%1111%). ERROR. Extract first and last % (1111). OK.
> (Equal)
>
> I know that search logic change as a function of the length of search
> string, but for us, is better than only search for two characters (is
> this case).

The problem is this misses cases eg %111% change to 111% and it misses
cases like 2111, similar if you chop off the last character and use
%111, then you would miss cases like 1112. And even then it won't
address cases with more complicated patterns.

I'd strongly suggest not to use hackish solutions in the driver, but
instead expand the column to be a bit wide. If the current length is
really important: add a check constraint to enforce it.

I am not too happy with the existence of FBWorkaroundStringField and
like to remove it entirely.

Mark
--
Mark Rotteveel