How to use the psycopg.ProgrammingError function in psycopg

To help you get started, we’ve selected a few psycopg examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github odoo / odoo / doc / migrate / 3.3.0-3.4.0 / pre.py View on Github external
cr.commit()

# ----------------------------------------------------- #
# add some fields (which cannot be added automatically) #
# ----------------------------------------------------- #

for line in (
        "alter table ir_model_fields add group_name varchar(64)",
        "alter table ir_model_fields add view_load boolean",
        "alter table ir_model_fields alter group_name set default ''",
        "alter table ir_model_fields alter view_load set default False",
        "delete from ir_values where value like '%,False'",
    ):
    try:
        cr.execute(line)
    except psycopg.ProgrammingError, e:
        cr.commit()
        print e

cr.commit()
cr.close()
github joliebig / featurehouse / fstmerge / examples / SpamBayes / rev3250-3267 / right-branch-3267 / spambayes / storage.py View on Github external
def load(self):
        '''Load state from database'''
        import psycopg
        if options["globals", "verbose"]:
            print('Loading state from', self.db_name, 'database', file=sys.stderr)
        self.db = psycopg.connect('dbname=' + self.db_name)
        c = self.cursor()
        try:
            c.execute("select count(*) from bayes")
        except psycopg.ProgrammingError:
            self.db.rollback()
            self.create_bayes()
        if self._has_key(self.statekey):
            row = self._get_row(self.statekey)
            self.nspam = row["nspam"]
            self.nham = row["nham"]
            if options["globals", "verbose"]:
                print(('%s is an existing database,'
                                      ' with %d spam and %d ham') \
                      % (self.db_name, self.nspam, self.nham), file=sys.stderr)
        else:
            if options["globals", "verbose"]:
                print(self.db_name,'is a new database', file=sys.stderr)
            self.nspam = 0
            self.nham = 0
class mySQLClassifier(SQLClassifier):
github smontanaro / spambayes / spambayes / spambayes / storage.py View on Github external
def load(self):
        '''Load state from database'''

        import psycopg

        if options["globals", "verbose"]:
            print >> sys.stderr, 'Loading state from',self.db_name,'database'

        self.db = psycopg.connect('dbname=' + self.db_name)

        c = self.cursor()
        try:
            c.execute("select count(*) from bayes")
        except psycopg.ProgrammingError:
            self.db.rollback()
            self.create_bayes()

        if self._has_key(self.statekey):
            row = self._get_row(self.statekey)
            self.nspam = row["nspam"]
            self.nham = row["nham"]
            if options["globals", "verbose"]:
                print >> sys.stderr, ('%s is an existing database,'
                                      ' with %d spam and %d ham') \
                      % (self.db_name, self.nspam, self.nham)
        else:
            # new database
            if options["globals", "verbose"]:
                print >> sys.stderr, self.db_name,'is a new database'
            self.nspam = 0
github smontanaro / spambayes / spambayes / spambayes / storage.py View on Github external
def load(self):
        '''Load state from database'''

        import psycopg

        if options["globals", "verbose"]:
            print >> sys.stderr, 'Loading state from', self.db_name, 'database'

        self.db = psycopg.connect('dbname=' + self.db_name)

        c = self.cursor()
        try:
            c.execute("select count(*) from bayes")
        except psycopg.ProgrammingError:
            self.db.rollback()
            self.create_bayes()

        if self._has_key(self.statekey):
            row = self._get_row(self.statekey)
            self.nspam = row["nspam"]
            self.nham = row["nham"]
            if options["globals", "verbose"]:
                print >> sys.stderr, ('%s is an existing database,'
                                      ' with %d spam and %d ham') \
                      % (self.db_name, self.nspam, self.nham)
        else:
            # new database
            if options["globals", "verbose"]:
                print >> sys.stderr, self.db_name,'is a new database'
            self.nspam = 0
github dustin / snippets / python / tiger / loader.py View on Github external
sizein[f] = nr

print "Need to load " + str(totalcount) + " records."

dbconn=psycopg.connect('dbname=tiger host=disk port=2345 user=dustin ' \
    + 'password=blahblah')

c=dbconn.cursor()

stats=Stats.Stats(totalcount)

for f in argv[1:]:
    try:
        zf = zipfile.ZipFile(f)
        loadAll(c, f, zf)
    except psycopg.ProgrammingError, e:
        if str(e).find("load_filesbyname"):
            print "Aready did " + f
            stats.reduceWorkload(sizein[f])
            print stats.getStats()
        else:
            raise e

