[Bio] / BioSimScratch / destroyBss.py Repository:
ViewVC logotype

Annotation of /BioSimScratch/destroyBss.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (view) (download) (as text)

1 : efrank 1.3 #!/usr/bin/env python
2 : efrank 1.1 #------------------------------------------------------------------------
3 :     #
4 : efrank 1.4 # Delete everything in an Oracle DB
5 : efrank 1.1 #
6 :     #------------------------------------------------------------------------
7 :    
8 :     import sys
9 :     import string
10 :     import cx_Oracle
11 :    
12 :    
13 :     def tryOnce():
14 :     fault=0
15 :    
16 :     c.execute( "select table_name from user_tables")
17 :     tablerows = c.fetchall()
18 :     for r in tablerows:
19 :     table=r[0]
20 :     cmd="select constraint_name from user_constraints where table_name='%s'" % (table)
21 :     c.execute(cmd)
22 :     conrows=c.fetchall()
23 :     for con in conrows:
24 :     conname=con[0]
25 :     cmd="alter table %s disable constraint %s" % (table, conname)
26 :     try:
27 :     c.execute(cmd)
28 :     except:
29 : efrank 1.2 print "failed to disable constraint ", table, conname
30 : efrank 1.1 fault=1
31 :    
32 : efrank 1.2 cmd = "drop table %s cascade constraints" % (table)
33 : efrank 1.1 try:
34 :     c.execute(cmd)
35 :     print "Dropped ", table
36 :     except:
37 : efrank 1.2 print "failed to drop table", table
38 :     fault=1
39 : efrank 1.1
40 :     c.execute( "select trigger_name from user_triggers")
41 :     rows = c.fetchall()
42 :     for r in rows:
43 :     cmd = "drop trigger %s" % (r[0])
44 :     try:
45 :     c.execute( cmd )
46 :     print "Dropped trigger ", r[0]
47 :     except:
48 : efrank 1.2 print "failed to drop trigger", r[0]
49 : efrank 1.1 fault=1
50 :    
51 : efrank 1.5 c.execute( "select sequence_name from user_sequences")
52 :     rows = c.fetchall()
53 :     for r in rows:
54 :     cmd = "drop sequence %s" % (r[0])
55 :     try:
56 :     c.execute( cmd )
57 :     print "Dropped sequence ", r[0]
58 :     except:
59 :     print "failed to drop sequence", r[0]
60 :     fault=1
61 : efrank 1.1 return fault
62 :    
63 :    
64 :    
65 :     if (__name__ == "__main__"):
66 : efrank 1.4 connectString=raw_input( "Give connect string for DB to destroy: " )
67 :     print "destroying everything in ", connectString
68 : efrank 1.1
69 : efrank 1.4 connection = cx_Oracle.connect( connectString )
70 : efrank 1.1 c = connection.cursor()
71 :    
72 :     fault=tryOnce()
73 :     connection.commit()
74 :     connection.close()
75 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3