Last active
September 7, 2017 01:47
-
-
Save laughingman7743/9d129116a35413a44d53 to your computer and use it in GitHub Desktop.
This file contains 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
# Oracle | |
export ORACLE_HOME=~/bin/oracle/instantclient_11_2 | |
export PATH=$ORACLE_HOME:$PATH | |
export DYLD_LIBRARY_PATH=$ORACLE_HOME | |
export LD_LIBRARY_PATH=$ORACLE_HOME |
This file contains 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
#!/bin/bash | |
pip install cx_Oracle |
This file contains 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
#!/bin/bash | |
ln -s ~/bin/oracle/instantclient_11_2/libclntsh.dylib.11.1 ~/bin/oracle/instantclient_11_2/libclntsh.dylib | |
ln -s ~/bin/oracle/instantclient_11_2/libocci.dylib.11.1 ~/bin/oracle/instantclient_11_2/libocci.dylib |
This file contains 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import urllib | |
from sqlalchemy.dialects.oracle.base import VARCHAR2, CHAR, DATE | |
from sqlalchemy.engine import create_engine | |
from sqlalchemy.ext.declarative.api import declarative_base | |
from sqlalchemy.orm.session import sessionmaker | |
from sqlalchemy.sql.schema import Column | |
ORACLE_USER = 'YOUR_USER' | |
ORACLE_PASSWORD = 'YOUR_PASSWORD' | |
ORACLE_HOST = 'YOUR_HOST' | |
ORACLE_PORT = 'YOUR_PORT' | |
ORACLE_SID = 'YOUR_SID' | |
ORACLE_CONNECTION_STRING = 'oracle+cx_oracle://%(user)s:%(password)s@%(server)s:%(port)s/%(sid)s' % { | |
'user': ORACLE_USER, | |
'password': urllib.quote_plus(ORACLE_PASSWORD), | |
'server': ORACLE_HOST, | |
'port': ORACLE_PORT, | |
'sid': ORACLE_SID} | |
Base = declarative_base() | |
class YourTable(Base): | |
__tablename__ = 'YOUR_TABLE' | |
__table_args__ = {'schema': 'YOUR_SCHEMA'} | |
column_1 = Column('COLUMN_1', VARCHAR2, primary_key=True) | |
column_2 = Column('COLUMN_2', VARCHAR2) | |
column_3 = Column('COLUMN_3', CHAR) | |
column_4 = Column('COLUMN_4', DATE) | |
def main(): | |
engine = create_engine(ORACLE_CONNECTION_STRING, coerce_to_unicode=True, echo=True) | |
conn = engine.connect() | |
session = sessionmaker(bind=engine)() | |
query = session.query(YourTable) | |
for q in query: | |
print(q.column_1) | |
print(q.column_2) | |
print(q.column_3) | |
print(q.column_4) | |
session.close() | |
conn.close() | |
engine.dispose() | |
if __name__ == '__main__': | |
main() |
This file contains 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import cx_Oracle | |
ORACLE_USER = 'YOUR_USER' | |
ORACLE_PASSWORD = 'YOUR_PASSWORD' | |
ORACLE_HOST = 'YOUR_HOST' | |
ORACLE_PORT = 'YOUR_PORT' | |
ORACLE_SID = 'YOUR_SID' | |
def main(): | |
dsn = cx_Oracle.makedsn(ORACLE_HOST, ORACLE_PORT, ORACLE_SID) | |
con = cx_Oracle.connect(ORACLE_USER, ORACLE_PASSWORD, dsn) | |
if (con): | |
print('Connection successful') | |
print(con.version) | |
else: | |
print('Connection not successful') | |
con.close() | |
if __name__ == '__main__': | |
main() |
This file contains 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
#!/bin/bash | |
xcode-select --install |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment