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

View of /BioSimScratch/destroyBss.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (download) (as text) (annotate)
Fri Nov 19 19:08:51 2004 UTC (15 years ago) by efrank
Branch: MAIN
CVS Tags: post-st-migration2, post-st-migration, HEAD
Changes since 1.4: +10 -0 lines
fixes

#!/usr/bin/env python
#------------------------------------------------------------------------
#
# Delete everything in an Oracle DB
#
#------------------------------------------------------------------------

import sys
import string
import cx_Oracle


def tryOnce():
    fault=0

    c.execute( "select table_name from user_tables")
    tablerows = c.fetchall()
    for r in tablerows:
        table=r[0]
        cmd="select constraint_name from user_constraints where table_name='%s'" % (table) 
        c.execute(cmd)
        conrows=c.fetchall()
        for con in conrows:
            conname=con[0]
            cmd="alter table %s disable constraint %s" % (table, conname)
            try:
                c.execute(cmd)
            except:
                print "failed to disable constraint ", table, conname
                fault=1

        cmd = "drop table %s cascade constraints" % (table)
        try:
            c.execute(cmd)
            print "Dropped ", table
        except:
            print "failed to drop table", table
            fault=1

    c.execute( "select trigger_name from user_triggers")
    rows = c.fetchall()
    for r in rows:
        cmd = "drop trigger %s" % (r[0])
        try:
            c.execute( cmd )
            print "Dropped trigger ", r[0]
        except:
            print "failed to drop trigger", r[0]
            fault=1

    c.execute( "select sequence_name from user_sequences")
    rows = c.fetchall()
    for r in rows:
        cmd = "drop sequence %s" % (r[0])
        try:
            c.execute( cmd )
            print "Dropped sequence ", r[0]
        except:
            print "failed to drop sequence", r[0]
            fault=1
    return fault



if (__name__ == "__main__"):
    connectString=raw_input( "Give connect string for DB to destroy: " )
    print "destroying everything in ", connectString
    
    connection = cx_Oracle.connect( connectString )
    c = connection.cursor()

    fault=tryOnce()
    connection.commit()
    connection.close()


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3