执行sql查询并将结果存储在excel文件中的命令行程序
sqlexceller的Python项目详细描述
SQL到Excel转换器
执行SQL查询并将结果存储在Excel文件中的命令行程序
- 免费软件:apache软件许可证2.0
功能
- 支持PostgreSQL、MySQL、Oracle、MSSQL和SQLite
- 接受多个SQL查询文件
- 每个SQL查询都将写入不同的工作表中
- 参数化查询
- 参数化输出文件名
安装
要安装,只需运行:
$ pip install --upgrade sqlexceller
使用帮助
usage: sqlexceller [-h] [-v] [--output OUTPUT] [--db_connection_info URL] [--param PARAMS] file [file ...] sqlexceller tool The tool will execute SQL queries and generate an Excel file with the results. positional arguments: file SQL Query file optional arguments: -h, --help show this help message and exit -v, --version show program's version number and exit --output OUTPUT, -o OUTPUT Output file --db_connection_info URL, -d URL DB connection information as an URL in the form of dialect[+driver]://username:password@host:port/database. --param PARAMS, -p PARAMS Adds a parameter for the SQL queries. Parameter must be specified as a key=value pair. This argument can be repeated as many times as necessary. Available dialects and drivers are: - postgresql: - psycopg2 - pg8000 - mysql: - mysqldb - mysqlconnector - oursql - oracle: - cx_oracle - mssql: - pyodbc - pymssql - sqlite There are some default parameters that will always be present: - NUM_QUERY - QUERY_NAME - DATE - DAY - MONTH - YEAR Usage examples: - Execute a simple query on a SQLite DB. sqlexceller query.sql -d sqlite:///example.db - Execute multiple queries with 2 different parameters and a custom output file on a PostgreSQL DB: Contents of query1.sql: SELECT * FROM stocks where transaction = :transaction; Contents of query2.sql: SELECT * FROM stocks where transaction = :transaction and product = :product; sqlexceller query1.sql query2.sql -p transaction=BUY -p product=HAT \ -o "report :trans (:MONTH-:DAY).xlsx" \ -d postgresql://user:password@localhost/mydatabase Generated file will be something like: "report BUY (10-16).xlsx"
报告问题
如果您发现了sqlexceller的问题,下面介绍如何报告该问题:
- 首选方法是在github上提交一个bug:
- 转到项目的issue tracker on GitHub
- 用有关问题的信息提交新问题
- 感谢您帮助改进sqlexceller
使用页面顶部的搜索字段< /LI>搜索现有问题 - 如果您没有github帐户,并且不希望创建一个帐户,您可以 给我发邮件。
历史记录
0.1.1(2018-03-17)
- 修正1:查询结果集为空时出现异常
0.1.0(2016-10-16)
- pypi上的第一个版本。