# HG changeset patch # User Alexandre Fayolle # Date 1314371677 -7200 # Node ID 681ef2a664ddd5c883507adcd49937d693d339cc # Parent 458cb2edf63afba5acb78c0df40f4fa87afd5995 work around cursor.rowcount not returning anything useful before 1st fetch with mssql (closes #1910869) use select count(*) from table to get the number of rows diff -r 458cb2edf63a -r 681ef2a664dd server/sources/native.py --- a/server/sources/native.py Wed Jul 27 16:43:07 2011 +0200 +++ b/server/sources/native.py Fri Aug 26 17:14:37 2011 +0200 @@ -1686,21 +1686,24 @@ archive.writestr('sequences/%s' % seq, serialized) def write_table(self, archive, table): + nb_lines_sql = 'SELECT COUNT(*) FROM %s' % table + self.cursor.execute(nb_lines_sql) + rowcount = self.cursor.fetchone()[0] sql = 'SELECT * FROM %s' % table columns, rows_iterator = self._get_cols_and_rows(sql) - self.logger.info('number of rows: %d', self.cursor.rowcount) + self.logger.info('number of rows: %d', rowcount) if table.startswith('cw_'): # entities blocksize = 2000 else: # relations and metadata blocksize = 10000 - if self.cursor.rowcount > 0: - for i, start in enumerate(xrange(0, self.cursor.rowcount, blocksize)): + if rowcount > 0: + for i, start in enumerate(xrange(0, rowcount, blocksize)): rows = list(itertools.islice(rows_iterator, blocksize)) serialized = self._serialize(table, columns, rows) archive.writestr('tables/%s.%04d' % (table, i), serialized) self.logger.debug('wrote rows %d to %d (out of %d) to %s.%04d', start, start+len(rows)-1, - self.cursor.rowcount, + rowcount, table, i) else: rows = []