Created
November 7, 2023 21:07
-
-
Save rubgithub/0cc0663dc067568af25e254bc0d93a47 to your computer and use it in GitHub Desktop.
Python Firebird SQLAlchemy Connection (windows)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy import create_engine, text | |
import os | |
# I'm using the 'portable' version of firebird 2.5 32bits and Python 3.11 32bits | |
# setting the firebird client path | |
os.environ['PATH'] = r'D:\Portable\database\firebird\Firebird25\bin;%PATH%' | |
# if you're running on the cmd line terminal set the path: | |
# set PATH=D:\Portable\database\firebird\Firebird25\bin;%PATH% | |
#database string connection | |
db_uri = 'firebird+fdb://sysdba:masterkey@localhost:3050/C:/mydata/data.fdb' | |
engine = create_engine(db_uri, echo=True) | |
# Create a connection | |
conn = engine.connect() | |
# Execute a SQL query | |
result = conn.execute(text('SELECT FIRST 1 * FROM MyTable')) | |
# Iterate through the results | |
for row in result: | |
print(row) | |
# Close the connection | |
conn.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sqlalchemy | |
sqlalchemy-firebird | |
packaging | |
fdb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment