Giter Site home page Giter Site logo

richardschoen / pythonibmicli Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 36 KB

IBM i Python cli Scripts with CL commands to query databases or insert, update delete individual records. These can be used on any platform including IBMi - AS/400 with QSHONI/QSHEXEC

Python 67.47% Batchfile 11.01% CLIPS 21.52%
as400 cli command-line ibmi python pase qsh qshell db2 ibm-db

pythonibmicli's Introduction

IBM i Python CLI Scripts to query databases or insert, update delete individual records

This repository will contain ready-to-run command line (CLI) utility app examples for querying, inserting and updating data using a command line Python script.

Sample CL wrappers will also be added that call the scripts via an IBM i CL command.

Several versions will be added for: IBM i DB2, ODBC, SQLite, MariaDB, PostgreSQL and SQL Server. Possibly more.

Use Case

RPG and CL cannot easily directly communicate with remote databases.

These Python scripts and commands will provide an easy way to query remote data and bring back results as CSV or other delimited resultsets for consumption directly from the IFS by an RPG program or by importing to a database via the CPYFRMIMP command (Copy From Import File).

Record results can also be returned in JSON format. These results can be then consumed in RPG via the YAJL library ported by Scott Klement (https://www.scottklement.com/yajl), noxDB library (https://github.com/sitemule/noxDB) or the DATA-INTO opcode in RPG (https://www.ibm.com/docs/en/i/7.5?topic=codes-data-into-parse-document-into-variable).

INSERT, UPDATE and DELETE commands can also be issued to update the selected remote database as well covering the entire CRUD cycle for data access.

ibmdbcli.py - Python command line interface (CLI) script to query or write data to DB2 with ibm_db driver

This script will run IBM DB2 database operations via native DB2 driver: python-ibmdb.

This script is similar to the IBM i db2util pase app for querying data, but it's a native Python scripting.

IBM i prerequisites
IBM i V7R3 and above
Python 3.6 or 3.9 on IBM i
QShell on i - (http://www.github.com/richardschoen/qshoni)

Pip packages needed
pip install ibm_db (IBM Database driver)

Parameters

--action - Action to perform. 
           QUERY - SQL SELECT Query     
           NONQUERY - SQL non query action. Ex: INSERT, UPDATE, DELETE  
           **NOTE: The CLI will not currently work with stored procedures.  
--sql - SQL query or action to run  
--outputtype - Output format for query. csv or json formats  
--delimiter - Output file delimiter for query to csv. Default = ,  
--outputfile - Output text file for QUERY action. No output for NONQUERY.  
--replace - Replace output file for query. True/False. Default = True  

Examples

Query table QIWS/QCUSCTDT and write to IFS file as CSV python3 ibmdbcli.py --sql "select * from qiws.qcustcdt" --outputfile "/tmp/qcustcdt.csv" --replace "true" --outputtype "csv" --delimiter ","

Query table QIWS/QCUSCTDT and write to IFS file as JSON python3 ibmdbcli.py --sql "select * from qiws.qcustcdt" --outputfile "/tmp/qcustcdt.csv" --replace "true" --outputtype "json"

Insert new record into table QIWS/QCUSTCDT python3 ibmdbdb.py --sql "insert into qiws.qcustcdt (cusnum,lstnam) values(123456,'Jones') " --outputfile "/tmp/qcustcdt.txt" --action "nonquery"

IBMDBCLI - CL wrapper command front end for ibmdbcli.py

Query table QIWS/QCUSCTDT and write to IFS file as CSV file.
Calls the ibmdbcli.py Python script via the QSHONI/QSHEXEC command.

IBMDBCLI SCRIPTFILE('/pythonapps/ibmdbcli.py')                                      
         SQL('select * from qiws.qcustcdt')                  
         ACTION('QUERY')                                     
         OUTPUTFILE('/tmp/qcustcdt.csv')                          
         FIELEDELIM(',')                                     
         REPLACE(*YES) 
         OUTPUTTYPE(CSV)

pythonibmicli's People

Contributors

richardschoen avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

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.