Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # RAW CX_ORACLE
- import cx_Oracle
- import os
- DB_USERNAME = '...'
- DB_PASSWORD = '...'
- DB_SID = '...' # basicaly a schema
- DB_IP = '...'
- DB_PORT = int
- def get_sql_connection():
- """Returns pre-configured Oracle connection.
- """
- os.environ['NLS_LANG'] = '.UTF8' # to receive properly encoded data (if not english)
- """
- TNS (Transparent Network Substrate) is Oracle's networking architecture.
- TNS provides a uniform application interface to enable network
- """
- dsn = cx_Oracle.makedsn(DB_IP, # dsn => data source name
- DB_PORT,
- DB_SID)
- conn = cx_Oracle.connect(DB_USERNAME, DB_PASSWORD, dsn)
- return conn
- # RAW PSYCOPG2
- import psycopg2
- from psycopg2 import IntegrityError
- conn = psycopg2.connect(database='...',
- user='...',
- password='...',
- host='...',
- port='...')
- c = conn.cursor()
- conn.autocommit = True
- # SQL ALCHEMY
- from sqlalchemy import create_engine, MetaData
- CS = 'connection string' # your connection string
- conn = create_engine(CS)
- meta = MetaData(schema='data', bind=eng)
- meta.reflect()
- test = meta.tables['data.test']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement