jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • JRuby
  • JRUBY-2767

Mistake in selecting identity with H2/HSQLDB

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Patch Submitted:
    Yes

Description

The SQL statement used to select the last inserted record has an unncessary part that causes extra rows to be returned.:

"SELECT IDENTITY() FROM #{table}" should be just "SELECT IDENTITY()"

  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. Text File
    arjdbc_select_identity_fix.patch
    09/Jul/08 1:41 AM
    0.5 kB
    Peter K Chan

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Charles Oliver Nutter added a comment - 13/Jul/08 12:25 AM

Thanks for the patch, Peter...I don't see why we couldn't go ahead and apply it soon, but I'll leave it to Nick to review.

Show
Charles Oliver Nutter added a comment - 13/Jul/08 12:25 AM Thanks for the patch, Peter...I don't see why we couldn't go ahead and apply it soon, but I'll leave it to Nick to review.
Hide
Permalink
Nick Sieger added a comment - 24/Nov/08 5:09 PM

Does this pertain to a particular version of HSQLDB or H2? We have tests to cover this and they break for HSQLDB with this change (but not H2).

Show
Nick Sieger added a comment - 24/Nov/08 5:09 PM Does this pertain to a particular version of HSQLDB or H2? We have tests to cover this and they break for HSQLDB with this change (but not H2).
Hide
Permalink
Peter K Chan added a comment - 24/Nov/08 10:02 PM

I did some research and I see that it breaks on HSQLDB. I also tried a few solutions, but the success between H2 and HSQLDB seems to be disjoint. I am not sure what the solution is, but here is a summary of ways to retrieve identity.

SELECT IDENTITY() from table;

  • works on both H2 and HSQLDB but returns as many rows as there are in the table, which makes this a huge performance issue.

SELECT IDENTITY()

  • works on H2 but HSQLDB complains about not having a FROM TABLE.

CALL IDENTITY()

  • Supposedly works on both H2 and HSQLDB according to documentation, but I am getting a "ActiveRecord::StatementInvalid: ActiveRecord::ActiveRecordError: executeUpdate() cannot be used with this statement: CALL IDENTITY()" in HSQLDB and some kind of casting error in H2.

Here is a quick setup script for testing.

CREATE TABLE testing (
testing_id INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 0) PRIMARY KEY,
name varchar
);

INSERT INTO testing (name) VALUES ('one');
INSERT INTO testing (name) VALUES ('two');
INSERT INTO testing (name) VALUES ('three');

Show
Peter K Chan added a comment - 24/Nov/08 10:02 PM I did some research and I see that it breaks on HSQLDB. I also tried a few solutions, but the success between H2 and HSQLDB seems to be disjoint. I am not sure what the solution is, but here is a summary of ways to retrieve identity. SELECT IDENTITY() from table;
  • works on both H2 and HSQLDB but returns as many rows as there are in the table, which makes this a huge performance issue.
SELECT IDENTITY()
  • works on H2 but HSQLDB complains about not having a FROM TABLE.
CALL IDENTITY()
  • Supposedly works on both H2 and HSQLDB according to documentation, but I am getting a "ActiveRecord::StatementInvalid: ActiveRecord::ActiveRecordError: executeUpdate() cannot be used with this statement: CALL IDENTITY()" in HSQLDB and some kind of casting error in H2.
Here is a quick setup script for testing. CREATE TABLE testing ( testing_id INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 0) PRIMARY KEY, name varchar ); INSERT INTO testing (name) VALUES ('one'); INSERT INTO testing (name) VALUES ('two'); INSERT INTO testing (name) VALUES ('three');
Hide
Permalink
Peter K Chan added a comment - 24/Nov/08 11:22 PM

A small update: I think the reason I got "ActiveRecord::StatementInvalid: ActiveRecord::ActiveRecordError: executeUpdate() cannot be used with this statement: CALL IDENTITY()" from HSQLDB is because of how "CALL IDENTITY()" was classified as an update query and executed with executeUpdate, instead of executeQuery, as it should be.

As a suggestion, perhaps getGeneratedKeys() can be used instead, which should take care of any syntax difference between HSQLDB and H2.

Show
Peter K Chan added a comment - 24/Nov/08 11:22 PM A small update: I think the reason I got "ActiveRecord::StatementInvalid: ActiveRecord::ActiveRecordError: executeUpdate() cannot be used with this statement: CALL IDENTITY()" from HSQLDB is because of how "CALL IDENTITY()" was classified as an update query and executed with executeUpdate, instead of executeQuery, as it should be. As a suggestion, perhaps getGeneratedKeys() can be used instead, which should take care of any syntax difference between HSQLDB and H2.
Hide
Permalink
Thomas E Enebo added a comment - 30/Jan/09 10:30 AM

Fixed in commit f69b992. I used Peter's suggestion of CALL IDENTITY(). I just fixed select? to accept all 'call' methods as well.

Show
Thomas E Enebo added a comment - 30/Jan/09 10:30 AM Fixed in commit f69b992. I used Peter's suggestion of CALL IDENTITY(). I just fixed select? to accept all 'call' methods as well.

People

  • Assignee:
    Thomas E Enebo
    Reporter:
    Peter K Chan
Vote (0)
Watch (2)

Dates

  • Created:
    09/Jul/08 1:41 AM
    Updated:
    25/Aug/09 11:32 AM
    Resolved:
    30/Jan/09 10:30 AM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.