(self)
return recovered
Recreate a database.

    Returns:
      int number of rows that were recovered from old database
      and written into new one
Recreate a database.
Recreate a database .
def _RecreateDatabase(self):
    """Recreate a database.

    Returns:
      int number of rows that were recovered from old database
      and written into new one
    """
    recovered = 0

    try:
      conn = self._Connect()
      table = []
      q = conn.execute(APPLICATION_USAGE_TABLE_SELECT)
      try:
        while 1:
          row = q.fetchone()
          if not row:
            break
          table.append(row)
      except sqlite3.Error:
        pass
        # ok, done, hit an error
      conn.close()
    except sqlite3.Error, e:
      logging.error('Unhandled error reading existing db: %s', str(e))
      return recovered

    usage_db_tmp = '%s.tmp.%d' % (APPLICATION_USAGE_DB, os.getpid())

    try:
      conn = self._Connect(usage_db_tmp)
      self._CreateApplicationUsageTable(conn)
      recovered = 0
      for row in table:
        if row[1:3] == ['', '', '']:
          continue
        try:
          conn.execute(APPLICATION_USAGE_TABLE_INSERT, row)
          conn.commit()
          recovered += 1
        except sqlite3.IntegrityError, e:
          logging.error('Ignored error: %s: %s', str(e), str(row))
      self._Close(conn)
      os.unlink(APPLICATION_USAGE_DB)
      os.rename(usage_db_tmp, APPLICATION_USAGE_DB)
    except sqlite3.Error, e:
      logging.error('Unhandled error: %s', str(e))
      recovered = 0

    return recovered
def _RecreateDatabase ( self ) : recovered = 0 try : conn = self . _Connect ( ) table = [ ] q = conn . execute ( APPLICATION_USAGE_TABLE_SELECT ) try : while 1 : row = q . fetchone ( ) if not row : break table . append ( row ) except sqlite3 . Error : pass # ok, done, hit an error conn . close ( ) except sqlite3 . Error , e : logging . error ( 'Unhandled error reading existing db: %s' , str ( e ) ) return recovered usage_db_tmp = '%s.tmp.%d' % ( APPLICATION_USAGE_DB , os . getpid ( ) ) try : conn = self . _Connect ( usage_db_tmp ) self . _CreateApplicationUsageTable ( conn ) recovered = 0 for row in table : if row [ 1 : 3 ] == [ '' , '' , '' ] : continue try : conn . execute ( APPLICATION_USAGE_TABLE_INSERT , row ) conn . commit ( ) recovered += 1 except sqlite3 . IntegrityError , e : logging . error ( 'Ignored error: %s: %s' , str ( e ) , str ( row ) ) self . _Close ( conn ) os . unlink ( APPLICATION_USAGE_DB ) os . rename ( usage_db_tmp , APPLICATION_USAGE_DB ) except sqlite3 . Error , e : logging . error ( 'Unhandled error: %s' , str ( e ) ) recovered = 0 return recovered