GithubHelp home page GithubHelp logo

vzhn / row-export Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 1.0 31 KB

SQL insert script generator. Rows accessable by foreign keys also included.

Java 100.00%
oracle-database jdbc sql insert-script sql-exporter topological-ordering

row-export's Introduction

usage: row-export [options]
 -e,--expression <arg>   expression
 -h,--help               show help and exit
 -l,--login <arg>        jdbc connection login
 -p,--password <arg>     jdbc connection password
 -u,--url <arg>          jdbc connection url

Usage example for a Northwind database:

./row-export --url jdbc:oracle:thin:@localhost:1521:XE --login northwind --password northwind -e "ORDERS ORDER_ID:10440"

Row selection expression explained:

ORDERS ORDER_ID:10440
^      ^        ^ 
|      |        +------- primary key value
|      +---------------- primary key column
+----------------------- table name

It is possible to define multiple rows using ; separator:

ORDERS ORDER_ID:10440; CUSTOMERS CUSTOMER_ID:71

If primary key consists of one column it can be omitted:

ORDERS 10440; CUSTOMERS 71

Output:

INSERT INTO NORTHWIND.SHIPPERS(SHIPPER_ID,COMPANY_NAME,PHONE) VALUES 
  (2,'United Package','(503) 555-3199');
INSERT INTO NORTHWIND.EMPLOYEES(EMPLOYEE_ID,LASTNAME,FIRSTNAME,TITLE,TITLE_OF_COURTESY,BIRTHDATE,HIREDATE,ADDRESS,CITY,REGION,POSTAL_CODE,COUNTRY,HOME_PHONE,EXTENSION,PHOTO,NOTES) VALUES 
  (2,'Fuller','Andrew','Vice President, Sales','Dr.',to_date('19.02.1952 00:00:00','DD.MM.YYYY HH24:MI:SS'),to_date('14.08.1992 00:00:00','DD.MM.YYYY HH24:MI:SS'),'908 W. Capital Way','Tacoma','WA','98401','USA','(206) 555-9482','3457','andrew  .jpg','Andrew received his BTS commercial and a Ph.D. in international marketing from the University of Dallas.  He is fluent in French and Italian and reads German.  He joined the company as a sales representative, was promoted to sales manager and was then named vice president of sales.  Andrew is a member of the Sales Management Roundtable, the Seattle Chamber of Commerce, and the Pacific Rim Importers Association.');
INSERT INTO NORTHWIND.CUSTOMERS(CUSTOMER_ID,CUSTOMER_CODE,COMPANY_NAME,CONTACT_NAME,CONTACT_TITLE,ADDRESS,CITY,REGION,POSTAL_CODE,COUNTRY,PHONE) VALUES 
  (71,'SAVEA','Save-a-lot Markets','Jose Pavarotti','Sales Representative','187 Suffolk Ln.','Boise','ID','83720','USA','(208) 555-8097');
INSERT INTO NORTHWIND.EMPLOYEES(EMPLOYEE_ID,LASTNAME,FIRSTNAME,TITLE,TITLE_OF_COURTESY,BIRTHDATE,HIREDATE,ADDRESS,CITY,REGION,POSTAL_CODE,COUNTRY,HOME_PHONE,EXTENSION,PHOTO,NOTES,REPORTS_TO) VALUES 
  (4,'Peacock','Margaret','Sales Representative','Mrs.',to_date('19.09.1958 00:00:00','DD.MM.YYYY HH24:MI:SS'),to_date('03.05.1993 00:00:00','DD.MM.YYYY HH24:MI:SS'),'4110 Old Redmond Rd.','Redmond','WA','98052','USA','(206) 555-8122','5176','margaret.jpg','Margaret holds a BA in English literature from Concordia College and an MA from the American Institute of Culinary Arts. She was temporarily assigned to the London office before returning to her permanent post in Seattle.',2);
INSERT INTO NORTHWIND.ORDERS(ORDER_ID,CUSTOMER_ID,EMPLOYEE_ID,ORDER_DATE,REQUIRED_DATE,SHIPPED_DATE,SHIP_VIA,FREIGHT,SHIP_NAME,SHIP_ADDRESS,SHIP_CITY,SHIP_REGION,SHIP_POSTAL_CODE,SHIP_COUNTRY) VALUES 
  (10440,71,4,to_date('10.02.1997 00:00:00','DD.MM.YYYY HH24:MI:SS'),to_date('10.03.1997 00:00:00','DD.MM.YYYY HH24:MI:SS'),to_date('28.02.1997 00:00:00','DD.MM.YYYY HH24:MI:SS'),2,86.53,'Save-a-lot Markets','187 Suffolk Ln.','Boise','ID','83720','USA');

When topological sorting for selected rows is not possible you'll see cycles detected exception message

Building

mvn clean package appassembler:assemble assembly:single

When build completes, you should see an application archive in the target folder:

target\row-export-1.0-SNAPSHOT-bin.zip

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.