3

hNal)@s,ddZddZddZddZdd	Zd
S)cCsddl}ddl}ddl}d|jd<|jjddddl}|j|}y|j|}Wn4|j	k
r}zt
d|tWYdd}~XnX|S)Nz'/u01/app/oracle/product/12.2.0/dbhome_1ZORACLE_HOMEz(/home/s/sultans/web/python/demo/etl/utilzCould not connect to database)ossysZ	cx_OracleenvironpathinsertencryptZget_connection_stringconnect
DatabaseErrorprintexit)db_namerroradbrZconnect_stringconner2/home/s/sultans/web/python/demo/etl/util/oracle.pyr
s


rc
Cs"t|}y|j}|j|}Wn"tdt|tYnXt|j}g}xP|jD]F}|d}|d}	|d}
|d}|d}|d}
|d}|j|qXWg}|j}x^|dk	rd}i}x4|D],}||}|dkrd	}t	|||<|d7}qW|j||j}qW|j
|j
|S)
NzCould not execute queryr)rcursorexecuter
rlendescriptionappendZfetchonestrclose)rsqlrrresultZnumOfCol	col_namesZcolInfoZcol_nameZcol_typeZcol_display_sizeZcol_internal_sizeZ
col_precisionZ	col_scaleZcol_nullable	list_dictrowidict	col_valuerrrquery%sF


r(cCsd|}t|}y|j}|j||jWn<tjk
rj}ztd|t|tWYdd}~XnX|j|jdS)NzDROP TABLE zCould not drop table)	rrrcommitr
r	r
rr)r
table_namer rrrrrr	dropTableWs

r+cCsFddl}d|d}|d7}|d}x|jD]z\}}|d|d7}t|}|jd|sj|jdt|rt|d	7}q.|tks|tkr|d
7}q.|tkr|d7}q.|d7}q.W|dt|d
d}|d7}t	|}	y|	j
}
|
j||	jWn>t
jk
r0}ztd|t|tWYdd}~XnX|
j|	jdS)Nrz
CREATE TABLE 
z( 
z    z	 z(date|_dt|dt_)z^[0123]?\d-\w\w\w-\d\dzDATE, 
z	NUMBER, 
zVARCHAR2(250), 
zUNKNOWN DATATYPE, 
r)zCould not create table)reitemstypesearchmatchrintfloatrrrrr)r
r	r
rr)rr*r#r.r Z
firstEntryZcolnameZcolvalueZdatatyperrrrrrcreateTablens8




r5c
Cs>ddl}d}t|}y|j}x|D]}|j}|j}	d|}
|
ddj|d7}
|
d7}
x8|	D]0}t|tr|
d|d7}
qd|
t|d7}
qdW|
dt|
d	}
|
d
7}
|j	|
|d7}|ddkr$|j	d
q$W|j
Wn>tjk
r(}zt
d|t
|
tWYdd}~XnX|j|j|S)NrzINSERT INTO z (z, z) zVALUES('z', rr-rdZCOMMITzCould not execute insert)r.rrkeysvaluesjoin
isinstancerrrr)r
r	r
rr)
rr*r#r.countrrr&r"Z
col_valuesr r'rrrrrs:




rN)rr(r+r5rrrrr<module>
s2,