dbconn.close()
github joliebig / featurehouse / fstmerge / examples / SpamBayes / rev3250-3267 / base-trunk-3250 / spambayes / storage.py View on Github external
def load(self):
        '''Load state from database'''
        import psycopg
        if options["globals", "verbose"]:
            print >> sys.stderr, 'Loading state from', self.db_name, 'database'
        self.db = psycopg.connect('dbname=' + self.db_name)
        c = self.cursor()
        try:
            c.execute("select count(*) from bayes")
        except psycopg.ProgrammingError:
            self.db.rollback()
            self.create_bayes()
        if self._has_key(self.statekey):
            row = self._get_row(self.statekey)
            self.nspam = row["nspam"]
            self.nham = row["nham"]
            if options["globals", "verbose"]:
                print >> sys.stderr, ('%s is an existing database,'
                                      ' with %d spam and %d ham') \
                      % (self.db_name, self.nspam, self.nham)
        else:
            if options["globals", "verbose"]:
                print >> sys.stderr, self.db_name,'is a new database'
            self.nspam = 0
            self.nham = 0
class mySQLClassifier(SQLClassifier):
github joliebig / featurehouse / fstmerge / examples / SpamBayes / rev3103-3133 / right-branch-3133 / spambayes / storage.py View on Github external
def load(self):
        '''Load state from database'''
        import psycopg
        if options["globals", "verbose"]:
            print >> sys.stderr, 'Loading state from',self.db_name,'database'
        self.db = psycopg.connect('dbname=' + self.db_name)
        c = self.cursor()
        try:
            c.execute("select count(*) from bayes")
        except psycopg.ProgrammingError:
            self.db.rollback()
            self.create_bayes()
        if self._has_key(self.statekey):
            row = self._get_row(self.statekey)
            self.nspam = row["nspam"]
            self.nham = row["nham"]
            if options["globals", "verbose"]:
                print >> sys.stderr, ('%s is an existing database,'
                                      ' with %d spam and %d ham') \
                      % (self.db_name, self.nspam, self.nham)
        else:
            if options["globals", "verbose"]:
                print >> sys.stderr, self.db_name,'is a new database'
            self.nspam = 0
            self.nham = 0
class mySQLClassifier(SQLClassifier):
github joliebig / featurehouse / fstmerge / examples / SpamBayes / rev3103-3133 / base-trunk-3103 / spambayes / storage.py View on Github external
def load(self):
        '''Load state from database'''
        import psycopg
        if options["globals", "verbose"]:
            print >> sys.stderr, 'Loading state from',self.db_name,'database'
        self.db = psycopg.connect('dbname=' + self.db_name)
        c = self.cursor()
        try:
            c.execute("select count(*) from bayes")
        except psycopg.ProgrammingError:
            self.db.rollback()
            self.create_bayes()
        if self._has_key(self.statekey):
            row = self._get_row(self.statekey)
            self.nspam = row["nspam"]
            self.nham = row["nham"]
            if options["globals", "verbose"]:
                print >> sys.stderr, ('%s is an existing database,'
                                      ' with %d spam and %d ham') \
                      % (self.db_name, self.nspam, self.nham)
        else:
            if options["globals", "verbose"]:
                print >> sys.stderr, self.db_name,'is a new database'
            self.nspam = 0
            self.nham = 0
class mySQLClassifier(SQLClassifier):
github dustin / snippets / python / net / index.py View on Github external
pass

        subject_line=''
        try:
            subject_line=headers['subject'][0]
        except IndexError:
            pass

        try:
            self.c.execute('insert into messages(folder_id, messid, ' \
                + 'from_line, to_line, subject_line, timestamp)\n' \
                + '\tvalues(%(boxid)i, %(messid)s, %(from)s, %(to)s, ' \
                + '%(subject)s, now())',
                { 'boxid': boxid, 'messid': messid, 'from': from_line,
                'to': to_line, 'subject': subject_line})
        except psycopg.ProgrammingError, e:
            if str(e).find('messages_bymid') >= 0:
                raise DuplicateMessage, messid
            else:
                raise e
        self.c.execute("select currval('messages_message_key_seq')")
        rv=self.c.fetchall()
        return rv[0][0]