From e6e0208c973f6a67e8d4593aa665133a6d7e7f03 Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Wed, 3 Dec 2014 03:23:51 +0000 Subject: [PATCH] Don't double quote already quoted identifiers. fixes patch 18 git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@901 f203690c-595d-4dc9-a70b-905162fa7fd2 --- pom.xml | 6 ++++++ src/changes/changes.xml | 3 +++ .../jackcess/impl/query/QueryImpl.java | 9 ++++++++- .../healthmarketscience/jackcess/query/QueryTest.java | 2 +- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 3d83e23..3903c71 100644 --- a/pom.xml +++ b/pom.xml @@ -94,6 +94,12 @@ Contributed to cookbook. + + Gabriele Favalessa + + Fixed various query generation issues. + + SourceForge2 diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 721e923..5137378 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -11,6 +11,9 @@ Fix table name quoting for append and make table queries. + + Don't double quote already quoted identifiers. + diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/query/QueryImpl.java b/src/main/java/com/healthmarketscience/jackcess/impl/query/QueryImpl.java index 90032eb..a695032 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/query/QueryImpl.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/query/QueryImpl.java @@ -510,7 +510,14 @@ public abstract class QueryImpl implements Query protected static StringBuilder toQuotedExpr(StringBuilder builder, String expr) { - return builder.append('[').append(expr).append(']'); + return (!isQuoted(expr) ? + builder.append('[').append(expr).append(']') : + builder.append(expr)); + } + + protected static boolean isQuoted(String expr) { + return ((expr.length() >= 2) && + (expr.charAt(0) == '[') && (expr.charAt(expr.length() - 1) == ']')); } protected static StringBuilder toRemoteDb(StringBuilder builder, diff --git a/src/test/java/com/healthmarketscience/jackcess/query/QueryTest.java b/src/test/java/com/healthmarketscience/jackcess/query/QueryTest.java index ade3ec1..65741cc 100644 --- a/src/test/java/com/healthmarketscience/jackcess/query/QueryTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/query/QueryTest.java @@ -224,7 +224,7 @@ public class QueryTest extends TestCase "UpdateQuery",multiline( "PARAMETERS User Name Text;", "UPDATE Table1", - "SET Table1.col1 = \"foo\", Table1.col2 = [Table2].[col3], [[Table2]].[[col1]] = [User Name]", + "SET Table1.col1 = \"foo\", Table1.col2 = [Table2].[col3], [Table2].[col1] = [User Name]", "WHERE ((([Table2].[col1]) Is Not Null));")); expectedQueries.put( "MakeTableQuery",multiline( -- 2.39.5