Monday, October 19, 2009

guide to installing cx_Oracle on Mac OSX

Ran into some trouble after I installed python 2.6, and found this helpful blog entry. Kept getting "Symbol not found: ___divdi3" error. Unfortunately, the advice didn't work for me, but it does seem to have worked for a number of people. The only thing that worked for me was ditching the 2.6 install and reverting back to OSX's default 2.5.1 version.

Build and install cx_Oracle on MacOS X Leopard Intel

Friday, October 16, 2009

python script to list oracle tables and indexes


import cx_Oracle
orcl = cx_Oracle.connect('username/password@db')
curs = orcl.cursor()

schema='my_schema'

curs.execute("""
select table_name from all_tables where owner=:own
order by 1
""",own=schema)

table_names=curs.fetchall()

tables=[]

class TableInfo:
def __init__ (self,tname):
self.name=tname
indexes={}
partitions={}


for tn in table_names:
t=TableInfo(tn[0])
indexlist={}
curs.execute("""
select index_name from all_indexes where table_name=:tbl
""",tbl=t.name)
index_names=curs.fetchall()

colnames=[]

for xn in index_names:
curs.execute("""
select column_name from all_ind_columns where index_name=:ind
""",ind=xn[0])

col_names=curs.fetchall()

for cn in col_names:
colnames.append(cn[0])

indexlist[xn[0]]=cn[0]

t.indexes=indexlist
tables.append(t)

for t in tables:
print t.name,t.indexes

curs.close()
orcl.close()