예제 #1
0
 def getVersion(self):
     cu = self.dbh.cursor()
     cu.execute("SAVEPOINT getversion_save")
     try:
         try:
             return BaseDatabase.getVersion(self, raiseOnError=True)
         except sqlerrors.InvalidTable:
             self.version = sqllib.DBversion(0, 0)
             return self.version
     finally:
         cu.execute("ROLLBACK TO SAVEPOINT getversion_save")
예제 #2
0
 def getVersion(self):
     cu = self.dbh.cursor()
     cu.execute("SAVEPOINT getversion_save")
     try:
         try:
             return BaseDatabase.getVersion(self, raiseOnError=True)
         except sqlerrors.InvalidTable:
             self.version = sqllib.DBversion(0, 0)
             return self.version
     finally:
         cu.execute("ROLLBACK TO SAVEPOINT getversion_save")
예제 #3
0
    def loadSchema(self):
        BaseDatabase.loadSchema(self)
        c = self.cursor()
        # get tables
        c.execute("""
        select tablename as name, schemaname as schema
        from pg_tables
        where schemaname not in ('pg_catalog', 'pg_toast', 'information_schema')
        and ( schemaname !~ '^pg_temp_' OR schemaname = (pg_catalog.current_schemas(true))[1])
        """)
        for table, schema in c.fetchall():
            if schema.startswith("pg_temp"):
                self.tempTables[table] = sqllib.Llist()
            else:
                self.tables[table] = sqllib.Llist()
        if not len(self.tables):
            return self.version
        # views
        c.execute("""
        select viewname as name
        from pg_views
        where schemaname not in ('pg_catalog', 'pg_toast', 'information_schema')
        """)
        for name, in c.fetchall():
            self.views[name] = True
        # indexes
        c.execute("""
        select indexname as name, tablename as table, schemaname as schema
        from pg_indexes
        where schemaname not in ('pg_catalog', 'pg_toast', 'information_schema')
        and ( schemaname !~ '^pg_temp_' OR schemaname = (pg_catalog.current_schemas(true))[1])
        """)
        for (name, table, schema) in c.fetchall():
            if schema.startswith("pg_temp"):
                self.tempTables.setdefault(table, sqllib.Llist()).append(name)
            else:
                self.tables.setdefault(table, sqllib.Llist()).append(name)
        # sequences. I wish there was a better way...
        c.execute("""
        SELECT c.relname as name
        FROM pg_catalog.pg_class c
        LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
        WHERE c.relkind = 'S'
        AND n.nspname NOT IN ('pg_catalog', 'pg_toast', 'information_schema')
        AND pg_catalog.pg_table_is_visible(c.oid)
        """)
        for name, in c.fetchall():
            self.sequences[name] = True
        # triggers
        # AWKWARD: postgres 9.0 changed tgisconstraint to tgisinternal, so we
        # have to detect which it is to maintain compatibility :(
        #   -- gxti 2010-11-01
        c.execute("""
            SELECT a.attname
            FROM pg_catalog.pg_attribute a
            LEFT JOIN pg_catalog.pg_class c ON a.attrelid = c.oid
            LEFT JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
            WHERE n.nspname = 'pg_catalog' AND c.relname = 'pg_trigger'
            AND a.attname in ('tgisconstraint', 'tgisinternal')
            """)
        colname, = c.fetchone()

        c.execute("""
        SELECT t.tgname, c.relname
        FROM pg_catalog.pg_trigger t, pg_class c, pg_namespace n
        WHERE t.tgrelid = c.oid AND c.relnamespace = n.oid
        AND NOT t.%(colname)s
        AND n.nspname NOT IN ('pg_catalog', 'pg_toast', 'information_schema')
        AND ( n.nspname !~ '^pg_temp_' OR n.nspname = (pg_catalog.current_schemas(true))[1])
        """ % dict(colname=colname))
        for (name, table) in c.fetchall():
            self.triggers[name] = table
        version = self.getVersion()
        return version
예제 #4
0
    def loadSchema(self):
        BaseDatabase.loadSchema(self)
        c = self.cursor()
        # get tables
        c.execute("""
        select tablename as name, schemaname as schema
        from pg_tables
        where schemaname not in ('pg_catalog', 'pg_toast', 'information_schema')
        and ( schemaname !~ '^pg_temp_' OR schemaname = (pg_catalog.current_schemas(true))[1])
        """)
        for table, schema in c.fetchall():
            if schema.startswith("pg_temp"):
                self.tempTables[table] = sqllib.Llist()
            else:
                self.tables[table] = sqllib.Llist()
        if not len(self.tables):
            return self.version
        # views
        c.execute("""
        select viewname as name
        from pg_views
        where schemaname not in ('pg_catalog', 'pg_toast', 'information_schema')
        """)
        for name, in c.fetchall():
            self.views[name] = True
        # indexes
        c.execute("""
        select indexname as name, tablename as table, schemaname as schema
        from pg_indexes
        where schemaname not in ('pg_catalog', 'pg_toast', 'information_schema')
        and ( schemaname !~ '^pg_temp_' OR schemaname = (pg_catalog.current_schemas(true))[1])
        """)
        for (name, table, schema) in c.fetchall():
            if schema.startswith("pg_temp"):
                self.tempTables.setdefault(table, sqllib.Llist()).append(name)
            else:
                self.tables.setdefault(table, sqllib.Llist()).append(name)
        # sequences. I wish there was a better way...
        c.execute("""
        SELECT c.relname as name
        FROM pg_catalog.pg_class c
        LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
        WHERE c.relkind = 'S'
        AND n.nspname NOT IN ('pg_catalog', 'pg_toast', 'information_schema')
        AND pg_catalog.pg_table_is_visible(c.oid)
        """)
        for name, in c.fetchall():
            self.sequences[name] = True
        # triggers
        # AWKWARD: postgres 9.0 changed tgisconstraint to tgisinternal, so we
        # have to detect which it is to maintain compatibility :(
        #   -- gxti 2010-11-01
        c.execute("""
            SELECT a.attname
            FROM pg_catalog.pg_attribute a
            LEFT JOIN pg_catalog.pg_class c ON a.attrelid = c.oid
            LEFT JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
            WHERE n.nspname = 'pg_catalog' AND c.relname = 'pg_trigger'
            AND a.attname in ('tgisconstraint', 'tgisinternal')
            """)
        colname, = c.fetchone()

        c.execute("""
        SELECT t.tgname, c.relname
        FROM pg_catalog.pg_trigger t, pg_class c, pg_namespace n
        WHERE t.tgrelid = c.oid AND c.relnamespace = n.oid
        AND NOT t.%(colname)s
        AND n.nspname NOT IN ('pg_catalog', 'pg_toast', 'information_schema')
        AND ( n.nspname !~ '^pg_temp_' OR n.nspname = (pg_catalog.current_schemas(true))[1])
        """ % dict(colname=colname))
        for (name, table) in c.fetchall():
            self.triggers[name] = table
        version = self.getVersion()
        return version