Esempio n. 1
0
    def _destroy_catalog(self, conn, ignored_cur, catalog):
        """Destroys a catalog.
        
           Do not call this method directly.

           NOTE: This code looks b0rken; notice reference to _dbc which is never defined
        """
        cur = None
        try:
            conn.set_isolation_level(
                psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)

            # first, attempt to disconnect clients
            cur = conn.cursor()
            cur.execute("""
SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE datname = %(dbname)s
  AND pid <> pg_backend_pid()
;""" % dict(dbname=sql_literal(catalog.descriptor[self._KEY_DBNAME])))

            #TODO: note that a client could reconnect ...now... and prevent the drop

            # then, drop database
            cur.execute("DROP DATABASE " +
                        sql_identifier(catalog.descriptor[self._KEY_DBNAME]))

            cur.close()

        except psycopg2.Error, ev:
            msg = str(ev)
            idx = msg.find("\n")  # DETAIL starts after the first line feed
            if idx > -1:
                msg = msg[0:idx]
            raise RuntimeError(msg)
Esempio n. 2
0
    def _destroy_catalog(self, conn, ignored_cur, catalog):
        """Destroys a catalog.
        
           Do not call this method directly.

           NOTE: This code looks b0rken; notice reference to _dbc which is never defined
        """
        cur = None
        try:
            conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
            
            # first, attempt to disconnect clients
            cur = conn.cursor()
            cur.execute("""
SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE datname = %(dbname)s
  AND pid <> pg_backend_pid()
;"""
                % dict(dbname=sql_literal(catalog.descriptor[self._KEY_DBNAME])))
            
            #TODO: note that a client could reconnect ...now... and prevent the drop
            
            # then, drop database
            cur.execute("DROP DATABASE " + 
                        sql_identifier(catalog.descriptor[self._KEY_DBNAME]))

            cur.close()
            
        except psycopg2.Error, ev:
            msg = str(ev)
            idx = msg.find("\n") # DETAIL starts after the first line feed
            if idx > -1:
                msg = msg[0:idx]
            raise RuntimeError(msg)
Esempio n. 3
0
 def body(conn, cur):
     # create database
     try:
         conn.set_isolation_level(
             psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
         cur.execute("CREATE DATABASE " + sql_identifier(dbname))
     except psycopg2.Error, ev:
         msg = str(ev)
         idx = msg.find("\n")  # DETAIL starts after the first line feed
         if idx > -1:
             msg = msg[0:idx]
         raise RuntimeError(msg)
Esempio n. 4
0
 def body(conn, ignored_cur):
     # create database
     cur = None
     try:
         conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
         cur = conn.cursor()
         cur.execute("CREATE DATABASE " + sql_identifier(dbname))
     except psycopg2.Error, ev:
         msg = str(ev)
         idx = msg.find("\n")  # DETAIL starts after the first line feed
         if idx > -1:
             msg = msg[0:idx]
         raise RuntimeError(msg)