summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--releases.moxie6
-rw-r--r--src/main/java/com/iciql/Db.java2
-rw-r--r--src/main/java/com/iciql/Query.java4
-rw-r--r--src/main/java/com/iciql/SQLDialect.java9
-rw-r--r--src/main/java/com/iciql/SQLDialectDefault.java5
-rw-r--r--src/main/java/com/iciql/SQLDialectMSSQL.java5
-rw-r--r--src/main/java/com/iciql/TableDefinition.java4
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