Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Field.equalIgnoreCase(String) method broken for SQL Server #2712

Closed
MiErnst opened this issue Aug 26, 2013 · 5 comments
Closed

Field.equalIgnoreCase(String) method broken for SQL Server #2712

MiErnst opened this issue Aug 26, 2013 · 5 comments

Comments

@MiErnst
Copy link

MiErnst commented Aug 26, 2013

We migrate our implementation from 2.6.0 to 3.1.0 and figured out that the equalIgnoreCase method is broken for longer string comparisions.

The method internally calls the cast method which calls org.jooq.impl.AbstractField.cast(DataType)

// [#473] Prevent unnecessary casts
if (getDataType().equals(type)) {
    return (Field<Z>) this;
}

Here getDataType() returns the a varchar (100) and compares it with a varchar without a length. This results in a Cast Object. Under MSSQL the default length of a varchar cast is 30 so all values will be shortened and the "=" compare fails for strings which are longer than 30 characters.

The generated code is:

      lower
      (
         cast([TABLE].[FIELD_NAME] as varchar)
      )
      = lower('MY-REEAAAAAALYYYYY-LONNNNNNNNG-STRING')
@lukaseder
Copy link
Member

Thank you for reporting this. This might be related to #2597. I'll need some further investigation, but I feel that this issue has been seen before

@lukaseder
Copy link
Member

I could reproduce this issue as such:

A a = create().newRecord(TAuthor());
a.setValue(TAuthor_ID(), 3);
a.setValue(TAuthor_LAST_NAME(), "ABCDEFGHIJ1234567890ABCDEFGHIJ1234567890");
assertEquals(1, a.store());

assertEquals(3, (int)
create().select(TAuthor_ID())
        .from(TAuthor())
        .where(TAuthor_LAST_NAME().equalIgnoreCase("abcdefghij1234567890abcdefghij1234567890"))
        .fetchOne(TAuthor_ID()));

@lukaseder
Copy link
Member

The quick fix is to have jOOQ's SQL Server integration cast VARCHAR types of unknown length to VARCHAR(MAX). A more thorough fix avoiding the cast entirely will be implemented with #2597.

The fix is committed and will be pushed in a bigger push, soon.

@lukaseder
Copy link
Member

Hmm, do you happen to know what other data types suffer from this? Surely, NVARCHAR and VARBINARY do. Which other ones?

@MiErnst
Copy link
Author

MiErnst commented Sep 23, 2013

Thank you for the fix.
No, I don't have evaluated which other datatypes have similar problems, only our test cases are broken for the string comparison.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants