]> source.dussan.org Git - iciql.git/commitdiff
Strip column identifiers from specified column names when mapping JDBC ResultSets...
authorJames Moger <james.moger@gitblit.com>
Tue, 21 Jul 2015 19:10:05 +0000 (15:10 -0400)
committerJames Moger <james.moger@gitblit.com>
Tue, 21 Jul 2015 19:10:05 +0000 (15:10 -0400)
releases.moxie
src/main/java/com/iciql/Db.java
src/main/java/com/iciql/Query.java
src/main/java/com/iciql/SQLDialect.java
src/main/java/com/iciql/SQLDialectDefault.java
src/main/java/com/iciql/SQLDialectMSSQL.java
src/main/java/com/iciql/TableDefinition.java

index 6ea2888ada3e5017a46ec781d08da06f0ccc6f5c..f8e386bc49a85305c3ed9463d69a529e59c1b582 100644 (file)
@@ -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
 }
 
 #
index ef079632200b203a8aae2484d562ecec1d7db5c0..088fc3070c40c1ef0fe1f40372089544aec6243e 100644 (file)
@@ -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);
index fd8d0210ffc9d10479904ba4488c3df214bf74e4..694f42e8d3e84b8ccc5cf2ef03322ddfd3d0db28 100644 (file)
@@ -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);
index ccc04529fbeddffcd6c9d428fd76bc51c2670587..8e6361a2bb908be89a47ed1945cdd87ccfe2cc0b 100644 (file)
@@ -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);
+
 }
index 371ee31a998f8f7b05a6d7781ef52e46f226c0bd..ec3f605ba6f6da6a85a17153c1a79409ff9f0308 100644 (file)
@@ -119,6 +119,11 @@ public class SQLDialectDefault implements SQLDialect {
                return name;
        }
 
+       @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 "
index 92b1297db75770655fb487563f9dd6149da74342..e591d4a09e7314a527ce778f403436e78056e2d0 100644 (file)
@@ -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
    *
index 8248f187edf8f8c18446ddb04e8b897737039332..4fe860d2a9f38c70155e361c1ad45ae0d8e74d4d 100644 (file)
@@ -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