Skip to content

Commit

Permalink
0001180: Add option to symadmin --send-sql to specify a file containing
Browse files Browse the repository at this point in the history
the sql to send.
  • Loading branch information
JishLong committed Jul 21, 2023
1 parent d689f5f commit bf49306
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Expand Up @@ -132,6 +132,7 @@ public class SymmetricAdmin extends AbstractCommandLauncher {
private static final String OPTION_EXCLUDE_LOG4J = "exclude-log4j";
private static final String OPTION_EXTERNAL_SECURITY = "external-security";
private static final String OPTION_ALTERS = "alters";
private static final String OPTION_FILE = "file";
private static final int WIDTH = 120;
private static final int PAD = 3;

Expand Down Expand Up @@ -266,6 +267,9 @@ private void printHelpCommand(CommandLine line) {
if (cmd.equals(CMD_EXPORT_SYM_TABLES)) {
addOption(options, null, OPTION_ALTERS, false);
}
if (cmd.equals(CMD_SEND_SQL)) {
addOption(options, "f", OPTION_FILE, true);
}
if (options.getOptions().size() > 0) {
format.printWrapped(writer, WIDTH, "\nOptions:");
format.printOptions(writer, WIDTH, options, PAD, PAD);
Expand Down Expand Up @@ -302,6 +306,7 @@ protected void buildOptions(Options options) {
addOption(options, null, OPTION_EXCLUDE_LOG4J, false);
addOption(options, null, OPTION_EXTERNAL_SECURITY, false);
addOption(options, null, OPTION_ALTERS, false);
addOption(options, null, OPTION_FILE, true);
buildCryptoOptions(options);
}

Expand Down Expand Up @@ -804,9 +809,20 @@ private void uninstall(CommandLine line, List<String> args) {

private void sendSql(CommandLine line, List<String> args) {
String tableName = popArg(args, "Table Name");
String sql = popArg(args, "SQL");
String sql;
String catalogName = line.getOptionValue(OPTION_CATALOG);
String schemaName = line.getOptionValue(OPTION_SCHEMA);
String fileName = line.getOptionValue(OPTION_FILE);
if (fileName != null) {
try {
File sqlFile = new File(fileName);
sql = FileUtils.readFileToString(sqlFile, Charset.defaultCharset());
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
sql = popArg(args, "SQL");
}
for (Node node : getNodes(line)) {
System.out.println("Sending SQL to node '" + node.getNodeId() + "'");
getSymmetricEngine().getDataService().sendSQL(node.getNodeId(), catalogName,
Expand Down
Expand Up @@ -146,6 +146,7 @@ SymAdmin.Option.exclude-indices=Don't send indices
SymAdmin.Option.exclude-log4j=Exclude log4j logging framework and configuration
SymAdmin.Option.external-security=Use security files outside of the WAR file for encryption keys and certificates
SymAdmin.Option.alters=DDL changes necessary to alter tables will be output
SymAdmin.Option.file=Specify a file to use.

DbExport.Option.compatible=Change export to be compatible with given database: db2, db2zos, derby, firebird, greenplum, h2, hsqldb, hsqldb2, informix, interbase, mssql, mysql, oracle, postgres, sybase.
DbExport.Option.add-drop-table=Add drop table commands to output.
Expand Down

0 comments on commit bf49306

Please sign in to comment.