Command Line Interface

RazorSQL has a command line interface for users to call RazorSQL operations without actually launching the RazorSQL graphical program. The command line interface can be used for users who want to run scheduled programs such as nightly batch scripts.

RazorSQL version 5.2 and newer includes a GUI tool for generating command line calls. The GUI tool is available via the following menu option:

DB Tools -> Command Line Call Generator

Please consider using the above tool to generate commands. This tool will contain only commands and parameters that are supported for the version of RazorSQL you are using.

 

Executing a Command

To use the RazorSQL command line interface, RazorSQL must be launched from a command prompt or terminal window or script. There are potentially slight differences depending on whether the operating system is Windows, Mac OS X, or Linux / Unix.

The format to run RazorSQL in command mode is the following:

java -jar razorsql.jar -command "parameter1" "parameter2" . . .

For example:

OS X / Linux / Unix

Change directory to the RazorSQL installation directory and execute the following:

java -jar razorsql.jar -export "Oracle Express" "select * from employee" csv "/Users/user/employee.txt" yes

Windows

Change directory to the RazorSQL installation directory and execute the following:

jre\bin\java -jar razorsql.jar -export "Oracle Express" "select * from employee" csv "C:\data\employee.txt" yes

For commands that may take a large amount of memory, the initial and max heap size settings for RazorSQL can be increased using the following syntax:

java -Xms64M -Xmx384M -jar razorsql.jar -command "parameter1" "parameter2" . . .

This command will start RazorSQL with 64MB of initial memory, with a maximum memory of 384MB.

 

Supported Commands

RazorSQL 5.5.4 adds the following command:

  • -compare (for comparing the results of two queries)

RazorSQL versions 5.2 and newer support the following commands:

  • -backup (for backing up a database or schema)
  • -backuptable (for backing up a database table)
  • -execute (for executing an SQL script file)
  • -export (for exporting a database table)
  • -import (for importing data into a database table)

RazorSQL versions 5.1.6 and earlier support the following commands:

  • -export (for exporting a database table)
  • -import (for importing data into a database table)

 

Export Tables

The -export command has the following parameters:

NOTE: Any parameters with spaces need to be enclosed in quotes (" ")

parameter 1 [required]: -export (the command to execute)

parameter 2 [required]: profile_name (the name of the profile to use to get the connection)
NOTE: The profile must have the save password option checked

parameter 3 [required]: query or path to file containing a query (the query to run to get the data to export) if this value is a path to an existing file, RazorSQL will read the contents of the file and execute it as a query

parameter 4 [required]: export_format (csv,tsv,xls,insert)

parameter 5 [required]: file to export data to

parameter 6 [optional]: show_columns (yes,no)

parameter 7 [optional]: convert nulls to blanks (yes,no)

parameter 8 [optional]: trim spaces (yes,no)

parameter 9 [optional]: date format (MM = month, dd = day, yyyy = year)

parameter 10 [optional]: timestamp format (MM = month, dd = day, yyyy = year, HH = hour, mm = minute, ss = second, SSS = millisecond)

parameter 11 (RazorSQL 5.6.2 or later) [optional]: characters to append at the end of each row

 

Import Table Data

The -import command has the following parameteres:

NOTE: Any parameters with spaces need to be enclosed in quotes (" ")

parameter 1 [required]: -import (the command to execute)

parameter 2 [required]: profile_name (the name of the profile to use to get the connection)
NOTE: The profile must have the save password option checked

parameter 3 [required]: delimited_file_location (the location of the comma, tab, or space delimited file)

parameter 4 [required]: delimiter (valid options are COMMA, SPACE, or TAB)

parameter 5 [required]: database (the database that contains the table, enter "null" if this is not applicable)

parameter 6 [required]: schema_or_owner (the schema or owner that contains the table, enter "null" if this is not applicable)

parameter 7 [required]: table (the name of the table to import the data to)

 

Backup Schema / Database

The -backup command has the following parameters:

NOTE: Any parameters with spaces need to be enclosed in quotes (" ")

parameter 1 [required]: -backup (the command to execute)

parameter 2 [required]: profile_name (the name of the profile to use to get the connection)
NOTE: The profile must have the save password option checked

parameter 3 [required]: database (the database that contains the objects. Enter "null" if this is not applicable)

parameter 4 [required]: schema (the schema that contains the objects. Enter "null" if this is not applicable)

parameter 5 [required]: SQL statement separator (enter the text to use to separate SQL statements generated, for example, ;)

parameter 6 [required]: backup file encoding (enter null for default or the name of the encoding, e.g., "UTF-8")

parameter 7 [required]: backup file location (enter the path to the backup file)

parameter 8 [required]: fully qualify object names (YES or NO)

parameter 9 [required]: objects to back up (comma separated list of objects to back up, e.g., tables,views,indexes,procedures,functions,triggers)

parameter 10 [optional]: only generate DDL. Do not generate SQL insert statements for table data.

 

Backup Table

The -backuptable command has the following parameters:

NOTE: Any parameters with spaces need to be enclosed in quotes (" ")

parameter 1 [required]: -backuptable (the command to execute)

parameter 2 [required]: profile_name (the name of the profile to use to get the connection)
NOTE: The profile must have the save password option checked

parameter 3 [required]: database (the database that contains the objects. Enter "null" if this is not applicable)

parameter 4 [required]: schema (the schema that contains the objects. Enter "null" if this is not applicable)

parameter 5 [required]: table (the name of the table to backup)

parameter 6 [required]: SQL statement separator (enter the text to use to separate SQL statements generated, for example, ;)

parameter 7 [required]: backup file encoding (enter null for default or the name of the encoding, e.g., "UTF-8")

parameter 8 [required]: backup file location (enter the path to the backup file)

parameter 9 [required]: fully qualify object names (YES or NO)

parameter 10 [optional]: only generate DDL. Do not generate SQL insert statements.

 

Execute SQL Script

The -execute command has the following parameters:

NOTE: Any parameters with spaces need to be enclosed in quotes (" ")

parameter 1 [required]: -execute (the command to execute)

parameter 2 [required]: profile_name (the name of the profile to use to get the connection)
NOTE: The profile must have the save password option checked

parameter 3 [required]: sql file location (the location of the SQL script to execute)

parameter 4 [required]: sql statement separator

parameter 5 [required]: sql file encoding (enter null for default or the name of the encoding, e.g., "UTF-8")

parameter 6 [required]: batch size (how many statements to execute per network call)

 

Compare

The compare command has the following parameters:

NOTE: Any parameters with spaces need to be enclosed in quotes (" ")

parameter 1 [required]: -compare

parameter 2 [required]: profile_name1 (the name of the connection profile to use to get the connection)
NOTE: The profile must have the save password option checked

parameter 3 [required]: query1 (the query to execute on profile_name1)

parameter 4 [required]: profile_name2 (the name of the connection profile to use to get the connection)
NOTE: The profile must have the save password option checked

parameter 5 [required]: query2 (the query to execute on profile_name2)

parameter 6 [required]: output_file (the location of the output file that the compare results will get written to)