From 549b92ea7df875bf43a74369951f64ae25566ced Mon Sep 17 00:00:00 2001 From: "Hicks, Josh" Date: Tue, 11 Sep 2018 07:35:17 -0400 Subject: [PATCH] 0003716: MSSQL bulk loader fails when truncate table is used as part of the load with a different target database and schema --- .../symmetric/io/MsSqlBulkDatabaseWriter.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/symmetric-client/src/main/java/org/jumpmind/symmetric/io/MsSqlBulkDatabaseWriter.java b/symmetric-client/src/main/java/org/jumpmind/symmetric/io/MsSqlBulkDatabaseWriter.java index 5ba736e91b..600846ca57 100644 --- a/symmetric-client/src/main/java/org/jumpmind/symmetric/io/MsSqlBulkDatabaseWriter.java +++ b/symmetric-client/src/main/java/org/jumpmind/symmetric/io/MsSqlBulkDatabaseWriter.java @@ -85,7 +85,8 @@ public boolean start(Table table) { String qualifiedName = sourceTable.getFullyQualifiedTableName(); if (writerSettings.isIgnoreMissingTables()) { if (!missingTables.contains(qualifiedName)) { - log.warn("Did not find the {} table in the target database", qualifiedName); + log.info("Did not find the {} table in the target database. This might have been part of a sql " + + "command (truncate) but will work if the fully qualified name was in the sql provided", qualifiedName); missingTables.add(qualifiedName); } } else { @@ -94,7 +95,7 @@ public boolean start(Table table) { } needsBinaryConversion = false; - if (! batch.getBinaryEncoding().equals(BinaryEncoding.HEX)) { + if (! batch.getBinaryEncoding().equals(BinaryEncoding.HEX) && targetTable != null) { for (Column column : targetTable.getColumns()) { if (column.isOfBinaryType()) { needsBinaryConversion = true; @@ -104,13 +105,15 @@ public boolean start(Table table) { } databaseTable = getPlatform(table).getTableFromCache(sourceTable.getCatalog(), sourceTable.getSchema(), sourceTable.getName(), false); - String[] csvNames = targetTable.getColumnNames(); - String[] columnNames = databaseTable.getColumnNames(); - needsColumnsReordered = false; - for (int i = 0; i < csvNames.length; i++) { - if (! csvNames[i].equals(columnNames[i])) { - needsColumnsReordered = true; - break; + if (targetTable != null) { + String[] csvNames = targetTable.getColumnNames(); + String[] columnNames = databaseTable.getColumnNames(); + needsColumnsReordered = false; + for (int i = 0; i < csvNames.length; i++) { + if (! csvNames[i].equals(columnNames[i])) { + needsColumnsReordered = true; + break; + } } } //TODO: Did this because start is getting called multiple times