diff options
author | James Moger <james.moger@gitblit.com> | 2015-07-21 15:10:05 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2015-07-21 15:10:05 -0400 |
commit | 83d290a54b3fd43f039bfe60f923737c93b5724e (patch) | |
tree | 8f5d6ae1e1b46b2bf84bfd0c5a910f86dee63e90 | |
parent | d3695336c7a49c10e084ced59ed19109717bffd5 (diff) | |
download | iciql-83d290a54b3fd43f039bfe60f923737c93b5724e.tar.gz iciql-83d290a54b3fd43f039bfe60f923737c93b5724e.zip |
Strip column identifiers from specified column names when mapping JDBC ResultSets to fields
-rw-r--r-- | releases.moxie | 6 | ||||
-rw-r--r-- | src/main/java/com/iciql/Db.java | 2 | ||||
-rw-r--r-- | src/main/java/com/iciql/Query.java | 4 | ||||
-rw-r--r-- | src/main/java/com/iciql/SQLDialect.java | 9 | ||||
-rw-r--r-- | src/main/java/com/iciql/SQLDialectDefault.java | 5 | ||||
-rw-r--r-- | src/main/java/com/iciql/SQLDialectMSSQL.java | 5 | ||||
-rw-r--r-- | src/main/java/com/iciql/TableDefinition.java | 4 |
7 files changed, 28 insertions, 7 deletions
diff --git a/releases.moxie b/releases.moxie index 6ea2888..f8e386b 100644 --- a/releases.moxie +++ b/releases.moxie @@ -9,11 +9,13 @@ r29: { html: ~ text: ~ security: ~ - fixes: ~ + fixes: + - Strip column identifiers from specified column names when mapping JDBC ResultSets to fields changes: ~ additions: ~ dependencyChanges: ~ - contributors: ~ + contributors: + - James Moger } # diff --git a/src/main/java/com/iciql/Db.java b/src/main/java/com/iciql/Db.java index ef07963..088fc30 100644 --- a/src/main/java/com/iciql/Db.java +++ b/src/main/java/com/iciql/Db.java @@ -416,7 +416,7 @@ public class Db implements AutoCloseable { try { // SQLite returns pre-closed ResultSets for query results with 0 rows if (!rs.isClosed()) { - int[] columns = def.mapColumns(wildcardSelect, rs); + int[] columns = def.mapColumns(dialect, wildcardSelect, rs); while (rs.next()) { T item = Utils.newObject(modelClass); def.readRow(dialect, item, rs, columns); diff --git a/src/main/java/com/iciql/Query.java b/src/main/java/com/iciql/Query.java index fd8d021..694f42e 100644 --- a/src/main/java/com/iciql/Query.java +++ b/src/main/java/com/iciql/Query.java @@ -250,7 +250,7 @@ public class Query<T> { try { // SQLite returns pre-closed ResultSets for query results with 0 rows if (!rs.isClosed()) { - int[] columns = def.mapColumns(false, rs); + int[] columns = def.mapColumns(db.getDialect(), false, rs); while (rs.next()) { T item = from.newObject(); def.readRow(db.getDialect(), item, rs, columns); @@ -406,7 +406,7 @@ public class Query<T> { try { // SQLite returns pre-closed ResultSets for query results with 0 rows if (!rs.isClosed()) { - int[] columns = def.mapColumns(false, rs); + int[] columns = def.mapColumns(db.getDialect(), false, rs); while (rs.next()) { X row = Utils.newObject(clazz); def.readRow(db.getDialect(), row, rs, columns); diff --git a/src/main/java/com/iciql/SQLDialect.java b/src/main/java/com/iciql/SQLDialect.java index ccc0452..8e6361a 100644 --- a/src/main/java/com/iciql/SQLDialect.java +++ b/src/main/java/com/iciql/SQLDialect.java @@ -215,4 +215,13 @@ public interface SQLDialect { */ String prepareStringParameter(Object o); + /** + * Returns the name of a formatted column identifier for the dialect. + * + * @param name + * the column name + * @return the column name without formatting syntax + */ + String extractColumnName(String name); + } diff --git a/src/main/java/com/iciql/SQLDialectDefault.java b/src/main/java/com/iciql/SQLDialectDefault.java index 371ee31..ec3f605 100644 --- a/src/main/java/com/iciql/SQLDialectDefault.java +++ b/src/main/java/com/iciql/SQLDialectDefault.java @@ -120,6 +120,11 @@ public class SQLDialectDefault implements SQLDialect { } @Override + public String extractColumnName(String name) { + return name.replace('\"', ' ').replace('\'', ' ').trim(); + } + + @Override public <T> void prepareDropTable(SQLStatement stat, TableDefinition<T> def) { StatementBuilder buff = new StatementBuilder("DROP TABLE IF EXISTS " + prepareTableName(def.schemaName, def.tableName)); diff --git a/src/main/java/com/iciql/SQLDialectMSSQL.java b/src/main/java/com/iciql/SQLDialectMSSQL.java index 92b1297..e591d4a 100644 --- a/src/main/java/com/iciql/SQLDialectMSSQL.java +++ b/src/main/java/com/iciql/SQLDialectMSSQL.java @@ -22,6 +22,11 @@ package com.iciql; */ public class SQLDialectMSSQL extends SQLDialectDefault { + @Override + public String extractColumnName(String name) { + return super.extractColumnName(name).replace('[', ' ').replace(']', ' ').trim(); + } + /** * Append limit and offset rows * diff --git a/src/main/java/com/iciql/TableDefinition.java b/src/main/java/com/iciql/TableDefinition.java index 8248f18..4fe860d 100644 --- a/src/main/java/com/iciql/TableDefinition.java +++ b/src/main/java/com/iciql/TableDefinition.java @@ -1140,7 +1140,7 @@ public class TableDefinition<T> { * @param rs * @return */ - int[] mapColumns(boolean wildcardSelect, ResultSet rs) { + int[] mapColumns(SQLDialect dialect, boolean wildcardSelect, ResultSet rs) { int[] columns = new int[fields.size()]; for (int i = 0; i < fields.size(); i++) { try { @@ -1149,7 +1149,7 @@ public class TableDefinition<T> { if (wildcardSelect) { // select * // create column index by field name - columnIndex = rs.findColumn(def.columnName); + columnIndex = rs.findColumn(dialect.extractColumnName(def.columnName)); } else { // select alpha, beta, gamma, etc // explicit select order |