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

Add new KiwiJdbc utilities to convert from a long (used as a boolean) to boolean #1045

Closed
sleberknight opened this issue Oct 5, 2023 · 1 comment · Fixed by #1056
Closed
Assignees
Labels
new feature A new feature such as a new class, method, package, group of classes, etc.
Milestone

Comments

@sleberknight
Copy link
Member

sleberknight commented Oct 5, 2023

Add two new static methods to KiwiJdbc:

boolean booleanFromLong(ResultSet rs, String columnName) throws SQLException

boolean booleanFromLong(long value)

These methods are intended for use with database fields that are intended as boolean, for example if you are using MySql which uses tinyint to store "boolean" values as zero or one.

If the database value is NULL, this method will return false (since ResultSet#getLong returns zero when the database value is NULL).

These methods should check that the long value is either zero or one first, and throw an exception (IllegalArgumentException) if not. They should return true for a value of one and false for zero.

Alternatively, these methods could consider zero as false, and anything non-zero as true. In this case, it would never throw an exception. Or, we could have methods that do one or the other, i.e. one "strict" method that only accepts zero or one, and another that accepts zero as false and any non-zero number as true.

@sleberknight sleberknight added the new feature A new feature such as a new class, method, package, group of classes, etc. label Oct 5, 2023
@sleberknight sleberknight added this to the 3.1.0 milestone Oct 5, 2023
@sleberknight sleberknight self-assigned this Oct 5, 2023
@sleberknight
Copy link
Member Author

The booleanFromLong(long value) is generic and not related to JDBC, so it can be moved to KiwiPrimitives.

Created #1053

sleberknight added a commit that referenced this issue Oct 7, 2023
* Add overloaded booleanFromLong methods. Both accept a ResultSet
  and a String columnName, but one accepts a BooleanConversionOption
  argument while the other doesn't. The one that does not accept
  a BooleanConversionOption uses the ZERO_OR_ONE option.

Closes #1045
sleberknight added a commit that referenced this issue Oct 7, 2023
* Add overloaded booleanFromLong methods. Both accept a ResultSet
  and a String columnName, but one accepts a BooleanConversionOption
  argument while the other doesn't. The one that does not accept
  a BooleanConversionOption uses the ZERO_OR_ONE option.

Closes #1045
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature A new feature such as a new class, method, package, group of classes, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant