Changeset 9477

Show
Ignore:
Timestamp:
04/16/08 15:46:44 (7 months ago)
Author:
jim++
Message:

Added helpers to commit in logger.py
Trying to ignore line for #3865

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/common/logger.py

    r9462 r9477  
    136136                self.get_jids_already_in_db() 
    137137 
     138        def simple_commit(self, sql_to_commit): 
     139                '''helper to commit''' 
     140                self.cur.execute(sql_to_commit) 
     141                try: 
     142                        self.con.commit() 
     143                except sqlite.OperationalError, e: 
     144                        print >> sys.stderr, str(e) 
     145 
    138146        def get_jids_already_in_db(self): 
    139147                try: 
     
    145153                for row in rows: 
    146154                        # row[0] is first item of row (the only result here, the jid) 
    147                         self.jids_already_in.append(row[0]) 
     155                        if row[0] == '': 
     156                                # malformed jid, ignore line 
     157                                pass 
     158                        else: 
     159                                self.jids_already_in.append(row[0]) 
    148160 
    149161        def get_jids_in_db(self): 
     
    332344                ''' add unread message with id: message_id''' 
    333345                sql = 'INSERT INTO unread_messages VALUES (%d, %d)' % (message_id, jid_id) 
    334                 self.cur.execute(sql) 
    335                 try: 
    336                         self.con.commit() 
    337                 except sqlite.OperationalError, e: 
    338                         print >> sys.stderr, str(e) 
     346                self.simple_commit(sql) 
    339347 
    340348        def set_read_messages(self, message_ids): 
     
    342350                ids = ','.join([str(i) for i in message_ids]) 
    343351                sql = 'DELETE FROM unread_messages WHERE message_id IN (%s)' % ids 
    344                 self.cur.execute(sql) 
    345                 try: 
    346                         self.con.commit() 
    347                 except sqlite.OperationalError, e: 
    348                         print >> sys.stderr, str(e) 
     352                self.simple_commit(sql) 
    349353 
    350354        def get_unread_msgs(self): 
     
    626630                sql = 'REPLACE INTO rooms_last_message_time VALUES (%d, %d)' % \ 
    627631                        (jid_id, time) 
    628                 self.cur.execute(sql) 
    629                 try: 
    630                         self.con.commit() 
    631                 except sqlite.OperationalError, e: 
    632                         print >> sys.stderr, str(e) 
     632                self.simple_commit(sql) 
    633633 
    634634        def _build_contact_where(self, account, jid): 
     
    663663                        if result == type_id: 
    664664                                return 
    665                         self.cur.execute( 
    666                                 'UPDATE transports_cache SET type = %d WHERE transport = "%s"' % ( 
    667                                 type_id, jid)) 
    668                         try: 
    669                                 self.con.commit() 
    670                         except sqlite.OperationalError, e: 
    671                                 print >> sys.stderr, str(e) 
     665                        sql = 'UPDATE transports_cache SET type = %d WHERE transport = "%s"' %\ 
     666                                (type_id, jid) 
     667                        self.simple_commit(sql) 
    672668                        return 
    673                 self.cur.execute( 
    674                         'INSERT INTO transports_cache VALUES ("%s", %d)' % (jid, type_id)) 
    675                 try: 
    676                         self.con.commit() 
    677                 except sqlite.OperationalError, e: 
    678                         print >> sys.stderr, str(e) 
     669                sql = 'INSERT INTO transports_cache VALUES ("%s", %d)' % (jid, type_id) 
     670                self.simple_commit(sql) 
    679671 
    680672        def get_transports_type(self): 
     
    757749                gzip.close() 
    758750                data = string.getvalue() 
    759                 self.cur.execute(''' 
     751                sql = ''' 
    760752                        INSERT INTO caps_cache ( node, ver, ext, data ) 
    761753                        VALUES (?, ?, ?, ?); 
    762                         ''', (node, ver, ext, buffer(data))) # (1) -- note above 
    763                 try: 
    764                         self.con.commit() 
    765                 except sqlite.OperationalError, e: 
    766                         print >> sys.stderr, str(e) 
     754                        ''', (node, ver, ext, buffer(data)) # (1) -- note above 
     755                self.simple_commit(sql)