daily pastebin goal
94%
SHARE
TWEET

Untitled

a guest Jan 20th, 2017 104 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # RAW CX_ORACLE
  2.  
  3. import cx_Oracle
  4. import os
  5.  
  6. DB_USERNAME = '...'
  7. DB_PASSWORD = '...'
  8. DB_SID = '...' # basicaly a schema
  9. DB_IP = '...'
  10. DB_PORT = int
  11.  
  12. def get_sql_connection():
  13.     """Returns pre-configured Oracle connection.
  14.     """
  15.     os.environ['NLS_LANG'] = '.UTF8'  # to receive properly encoded data (if not english)
  16.  
  17.     """
  18.     TNS (Transparent Network Substrate) is Oracle's networking architecture.
  19.     TNS provides a uniform application interface to enable network
  20.     """
  21.     dsn = cx_Oracle.makedsn(DB_IP,  # dsn => data source name
  22.                             DB_PORT,
  23.                             DB_SID)  
  24.  
  25.     conn = cx_Oracle.connect(DB_USERNAME, DB_PASSWORD, dsn)
  26.  
  27.     return conn
  28.  
  29.  
  30. # RAW PSYCOPG2
  31.  
  32. import psycopg2
  33.  
  34. from psycopg2 import IntegrityError
  35.  
  36. conn = psycopg2.connect(database='...',
  37.                         user='...',
  38.                         password='...',
  39.                         host='...',
  40.                         port='...')
  41.  
  42. c = conn.cursor()
  43. conn.autocommit = True
  44.  
  45.  
  46. # SQL ALCHEMY
  47.  
  48. from sqlalchemy import create_engine, MetaData
  49.  
  50. CS = 'connection string'  # your connection string
  51.  
  52. conn = create_engine(CS)
  53.  
  54. meta = MetaData(schema='data', bind=eng)
  55. meta.reflect()
  56.  
  57. test = meta.tables['data.test']
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top