aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2015-07-21 15:10:05 -0400
committerJames Moger <james.moger@gitblit.com>2015-07-21 15:10:05 -0400
commit83d290a54b3fd43f039bfe60f923737c93b5724e (patch)
tree8f5d6ae1e1b46b2bf84bfd0c5a910f86dee63e90 /src
parentd3695336c7a49c10e084ced59ed19109717bffd5 (diff)
downloadiciql-83d290a54b3fd43f039bfe60f923737c93b5724e.tar.gz
iciql-83d290a54b3fd43f039bfe60f923737c93b5724e.zip
Strip column identifiers from specified column names when mapping JDBC ResultSets to fields
Diffstat (limited to 'src')
-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
6 files changed, 24 insertions, 5 deletions
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