Giter Site home page Giter Site logo

ase-db-tool's Introduction

ASE Database Connection Tool

This Python script provides a command-line interface for connecting to an Adaptive Server Enterprise (ASE) database, executing SQL commands, and exporting query results to CSV files.

Features

  • Connect to an ASE database without using a DSN.
  • Execute SQL commands interactively.
  • Switch between databases dynamically.
  • Export query results to timestamped CSV files.
  • Clear terminal screen for better readability.

Requirements

  • Python 3.x
  • pyodbc library
  • tabulate library

Installation

  1. Clone the repository (if applicable):

    git clone https://github.com/your-repository/ase-connection-tool.git
    cd ase-connection-tool
  2. Install the required packages:

    pip install pyodbc tabulate
  3. Ensure the Adaptive Server Enterprise ODBC driver is installed:

    • Follow the instructions provided by SAP to install the ASE ODBC driver on your system.

Usage

  1. Edit the config.ini to set your database connection parameters:

    server = '<server>'  
    port = '<port>'
    user = '<username>'
    password = '<password>'
    database = '<database_name>' # You have the ability to switch db later.
  2. Run the script:

    python ase_connection_tool.py
  3. Interact with the tool:

    • Enter your SQL commands at the prompt.
    • Use the exit command to quit the tool.
    • Use the clear command to clear the terminal screen.
    • Switch databases by using the USE <database_name> command.
    • Results of the queries will be displayed in a tabulated format and saved as CSV files with timestamps.

Example

python ase_connection_tool.py

Console Output

Connection successful!
Enter your SQL command for database DATABASE (or 'exit' to quit, 'clear' to clear screen): SELECT * FROM my_table;
Results for query: SELECT * FROM my_table written to query_results_20230701_123456.csv
Results for query: SELECT * FROM my_table
+----+----------+-----------+
| ID | Name     | Value     |
+----+----------+-----------+
| 1  | Example1 | 123       |
| 2  | Example2 | 456       |
+----+----------+-----------+
Enter your SQL command for database DATABASE (or 'exit' to quit, 'clear' to clear screen):

Notes

  • The tool handles empty input gracefully.
  • If the USE <database_name> command is used, the tool will attempt to switch the database context.
  • Query results are saved as CSV files in the same directory as the script with a unique timestamp.

ase-db-tool's People

Contributors

iam-aaron avatar

Watchers

 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.