From 2574e7e37f7807507085b47eb140d1127b4c8129 Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Tue, 31 Mar 2020 11:58:45 -0700 Subject: [PATCH] Note MySQL handling of BLOB --- CHANGELOG.md | 1 + doc/tips-and-tricks.md | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49143f3..ff9270a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Only accretive/fixative changes will be made from now on. The following changes have been made to **master** since the 1.0.409 build: +* In **Tips & Tricks**, noted that MySQL returns `BLOB` columns as `byte[]` instead of `java.sql.Blob`. * Fixes #102 by allowing keywords or strings in `:return-keys`. * Fixes #101 by tightening the spec on a JDBC URL to correctly reflect that it must start with `jdbc:`. * Add support for calling `.getLoginTimeout`/`.setLoginTimeout` on the reified `DataSource` returned by `get-datasource` when called on a hash map "db-spec" or JDBC URL string. diff --git a/doc/tips-and-tricks.md b/doc/tips-and-tricks.md index 0d10f0e..7b248e6 100644 --- a/doc/tips-and-tricks.md +++ b/doc/tips-and-tricks.md @@ -4,7 +4,7 @@ This page contains various tips and tricks that make it easier to use `next.jdbc ## CLOB & BLOB SQL Types -Columns declared with the `CLOB` or `BLOB` SQL types are typically rendered into Clojure result sets as database-specific custom types but they will implement `java.sql.Clob` or `java.sql.Blob` (as appropriate). In general, you can only read the data out of those Java objects during the current transaction, which effectively means that you need to do it either inside the reduction (for `plan`) or inside the result set builder (for `execute!` or `execute-one!`). If you always treat these types the same way for all columns across the whole of your application, you could simply extend `next.jdbc.result-set/ReadableColumn` to `java.sql.Clob` (and/or `java.sql.Blob`). Here's an example for reading `CLOB` into a `String`: +Columns declared with the `CLOB` or `BLOB` SQL types are typically rendered into Clojure result sets as database-specific custom types but they should implement `java.sql.Clob` or `java.sql.Blob` (as appropriate). In general, you can only read the data out of those Java objects during the current transaction, which effectively means that you need to do it either inside the reduction (for `plan`) or inside the result set builder (for `execute!` or `execute-one!`). If you always treat these types the same way for all columns across the whole of your application, you could simply extend `next.jdbc.result-set/ReadableColumn` to `java.sql.Clob` (and/or `java.sql.Blob`). Here's an example for reading `CLOB` into a `String`: ```clojure (extend-protocol rs/ReadableColumn @@ -36,6 +36,8 @@ No helper or column reader is provided for `BLOB` data since it is expected that Consult the [java.sql.Blob documentation](https://docs.oracle.com/javase/8/docs/api/java/sql/Blob.html) for more ways to process it. +> Note: the standard MySQL JDBC driver seems to return `BLOB` data as `byte[]` instead of `java.sql.Blob`. + ## MS SQL Server In MS SQL Server, the generated key from an insert comes back as `:GENERATED_KEYS`.