spacepaste

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
                eid = None
                fid = None

                try:
                    print self.cursor.mogrify(
                        """SELECT * FROM emails AS e WHERE e.username = %(user)s AND e.hostname = %(host)s""",
                        {'user': username, 'host': hostname}
                    )
                    self.cursor.execute(
                        """SELECT * FROM emails AS e WHERE e.username = %(user)s AND e.hostname = %(host)s""",
                        {'user': username, 'host': hostname}
                    )
                except ProgrammingError:
                    try:
                        print self.cursor.mogrify(
                            """INSERT INTO emails (username, hostname) VALUES (%(user)s, %(host)s) RETURNING id""",
                            {'user': username, 'host': hostname}
                        )
                        self.cursor.execute(
                            """INSERT INTO emails (username, hostname) VALUES (%(user)s, %(host)s) RETURNING id""",
                            {'user': username, 'host': hostname}
                        )
                    except ProgrammingError:
                        print("select fails, insert fails. WTF?!?")
                finally:
                    try:
                        eid = self.cursor.fetchone()[0]
                    except ProgrammingError:
                        print("nothing to fetch!")
                        eid = -1
                    finally:
                        print("email: %s" % eid)

                print("at the end, the eid: %s" % eid)