Skip to content

Commit 2a1af3d

Browse files
committed
Add some docs. Override config with command line parameters
1 parent 2f1a6a7 commit 2a1af3d

File tree

4 files changed

+47
-9
lines changed

4 files changed

+47
-9
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ hs_err_pid*
2424

2525
.idea
2626
*.iml
27-
target/
27+
target/
28+
.classpath
29+
.project
30+
.settings/

README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,30 @@
11
# sqlcmd
2-
SQL command line executor using JDBC drivers. Usefull for cron jobs and some automation. Porting of my previous sf.net code
2+
SQL command line executor using JDBC drivers. Useful for cron jobs and some automation. Porting of my previous sf.net code
3+
4+
Usage:
5+
6+
java -jar sqlcmd.jar -c:sqlcmd_config.properties <<EOF
7+
SELECT *
8+
FROM MY_TABLE
9+
EOF
10+
11+
Config values:
12+
13+
* jdbcDriverPath=Path to jdbc driver jar (loaded dynamically)
14+
* jdbcDriverClass=Jdbc Driver class full name
15+
* jdbcUrl=Jdbc connection URL
16+
* jdbcUser=
17+
* jdbcPass=
18+
* inputSQL=Path to input sql file (not required/optional if not present it uses stdin)
19+
* outputResult=Path to output file (if not present uses stdout)
20+
* printHeader=true/false If true adds header with query's column name. Default true
21+
* printFieldSeparator=Field separator for printing. Default tab (\t)
22+
23+
Config values can be set also with parameters:
24+
25+
-p:paran_name=param_value
26+
27+
Ex:
28+
29+
-p:printHeader=false
30+

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
<distributionManagement>
5656
<repository>
5757
<id>github</id>
58-
<name>GitHub OWNER Apache Maven Packages</name>
58+
<name>GitHub jdlopez Apache Maven Packages</name>
5959
<url>https://maven.pkg.github.com/jdlopez/sqlcmd</url>
6060
</repository>
6161
</distributionManagement>

src/main/java/es/jdlopez/sqlcmd/MainRunner.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,26 @@ private static String readAll(InputStream in) throws IOException {
9090

9191
private static RunnerConfig readArgs(String[] args) throws ConfigException {
9292
RunnerConfig conf = null;
93-
if (args != null)
94-
for (String a: args) {
93+
if (args != null) {
94+
Properties p = new Properties();
95+
for (String a : args) {
9596
if (a.startsWith("-c:")) { // config
96-
Properties p = new Properties();
9797
try {
9898
p.load(new FileReader(a.substring("-c:".length())));
9999
} catch (IOException e) {
100100
throw new ConfigException("configFile", "Reading config file", e);
101101
}
102-
conf = BeanReader.fromProperties(p, RunnerConfig.class);
103-
} // else if ... for any other args TODO
102+
} else if (a != null && a.startsWith("-p:")) {
103+
String s = a.substring("-p:".length());
104+
int idxEq = s != null? s.indexOf("="):-1;
105+
if (idxEq < 0)
106+
throw new ConfigException(s, "Param argument must be: -p:name=value");
107+
else
108+
p.setProperty(s.substring(0, idxEq), s.substring(idxEq + 1));
109+
}
104110
}
105-
else
111+
conf = BeanReader.fromProperties(p, RunnerConfig.class);
112+
} else
106113
throw new ConfigException(null, "No arguments");
107114
// default values (cant use constructor, explicit or implicit)
108115
if (conf.getPrintFieldSeparator() == null)

0 commit comments

Comments
 (0)