Skip to main content

Firebirdsql wrapper inspired by subprocess.run

Project description

firebirdsql-run

Firebirdsql wrapper inspired by subprocess.run

PyPI version Main pre-commit.ci codecov

Installation

pip install firebirdsql-run

Examples

Execute a query with read-only access:

from firebirdsql_run import DBAccess, execute

# Execute a query with read-only access.
result = execute(query="SELECT * FROM table", db="database", access=DBAccess.READ_ONLY)

# Output: List of dictionaries containing the query results.
print(result.data)

Execute a query with parameters:

# Execute a query with parameters.
result = execute(q"INSERT INTO customers (name, age) VALUES (?, ?)", params=("John", 25))

# Output: List of dictionaries containing the query results.
print(result.data)

Execute a query using the existing connection:

# Create a connection object.
conn = connection(db="/path/to/database.fdb")
# Execute a query using the existing connection.
result = execute(query="SELECT * FROM table", use_conn=conn)
# Close the connection.
conn.close()

# Output: 0 (success) or 1 (error).
print(result.returncode)

Completed transaction

When you execute a query, firebirdsql-run returns a CompletedTransaction object.
This object contains the following attributes:

  • host: The host address of the server.
  • port: The port number of the server.
  • db: The database where the transaction was executed.
  • user: The user who executed the transaction.
  • access: The access mode used for the transaction.
  • returncode: The return code of the transaction execution.
  • exception: The exception message if the transaction failed.
  • query: The SQL query executed in the transaction.
  • params: The parameters used in the SQL query.
  • time: The number of seconds it took to execute the transaction.
  • data: The data returned by the transaction, represented as a list of dictionaries.

Queried table:

maker model type
B 1121 PC
A 1232 PC

An example of a successful transaction:

CompletedTransaction(
    host="127.0.0.1",
    db="database",
    user="TWUSER",
    access="READ_ONLY",
    returncode=0,
    exception="",
    query="SELECT * FROM table",
    params=(),
    time=0.001,
    data=[
        {"maker": "B", "model": 1121, "type": "PC"},
        {"maker": "A", "model": 1232, "type": "PC"},
    ],
)

An example of a failed transaction:

CompletedTransaction(
    host="127.0.0.1",
    db="database",
    user="TWUSER",
    access="READ_ONLY",
    returncode=1,
    exception="Dynamic SQL Error\nSQL error code = -204\nTable unknown\ntable\nAt line 1, column 15\n",
    query="SELECT * FROM table",
    params=(),
    time=0.001,
    data=[],
)

Env variables

FIREBIRD_KEY=

The FIREBIRD_KEY environment variable can be overridden with the functions argument passwd.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

firebirdsql_run-1.1.0.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

firebirdsql_run-1.1.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file firebirdsql_run-1.1.0.tar.gz.

File metadata

  • Download URL: firebirdsql_run-1.1.0.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for firebirdsql_run-1.1.0.tar.gz
Algorithm Hash digest
SHA256 250e63ece6f9957591f5042d66c6894d43f66d971f66d5dcd45969837f1ea63d
MD5 b1617eb99bf8bf5980a3f596b798a4f1
BLAKE2b-256 5e16cd4dae94e0e87abe014415d9cd79413d6367c9b0bad585078fff3e6a050d

See more details on using hashes here.

File details

Details for the file firebirdsql_run-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for firebirdsql_run-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 89b0a1447b6c6ed27a8afcd0be95694be4f70e8027d5c807d102d93fb790a50f
MD5 a87314aab02352744a3fdc23c56b6549
BLAKE2b-256 f3a6173f72cbf545ad4b51b789b7db8594c67c0c8eaeac0ce78eb34505f421f3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page