Skip to content

Commit

Permalink
fix issue #9. Added new quoted.identifiers parameter
Browse files Browse the repository at this point in the history
Escape the columns name when quoted-identifiers parameter is set
  • Loading branch information
osalvador committed Jun 8, 2020
1 parent c7c64d4 commit de4e949
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
6 changes: 3 additions & 3 deletions ReplicaDB.iml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
<orderEntry type="library" name="Maven: com.oracle.ojdbc:xmlparserv2:19.3.0.0" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-log4j12:1.7.25" level="project" />
<orderEntry type="library" name="Maven: log4j:log4j:1.2.17" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.10.2" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.10.2" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.10.2" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.11.0" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.11.0" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.11.0" level="project" />
<orderEntry type="library" name="Maven: com.microsoft.sqlserver:mssql-jdbc:7.2.2.jre8" level="project" />
<orderEntry type="library" name="Maven: com.amazonaws:aws-java-sdk-s3:1.11.106" level="project" />
<orderEntry type="library" name="Maven: com.amazonaws:aws-java-sdk-kms:1.11.106" level="project" />
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.replicadb</groupId>
<artifactId>ReplicaDB</artifactId>
<version>0.8.0</version>
<version>0.8.1</version>

<name>ReplicaDB</name>
<url>https://github.com/osalvador/ReplicaDB</url>
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/org/replicadb/cli/ToolOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class ToolOptions {
private Boolean help = false;
private Boolean version = false;
private Boolean verbose = false;
private Boolean quotedIdentifiers = false;
private String optionsFile;

private String mode = DEFAULT_MODE;
Expand Down Expand Up @@ -286,6 +287,13 @@ private void checkOptions(String[] args) throws ParseException, IOException {
Option verboseOpt = new Option("v", "verbose", false, "Print more information while working");
options.addOption(verboseOpt);

options.addOption(
Option.builder()
.longOpt("quoted-identifiers")
.desc("Should all database identifiers be quoted.")
.build()
);


// create the command line parser
CommandLineParser parser = new DefaultParser();
Expand All @@ -312,6 +320,7 @@ private void checkOptions(String[] args) throws ParseException, IOException {
if (line.hasOption("sink-disable-escape")) setSinkDisableEscapeNotNull(true);
if (line.hasOption("sink-disable-truncate")) setSinkDisableTruncateNotNull(true);
if (line.hasOption("sink-analyze")) setSinkAnalyzeNotNull(true);
if (line.hasOption("quoted-identifiers")) setQuotedIdentifiers(true);

setModeNotNull(line.getOptionValue("mode"));
setSinkColumnsNotNull(line.getOptionValue("sink-columns"));
Expand Down Expand Up @@ -426,6 +435,7 @@ private void loadOptionsFile() throws IOException {
setJobs(prop.getProperty("jobs"));
setFetchSize(prop.getProperty("fetch.size"));
setBandwidthThrottling(prop.getProperty("bandwidth.throttling"));
setQuotedIdentifiers(Boolean.parseBoolean(prop.getProperty("quoted.identifiers")));

// Connection params
setSinkConnectionParams(of.getSinkConnectionParams());
Expand Down Expand Up @@ -828,6 +838,7 @@ public String toString() {
",\n\tsinkAnalyze=" + sinkAnalyze +
",\n\tjobs=" + jobs +
",\n\tbandwidthThrottling=" + bandwidthThrottling +
",\n\tquotedIdentifiers=" + quotedIdentifiers +
",\n\tfetchSize=" + fetchSize +
",\n\thelp=" + help +
",\n\tversion=" + version +
Expand Down Expand Up @@ -860,4 +871,12 @@ public void setBandwidthThrottlingNotNull(String bandwidthThrottling) {
if (bandwidthThrottling != null && !bandwidthThrottling.isEmpty())
setBandwidthThrottling(bandwidthThrottling);
}

public Boolean getQuotedIdentifiers() {
return quotedIdentifiers;
}

public void setQuotedIdentifiers(Boolean quotedIdentifiers) {
this.quotedIdentifiers = quotedIdentifiers;
}
}
5 changes: 4 additions & 1 deletion src/main/java/org/replicadb/manager/ConnManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ private String getColumnsFromResultSetMetaData(ResultSetMetaData rsmd) throws SQ

for (int i = 1; i <= columnsNumber; i++) {
if (i > 1) columnNames.append(",");
columnNames.append(rsmd.getColumnName(i));
if (this.options.getQuotedIdentifiers())
columnNames.append("\"").append(rsmd.getColumnName(i)).append("\"");
else
columnNames.append(rsmd.getColumnName(i));
}
return columnNames.toString();
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/replicadb/manager/SqlManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,10 @@ public String[] getPrimaryKeys(String table, String schema) {
ArrayList<String> pks = new ArrayList<>();
while (results.next()) {
String pkName = results.getString("COLUMN_NAME");
pks.add(pkName);
if (this.options.getQuotedIdentifiers())
pks.add("\""+ pkName +"\"");
else
pks.add(pkName);
}

if (pks.isEmpty())
Expand Down

0 comments on commit de4e949

Please sign in to comment.