-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from zappee/set-timeout
Set timeout
- Loading branch information
Showing
7 changed files
with
95 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,39 @@ | ||
# TODO: this content needs to be updated and finished | ||
# Remal SQL-Runner command line tool | ||
|
||
[release note](release.md) | ||
_keywords: java, sql, query, insert, select, update, oracle, database, bash script, shell script, command line, tool, execute, automate, docker_ | ||
|
||
The tool can be used from script files. | ||
A possible Docker use case to check whether the database server is ready to receiver incoming connections or not: | ||
_[Release Note](release.md)_ | ||
|
||
## 1) Overview | ||
The SQL-Runner is a flexible command line Java tool can be used to run any SQL commands using bash script and command line. It can be used very effectively from Windows/Linux script files. | ||
|
||
The latest version of the tool only supports Oracle Database server, but it can support different SQL dialects as well. | ||
|
||
## 2) Use cases | ||
#### 2.1) Database status check | ||
A possible use case in Docker environment is to check whether the database server is ready to receive incoming connections or not: | ||
~~~ | ||
#!/bin/bash | ||
until java -jar sql-runner-1.0-with-dependencies.jar -j jdbc:oracle:thin:@//oracle-db:1521/ORCLPDB1.localdomain -U "SYS as SYSDBA" -P Oradoc_db1 "select 1 from dual" | ||
until java -jar sql-runner-0.2.0-with-dependencies.jar -j jdbc:oracle:thin:@//oracle-db:1521/ORCLPDB1.localdomain -U "SYS as SYSDBA" -P Oradoc_db1 "select 1 from dual" | ||
do | ||
echo "The database server in not up and running. Waiting..." | ||
# sleep 0.5 | ||
sleep 0.5 | ||
done | ||
echo ok | ||
echo "Database server is up and running" | ||
~~~ | ||
|
||
**Usage** | ||
## 3) Usage | ||
~~~~ | ||
Usage: SqlRunner [-?sv] [-t=<dialect>] -U=<user> (-P=<password> | -I) (-j=<jdbcUrl> | (-h=<host> | ||
-p=<port> -d=<sid>)) <sql> | ||
Usage: SqlRunner [-?sv] [-c=<dialect>] -U=<user> (-P=<password> | -I) (-j=<jdbcUrl> | (-h=<host> | ||
-p=<port> -d=<database>)) <sql> | ||
SQL command line tool. It executes the given SQL and show the result on the standard output. | ||
General options: | ||
<sql> SQL to be executed. Example: 'select 1 from dual' | ||
-?, --help Display this help and exit. | ||
-v, --verbose It provides additional details as to what the tool is doing. | ||
-t, --dialect=<dialect> SQL dialect used during the execution of the SQL statement. Supported | ||
-c, --dialect=<dialect> SQL dialect used during the execution of the SQL statement. Supported | ||
SQL dialects: ORACLE. | ||
Default: ORACLE | ||
-s, --showHeader Shows the name of the fields from the SQL result set. | ||
|
@@ -39,18 +46,22 @@ Specify a password for the connecting user: | |
Custom configuration: | ||
-h, --host=<host> Name of the database server. | ||
-p, --port=<port> Number of the port where the server listens for requests. | ||
-d, --database=<sid> Name of the particular database on the server. Also known as the SID in | ||
-d, --database=<database> Name of the particular database on the server. Also known as the SID in | ||
Oracle terminology. | ||
Provide a JDBC URL: | ||
-j, --jdbcUrl=<jdbcUrl> JDBC URL, example: jdbc:oracle:<drivertype>:@//<host>:<port>/<database>. | ||
Exit codes: | ||
1 Successful program execution. | ||
2 An unexpected error appeared while executing the SQL statement. | ||
3 Usage error. User input for the command was incorrect. | ||
0 Successful program execution. | ||
1 An unexpected error appeared while executing the SQL statement. | ||
2 Usage error. User input for the command was incorrect. | ||
Please report issues at [email protected]. | ||
Documentation, source code: https://github.com/zappee/sql-runner.git | ||
~~~~ | ||
|
||
**Examples** | ||
* `java -jar target/sql-runner-1.0-with-dependencies.jar -j jdbc:oracle:thin:@//localhost:1521/ORCLPDB1.localdomain -U "SYS as SYSDBA" -P "Oradoc_db1" "select * from SLM.APPLICATION"` | ||
* `java -jar target/sql-runner-1.0-with-dependencies.jar -h localhost -p 1521 -d ORCLPDB1.localdomain -U "SYS as SYSDBA" -P "Oradoc_db1" "select * from SLM.APPLICATION"` | ||
## 4) Licence | ||
BSD (2-clause) licensed. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
import java.util.concurrent.Callable; | ||
|
||
import com.remal.sqlrunner.domain.Dialect; | ||
import com.remal.sqlrunner.domain.ExitCode; | ||
import picocli.CommandLine; | ||
import picocli.CommandLine.ArgGroup; | ||
import picocli.CommandLine.Command; | ||
|
@@ -26,11 +27,11 @@ | |
description = "SQL command line tool. It executes the given SQL and show the result on the standard output.%n", | ||
parameterListHeading = "General options:%n", | ||
exitCodeListHeading = "%nExit codes:%n", | ||
exitCodeOnUsageHelp = 3, | ||
exitCodeOnUsageHelp = ExitCode.CLI_ERROR_EXIT_CODE, | ||
exitCodeList = { | ||
"1:Successful program execution.", | ||
"2:An unexpected error appeared while executing the SQL statement.", | ||
"3:Usage error. User input for the command was incorrect." }, | ||
"0:Successful program execution.", | ||
"1:An unexpected error appeared while executing the SQL statement.", | ||
"2:Usage error. User input for the command was incorrect." }, | ||
footerHeading = "%nPlease report issues at [email protected].", | ||
footer = "%nDocumentation, source code: https://github.com/zappee/sql-runner.git") | ||
public class SqlRunner implements Callable<Integer> { | ||
|
@@ -47,7 +48,7 @@ public class SqlRunner implements Callable<Integer> { | |
description = "It provides additional details as to what the tool is doing.") | ||
private boolean verbose; | ||
|
||
@Option(names = {"-t", "--dialect"}, | ||
@Option(names = {"-c", "--dialect"}, | ||
defaultValue = Dialect.ORACLE_VALUE, | ||
showDefaultValue = CommandLine.Help.Visibility.ALWAYS, | ||
description = "SQL dialect used during the execution of the SQL statement. " | ||
|
@@ -139,7 +140,7 @@ static class CustomConfigurationGroup { | |
required = true, | ||
description = "Name of the particular database on the server. Also known as the SID in Oracle " | ||
+ "terminology.") | ||
private String sid; | ||
private String database; | ||
} | ||
|
||
/** | ||
|
@@ -180,7 +181,7 @@ public Integer call() { | |
dialect, | ||
mainArgGroup.customConfigurationGroup.host, | ||
mainArgGroup.customConfigurationGroup.port, | ||
mainArgGroup.customConfigurationGroup.sid, | ||
mainArgGroup.customConfigurationGroup.database, | ||
sql) | ||
.getExitCode(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,15 +10,30 @@ | |
* @author [email protected] | ||
*/ | ||
public enum ExitCode { | ||
|
||
/** | ||
* Used in case of the successful program execution. | ||
*/ | ||
OK(1), | ||
OK(ExitCode.OK_EXIT_CODE), | ||
|
||
/** | ||
* Command Line Interface error. | ||
* This exit code is used in case of missing command line parameter(s). | ||
*/ | ||
CLI_ERROR(ExitCode.CLI_ERROR_EXIT_CODE), | ||
|
||
/** | ||
* Used if an unexpected error appeared while executing the SQL statement. | ||
*/ | ||
SQL_ERROR(2); | ||
SQL_ERROR(ExitCode.SQL_ERROR_EXIT_CODE); | ||
|
||
/** | ||
* Exit codes constants. | ||
*/ | ||
public static final int OK_EXIT_CODE = 0; | ||
public static final int CLI_ERROR_EXIT_CODE = 1; | ||
public static final int SQL_ERROR_EXIT_CODE = 2; | ||
|
||
|
||
private int exitCodeRepresentation; | ||
|
||
|