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

Implement createArrayOf and setArray #418

Merged
merged 1 commit into from Jan 12, 2017

Conversation

marschall
Copy link
Contributor

Currently java.sql.Array is only supported when returned from the
database. Passing arrays to the database is not supported.
Connection#createArrayOf, PreparedStatement#setArray and
PreparedStatement#setObject with a java.sql.Array are not supported.

This pull requests implements passing java.sql.Array objects to the
database and includes the following changes:

  • implement Connection#createArrayOf
  • implement PreparedStatement#setArray
  • implement conversion from java.sql.Array to Value
  • update DataType#convertTo to support arrays as well
  • add tests for #createArrayOf, #setArray and #setObject
  • remove the test for PreparedStatement#setArray being unsupported

The typeName passed to #createArrayOf is ignored, this is in accordance
with JdbcArray#getBaseTypeName returning "NULL" and
JdbcArray#getBaseType returning Types.NULL even if the backing array is
homogeneous.

@svladykin
Copy link
Member

Looks good, but in some places (createArrayOf and setArray) you do checkClosedForWrite() and then afterWriting(). I think it must be enough to do checkClosed() because an array can be treated like any simple parameter.

Also it would be nice to have more extensive tests for null values, nested arrays, etc...

@marschall
Copy link
Contributor Author

I can do that, give me a moment.

Currently java.sql.Array is only supported when returned from the
database. Passing arrays to the database is not supported.
Connection#createArrayOf, PreparedStatement#setArray and
PreparedStatement#setObject with a java.sql.Array are not supported.

This pull requests implements passing java.sql.Array objects to the
database and includes the following changes:

 - implement Connection#createArrayOf
 - implement PreparedStatement#setArray
 - implement array support in ResultSet#getObject
 - implement conversion from java.sql.Array to Value
 - update DataType#convertTo to support arrays as well
 - add tests for #createArrayOf, #setArray and #setObject
 - add tests for #getObject with an array argument
 - remove the test for Connection#createArrayOf being unsupported
 - remove the test for PreparedStatement#setArray being unsupported

The typeName passed to #createArrayOf is ignored, this is in accordance
with JdbcArray#getBaseTypeName returning "NULL" and
JdbcArray#getBaseType returning Types.NULL even if the backing array is
homogeneous.
@marschall
Copy link
Contributor Author

@svladykin I changed checkClosedForWrite() to checkClosed() and added tests for nulls and nested arrays

@svladykin svladykin merged commit 790cf87 into h2database:master Jan 12, 2017
@svladykin
Copy link
Member

Thanks for the contribution!

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

Successfully merging this pull request may close these issues.

None yet

2 participants