Skip to content

Commit

Permalink
Have added support for byte[] to be inserted into blob-like fields.
Browse files Browse the repository at this point in the history
I experienced issues while trying to save images in a BLOB on mysql, adding this fixed the problem as it doesn't convert the binary data into another format.
  • Loading branch information
mj1618 committed Feb 16, 2015
1 parent 7f982a7 commit 4878681
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/com/jcabi/jdbc/ColumnOutcome.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public ColumnOutcome(@NotNull(message = "type can't be NULL")
if (tpe.equals(String.class) || tpe.equals(Long.class)
|| tpe.equals(Boolean.class) || tpe.equals(Byte.class)
|| tpe.equals(Date.class) || tpe.equals(Utc.class)
|| tpe.equals(byte[].class)
) {
this.type = tpe.getName();
} else {
Expand Down Expand Up @@ -121,6 +122,8 @@ private T fetch(final ResultSet rset) throws SQLException {
result = rset.getDate(1);
} else if (tpe.equals(Utc.class)) {
result = new Utc(Utc.getTimestamp(rset, 1));
} else if (tpe.equals(byte[].class)) {
result = rset.getBytes(1);
} else {
throw new IllegalStateException(
String.format("type %s is not allowed", tpe.getName())
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/jcabi/jdbc/PrepareArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public void prepare(final PreparedStatement stmt) throws SQLException {
stmt.setInt(pos, Integer.class.cast(arg));
} else if (arg instanceof Utc) {
Utc.class.cast(arg).setTimestamp(stmt, pos);
} else if (arg instanceof byte[]) {
stmt.setBytes(pos,(byte[])arg);
} else {
stmt.setString(pos, arg.toString());
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/jcabi/jdbc/SingleOutcome.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public SingleOutcome(
if (tpe.equals(String.class) || tpe.equals(Long.class)
|| tpe.equals(Boolean.class) || tpe.equals(Byte.class)
|| tpe.equals(Date.class) || tpe.equals(Utc.class)
|| tpe.equals(byte[].class)
) {
this.type = tpe.getName();
} else {
Expand Down Expand Up @@ -152,6 +153,8 @@ private T fetch(final ResultSet rset) throws SQLException {
result = rset.getDate(1);
} else if (tpe.equals(Utc.class)) {
result = new Utc(Utc.getTimestamp(rset, 1));
} else if (tpe.equals(byte[].class)) {
result = rset.getBytes(1);
} else {
throw new IllegalStateException(
String.format("type %s is not allowed", tpe.getName())
Expand Down

0 comments on commit 4878681

Please sign in to comment.