From e8e956f58e1e6677f86549eaeaa7adea1c3a26a9 Mon Sep 17 00:00:00 2001 From: rwisser Date: Tue, 27 Dec 2016 11:58:34 +0000 Subject: [PATCH] fix for "Column name not exported with double quotes" git-svn-id: https://svn.code.sf.net/p/jailer/code/trunk@1129 3dd849cd-670e-4645-a7cd-dd197c8d0e81 --- releasenotes-dbeauty.txt | 1 + releasenotes.txt | 1 + src/main/net/sf/jailer/DDLCreator.java | 4 +- .../net/sf/jailer/database/SQLDialect.java | 2 +- .../JDBCMetaDataBasedModelElementFinder.java | 6 +- .../databrowser/TableContentViewFilter.java | 19 +++++- src/main/net/sf/jailer/util/Quoting.java | 16 ----- src/test/net/sf/jailer/DeletionTestCase.java | 2 +- src/test/net/sf/jailer/ExportTestCase.java | 2 +- .../net/sf/jailer/PseudoColumnsTestCase.java | 62 +++++++++---------- 10 files changed, 58 insertions(+), 57 deletions(-) diff --git a/releasenotes-dbeauty.txt b/releasenotes-dbeauty.txt index a871a9f9a..447e2e66d 100644 --- a/releasenotes-dbeauty.txt +++ b/releasenotes-dbeauty.txt @@ -1,5 +1,6 @@ 2.8.1 - Data Browser has been improved. + - Bug fix for "Column name not exported with double quotes" https://sourceforge.net/p/jailer/discussion/700499/thread/a3635560/ 2.8.1 - Fixed an incompatibility with Java 9. diff --git a/releasenotes.txt b/releasenotes.txt index 4fec29bde..ef59b72c8 100644 --- a/releasenotes.txt +++ b/releasenotes.txt @@ -1,5 +1,6 @@ 6.3.2 - Data Browser has been improved. + - Bug fix for "Column name not exported with double quotes" https://sourceforge.net/p/jailer/discussion/700499/thread/a3635560/ 6.3.1 - Fixed an incompatibility with Java 9. diff --git a/src/main/net/sf/jailer/DDLCreator.java b/src/main/net/sf/jailer/DDLCreator.java index bc962a1e1..481d5beda 100755 --- a/src/main/net/sf/jailer/DDLCreator.java +++ b/src/main/net/sf/jailer/DDLCreator.java @@ -122,7 +122,7 @@ private static boolean createDDL(DataModel dataModel, Session session, Temporary } String tableName = SQLDialect.CONFIG_TABLE_; arguments.put("config-dml-reference", tableName); - String schema = workingTableSchema != null? new Quoting(session, true).quote(workingTableSchema) + "." : ""; + String schema = workingTableSchema != null? new Quoting(session).quote(workingTableSchema) + "." : ""; arguments.put("schema", schema); arguments.put("index-schema", supportsSchemasInIndexDefinitions(session)? schema : ""); if (tableManager != null) { @@ -239,7 +239,7 @@ public static boolean isUptodate(final Session session, boolean useRowId, String final Map typeReplacement = Configuration.forDbms(session).getTypeReplacement(); final RowIdSupport rowIdSupport = new RowIdSupport(datamodel, Configuration.forDbms(session), useRowId); - final String schema = workingTableSchema == null ? "" : new Quoting(session, true).quote(workingTableSchema) + "."; + final String schema = workingTableSchema == null ? "" : new Quoting(session).quote(workingTableSchema) + "."; session.executeQuery("Select jvalue from " + schema + SQLDialect.CONFIG_TABLE_ + " where jversion='" + Jailer.VERSION + "' and jkey='upk'", new Session.ResultSetReader() { diff --git a/src/main/net/sf/jailer/database/SQLDialect.java b/src/main/net/sf/jailer/database/SQLDialect.java index 5f5ef42eb..0ad221320 100644 --- a/src/main/net/sf/jailer/database/SQLDialect.java +++ b/src/main/net/sf/jailer/database/SQLDialect.java @@ -139,7 +139,7 @@ public static String dmlTableReference(String tableName, Session session) throws if (temporaryTableScope != TemporaryTableScope.LOCAL_DATABASE) { String schema = CommandLineParser.getInstance().workingTableSchema; if (schema != null) { - tableRef = new Quoting(session, true).quote(schema) + "." + tableRef; + tableRef = new Quoting(session).quote(schema) + "." + tableRef; } } return tableRef; diff --git a/src/main/net/sf/jailer/modelbuilder/JDBCMetaDataBasedModelElementFinder.java b/src/main/net/sf/jailer/modelbuilder/JDBCMetaDataBasedModelElementFinder.java index 60049fa28..11e5592de 100755 --- a/src/main/net/sf/jailer/modelbuilder/JDBCMetaDataBasedModelElementFinder.java +++ b/src/main/net/sf/jailer/modelbuilder/JDBCMetaDataBasedModelElementFinder.java @@ -82,7 +82,7 @@ public class JDBCMetaDataBasedModelElementFinder implements ModelElementFinder { public Collection findAssociations(DataModel dataModel, Map namingSuggestion, Session session) throws Exception { Collection associations = new ArrayList(); DatabaseMetaData metaData = session.getMetaData(); - Quoting quoting = new Quoting(session, true); + Quoting quoting = new Quoting(session); ResultSet resultSet; String defaultSchema = getDefaultSchema(session, session.dbUser); @@ -156,7 +156,7 @@ public Set findTables(Session session) throws Exception { Set
tables = new HashSet
(); DatabaseMetaData metaData = session.getMetaData(); - Quoting quoting = new Quoting(session, true); + Quoting quoting = new Quoting(session); ResultSet resultSet; resultSet = getTables(session, metaData, session.getIntrospectionSchema(), "%", new String[] { "TABLE" }); List tableNames = new ArrayList(); @@ -526,7 +526,7 @@ public void readCurrentRow(ResultSet resultSet) throws SQLException { public List findColumns(Table table, Session session) throws Exception { List columns = new ArrayList(); DatabaseMetaData metaData = session.getMetaData(); - Quoting quoting = new Quoting(session, true); + Quoting quoting = new Quoting(session); if (forDefaultSchema != session) { forDefaultSchema = session; _log.info("getting default schema..."); diff --git a/src/main/net/sf/jailer/ui/databrowser/TableContentViewFilter.java b/src/main/net/sf/jailer/ui/databrowser/TableContentViewFilter.java index 4c050cda5..d0f561103 100644 --- a/src/main/net/sf/jailer/ui/databrowser/TableContentViewFilter.java +++ b/src/main/net/sf/jailer/ui/databrowser/TableContentViewFilter.java @@ -85,12 +85,27 @@ public Object filter(Object[] object, Map name) { bindings.put("object", object); bindings.put("name", name); bindings.put("df", df); - script.eval(bindings); + // script.eval(bindings); + Integer i; + i = name.get("angelegt"); + if (i != null) { + object[i.intValue()] = df.format(new java.util.Date(parseInt(object[i.intValue()].toString()))); + } + + i = name.get("geaendert"); + if (i != null) { + object[i.intValue()] = df.format(new java.util.Date(parseInt(object[i.intValue()].toString()))); + } + + } catch (Exception e) { - e.printStackTrace(); } return object; } + private long parseInt(String string) { + return Long.parseLong(string); + } + } diff --git a/src/main/net/sf/jailer/util/Quoting.java b/src/main/net/sf/jailer/util/Quoting.java index d5f0193bb..877f8e8ac 100644 --- a/src/main/net/sf/jailer/util/Quoting.java +++ b/src/main/net/sf/jailer/util/Quoting.java @@ -61,25 +61,12 @@ public class Quoting { */ private Set keyWords = new HashSet(); - private final boolean force; - /** * Constructor. * * @param session the database session */ public Quoting(Session session) throws SQLException { - this(session, false); - } - - /** - * Constructor. - * - * @param session the database session - * @param force if true, quote unquoted identifiers - */ - public Quoting(Session session, boolean force) throws SQLException { - this.force = force; DatabaseMetaData metaData = session.getMetaData(); String quoteString = metaData.getIdentifierQuoteString(); if (quoteString != null @@ -178,9 +165,6 @@ public String quote(String identifier) { if (identifier != null) { identifier = identifier.trim(); } - if (!force && !isQuoted(identifier)) { - return identifier; - } identifier = unquote(identifier); if (quote != null && identifier != null && identifier.length() > 0) { if (!keyWords.contains(identifier.toUpperCase())) { diff --git a/src/test/net/sf/jailer/DeletionTestCase.java b/src/test/net/sf/jailer/DeletionTestCase.java index 4d11e8cb7..b890ea48a 100644 --- a/src/test/net/sf/jailer/DeletionTestCase.java +++ b/src/test/net/sf/jailer/DeletionTestCase.java @@ -78,7 +78,7 @@ public void testDeletion() throws Exception { if (doDeletion(datamodelDir, new File(testDir, "extractionmodel.csv"), result, insertResult, scope)) { Session statementExecutor = new Session(connectionArguments.get(0), connectionArguments.get(1), connectionArguments.get(2), connectionArguments.get(3)); - SqlScriptExecutor.executeScript(result.getCanonicalPath(), statementExecutor); + new SqlScriptExecutor(statementExecutor, 1).executeScript(result.getCanonicalPath()); statementExecutor.shutDown(); File actualState = new File(resultDir, "remaining-state.xml"); diff --git a/src/test/net/sf/jailer/ExportTestCase.java b/src/test/net/sf/jailer/ExportTestCase.java index 94de6d650..edce33a45 100644 --- a/src/test/net/sf/jailer/ExportTestCase.java +++ b/src/test/net/sf/jailer/ExportTestCase.java @@ -93,7 +93,7 @@ public void testExport() throws Exception { if (format.equals("SQL")) { DatabaseOperation.DELETE_ALL.execute(getConnection(), getDataSet()); Session statementExecutor = new Session(connectionArguments.get(0), connectionArguments.get(1), connectionArguments.get(2), connectionArguments.get(3)); - SqlScriptExecutor.executeScript(result.getCanonicalPath(), statementExecutor); + new SqlScriptExecutor(statementExecutor, 1).executeScript(result.getCanonicalPath()); statementExecutor.shutDown(); assertDatabaseState(expectedResult.getCanonicalPath()); } diff --git a/src/test/net/sf/jailer/PseudoColumnsTestCase.java b/src/test/net/sf/jailer/PseudoColumnsTestCase.java index 8a7c8542a..48bfa2af9 100644 --- a/src/test/net/sf/jailer/PseudoColumnsTestCase.java +++ b/src/test/net/sf/jailer/PseudoColumnsTestCase.java @@ -26,40 +26,40 @@ public class PseudoColumnsTestCase extends TestCase { public void testPseudoColumn() throws Exception { - assertEquals("(T1.birthday - 1)=(T2.birthday - 1)", SqlUtil.resolvePseudoColumns("A.$distance=B.$distance", "T1", "T2", 2, 1)); - assertEquals("(T1.birthday - 1)=(T2.birthday - 1)", SqlUtil.resolvePseudoColumns("A . $distance=B . $distance", "T1", "T2", 2, 1)); - assertEquals("(T1.birthday - 1)=(T2.birthday - 1)", SqlUtil.resolvePseudoColumns("A.$DISTANCE=B.$DISTANCE", "T1", "T2", 2, 1)); - assertEquals("(T1.birthday - 1)=(T2.birthday - 1)", SqlUtil.resolvePseudoColumns("A . $DISTANCE=B . $DISTANCE", "T1", "T2", 2, 1)); - assertEquals("(T1.birthday - 1)=B", SqlUtil.resolvePseudoColumns("A.$DISTANCE=B", "T1", "T2", 2, 1)); - assertEquals("(T1.birthday - 1)=(T2.birthday - 1)", SqlUtil.resolvePseudoColumns("a.$distance=b.$distance", "T1", "T2", 2, 1)); - assertEquals("(T1.birthday - 1)=(T2.birthday - 1)", SqlUtil.resolvePseudoColumns("a . $distance=b . $distance", "T1", "T2", 2, 1)); - assertEquals("(T1.birthday - 1)=(T2.birthday - 1)", SqlUtil.resolvePseudoColumns("a.$DISTANCE=b.$DISTANCE", "T1", "T2", 2, 1)); - assertEquals("(T1.birthday - 1)=(T2.birthday - 1)", SqlUtil.resolvePseudoColumns("a . $DISTANCE=b . $DISTANCE", "T1", "T2", 2, 1)); - assertEquals("(T1.birthday - 1)=b", SqlUtil.resolvePseudoColumns("a.$DISTANCE=b", "T1", "T2", 2, 1)); + assertEquals("(T1.birthday - 1)=(T2.birthday - 1)", SqlUtil.resolvePseudoColumns("A.$distance=B.$distance", "T1", "T2", 2, 1, false)); + assertEquals("(T1.birthday - 1)=(T2.birthday - 1)", SqlUtil.resolvePseudoColumns("A . $distance=B . $distance", "T1", "T2", 2, 1, false)); + assertEquals("(T1.birthday - 1)=(T2.birthday - 1)", SqlUtil.resolvePseudoColumns("A.$DISTANCE=B.$DISTANCE", "T1", "T2", 2, 1, false)); + assertEquals("(T1.birthday - 1)=(T2.birthday - 1)", SqlUtil.resolvePseudoColumns("A . $DISTANCE=B . $DISTANCE", "T1", "T2", 2, 1, false)); + assertEquals("(T1.birthday - 1)=B", SqlUtil.resolvePseudoColumns("A.$DISTANCE=B", "T1", "T2", 2, 1, false)); + assertEquals("(T1.birthday - 1)=(T2.birthday - 1)", SqlUtil.resolvePseudoColumns("a.$distance=b.$distance", "T1", "T2", 2, 1, false)); + assertEquals("(T1.birthday - 1)=(T2.birthday - 1)", SqlUtil.resolvePseudoColumns("a . $distance=b . $distance", "T1", "T2", 2, 1, false)); + assertEquals("(T1.birthday - 1)=(T2.birthday - 1)", SqlUtil.resolvePseudoColumns("a.$DISTANCE=b.$DISTANCE", "T1", "T2", 2, 1, false)); + assertEquals("(T1.birthday - 1)=(T2.birthday - 1)", SqlUtil.resolvePseudoColumns("a . $DISTANCE=b . $DISTANCE", "T1", "T2", 2, 1, false)); + assertEquals("(T1.birthday - 1)=b", SqlUtil.resolvePseudoColumns("a.$DISTANCE=b", "T1", "T2", 2, 1, false)); - assertEquals("(T1.birthday - 1 = 0) and (T2.birthday - 1 = 0)", SqlUtil.resolvePseudoColumns("A.$is_subject and B.$is_subject", "T1", "T2", 2, 1)); - assertEquals("(T1.birthday - 1 = 0) and (T2.birthday - 1 = 0)", SqlUtil.resolvePseudoColumns("A . $is_subject and B . $is_subject", "T1", "T2", 2, 1)); - assertEquals("(T1.birthday - 1 = 0) and (T2.birthday - 1 = 0)", SqlUtil.resolvePseudoColumns("A.$IS_SUBJECT and B.$IS_SUBJECT", "T1", "T2", 2, 1)); - assertEquals("(T1.birthday - 1 = 0) and (T2.birthday - 1 = 0)", SqlUtil.resolvePseudoColumns("A . $IS_SUBJECT and B . $IS_SUBJECT", "T1", "T2", 2, 1)); - assertEquals("(T1.birthday - 1 = 0) and B", SqlUtil.resolvePseudoColumns("A.$IS_SUBJECT and B", "T1", "T2", 2, 1)); - assertEquals("(T1.birthday - 1 = 0) and (T2.birthday - 1 = 0)", SqlUtil.resolvePseudoColumns("a.$is_subject and b.$is_subject", "T1", "T2", 2, 1)); - assertEquals("(T1.birthday - 1 = 0) and (T2.birthday - 1 = 0)", SqlUtil.resolvePseudoColumns("a . $is_subject and b . $is_subject", "T1", "T2", 2, 1)); - assertEquals("(T1.birthday - 1 = 0) and (T2.birthday - 1 = 0)", SqlUtil.resolvePseudoColumns("a.$IS_SUBJECT and b.$IS_SUBJECT", "T1", "T2", 2, 1)); - assertEquals("(T1.birthday - 1 = 0) and (T2.birthday - 1 = 0)", SqlUtil.resolvePseudoColumns("a . $IS_SUBJECT and b . $IS_SUBJECT", "T1", "T2", 2, 1)); - assertEquals("(T1.birthday - 1 = 0) and b", SqlUtil.resolvePseudoColumns("a.$IS_SUBJECT and b", "T1", "T2", 2, 1)); + assertEquals("(T1.birthday - 1 = 0) and (T2.birthday - 1 = 0)", SqlUtil.resolvePseudoColumns("A.$is_subject and B.$is_subject", "T1", "T2", 2, 1, false)); + assertEquals("(T1.birthday - 1 = 0) and (T2.birthday - 1 = 0)", SqlUtil.resolvePseudoColumns("A . $is_subject and B . $is_subject", "T1", "T2", 2, 1, false)); + assertEquals("(T1.birthday - 1 = 0) and (T2.birthday - 1 = 0)", SqlUtil.resolvePseudoColumns("A.$IS_SUBJECT and B.$IS_SUBJECT", "T1", "T2", 2, 1, false)); + assertEquals("(T1.birthday - 1 = 0) and (T2.birthday - 1 = 0)", SqlUtil.resolvePseudoColumns("A . $IS_SUBJECT and B . $IS_SUBJECT", "T1", "T2", 2, 1, false)); + assertEquals("(T1.birthday - 1 = 0) and B", SqlUtil.resolvePseudoColumns("A.$IS_SUBJECT and B", "T1", "T2", 2, 1, false)); + assertEquals("(T1.birthday - 1 = 0) and (T2.birthday - 1 = 0)", SqlUtil.resolvePseudoColumns("a.$is_subject and b.$is_subject", "T1", "T2", 2, 1, false)); + assertEquals("(T1.birthday - 1 = 0) and (T2.birthday - 1 = 0)", SqlUtil.resolvePseudoColumns("a . $is_subject and b . $is_subject", "T1", "T2", 2, 1, false)); + assertEquals("(T1.birthday - 1 = 0) and (T2.birthday - 1 = 0)", SqlUtil.resolvePseudoColumns("a.$IS_SUBJECT and b.$IS_SUBJECT", "T1", "T2", 2, 1, false)); + assertEquals("(T1.birthday - 1 = 0) and (T2.birthday - 1 = 0)", SqlUtil.resolvePseudoColumns("a . $IS_SUBJECT and b . $IS_SUBJECT", "T1", "T2", 2, 1, false)); + assertEquals("(T1.birthday - 1 = 0) and b", SqlUtil.resolvePseudoColumns("a.$IS_SUBJECT and b", "T1", "T2", 2, 1, false)); - assertEquals("(1 = 0)", SqlUtil.resolvePseudoColumns("b . $IS_SUBJECT", "T1", null, 2, 1)); + assertEquals("(1 = 0)", SqlUtil.resolvePseudoColumns("b . $IS_SUBJECT", "T1", null, 2, 1, false)); - assertEquals("(T1.birthday - 1)=2", SqlUtil.resolvePseudoColumns("A.$distance=B.$distance", "T1", null, 3, 1)); - assertEquals("(T1.birthday - 1)=2", SqlUtil.resolvePseudoColumns("A . $distance=B . $distance", "T1", null, 3, 1)); - assertEquals("(T1.birthday - 1)=2", SqlUtil.resolvePseudoColumns("A.$DISTANCE=B.$DISTANCE", "T1", null, 3, 1)); - assertEquals("(T1.birthday - 1)=2", SqlUtil.resolvePseudoColumns("A . $DISTANCE=B . $DISTANCE", "T1", null, 3, 1)); - assertEquals("(T1.birthday - 1)=B", SqlUtil.resolvePseudoColumns("A.$DISTANCE=B", "T1", null, 3, 1)); - assertEquals("(T1.birthday - 1)=2", SqlUtil.resolvePseudoColumns("a.$distance=b.$distance", "T1", null, 3, 1)); - assertEquals("(T1.birthday - 1)=2", SqlUtil.resolvePseudoColumns("a . $distance=b . $distance", "T1", null, 3, 1)); - assertEquals("(T1.birthday - 1)=2", SqlUtil.resolvePseudoColumns("a.$DISTANCE=b.$DISTANCE", "T1", null, 3, 1)); - assertEquals("(T1.birthday - 1)=2", SqlUtil.resolvePseudoColumns("a . $DISTANCE=b . $DISTANCE", "T1", null, 3, 1)); - assertEquals("(T1.birthday - 1)=b", SqlUtil.resolvePseudoColumns("a.$DISTANCE=b", "T1", null, 3, 1)); + assertEquals("(T1.birthday - 1)=2", SqlUtil.resolvePseudoColumns("A.$distance=B.$distance", "T1", null, 3, 1, false)); + assertEquals("(T1.birthday - 1)=2", SqlUtil.resolvePseudoColumns("A . $distance=B . $distance", "T1", null, 3, 1, false)); + assertEquals("(T1.birthday - 1)=2", SqlUtil.resolvePseudoColumns("A.$DISTANCE=B.$DISTANCE", "T1", null, 3, 1, false)); + assertEquals("(T1.birthday - 1)=2", SqlUtil.resolvePseudoColumns("A . $DISTANCE=B . $DISTANCE", "T1", null, 3, 1, false)); + assertEquals("(T1.birthday - 1)=B", SqlUtil.resolvePseudoColumns("A.$DISTANCE=B", "T1", null, 3, 1, false)); + assertEquals("(T1.birthday - 1)=2", SqlUtil.resolvePseudoColumns("a.$distance=b.$distance", "T1", null, 3, 1, false)); + assertEquals("(T1.birthday - 1)=2", SqlUtil.resolvePseudoColumns("a . $distance=b . $distance", "T1", null, 3, 1, false)); + assertEquals("(T1.birthday - 1)=2", SqlUtil.resolvePseudoColumns("a.$DISTANCE=b.$DISTANCE", "T1", null, 3, 1, false)); + assertEquals("(T1.birthday - 1)=2", SqlUtil.resolvePseudoColumns("a . $DISTANCE=b . $DISTANCE", "T1", null, 3, 1, false)); + assertEquals("(T1.birthday - 1)=b", SqlUtil.resolvePseudoColumns("a.$DISTANCE=b", "T1", null, 3, 1, false)); } } \ No newline at end of file