diff --git a/fdb/services.py b/fdb/services.py index eceb135..774b41d 100644 --- a/fdb/services.py +++ b/fdb/services.py @@ -29,6 +29,7 @@ import struct import warnings import datetime +import types api = None @@ -760,7 +761,8 @@ def get_statistics(self, database, # 2004.06.06: False by default b/c gstat behaves that way: show_system_tables_and_indexes=0, show_record_versions=0, - callback=None + callback=None, + tables=None ): """Request database statisctics. **(ASYNC service)** @@ -775,6 +777,7 @@ def get_statistics(self, database, :param integer show_record_versions: `1` to analyze record versions. :param function callback: Function to call back with each output line. Function must accept only one parameter: line of output. + :param string_or_list tables: table name or iterable of table names. If `callback` is not specified, statistical report could be retrieved through :meth:`readline`, :meth:`readlines`, iteration over `Connection` @@ -812,6 +815,12 @@ def get_statistics(self, database, reqBuf.add_database_name(database) reqBuf.add_option_mask(optionMask) + if tables is not None: + if isinstance(tables, types.StringTypes): + tables = (tables,) + cmdline = ['-t'] + cmdline.extend(tables) + reqBuf.add_string(ibase.isc_spb_command_line, ' '.join(cmdline)) self._act(reqBuf) self.__fetching = True self.__eof = False diff --git a/test/testfdb.py b/test/testfdb.py index 1f3cfca..7847e1c 100644 --- a/test/testfdb.py +++ b/test/testfdb.py @@ -1572,6 +1572,21 @@ def fetchline(line): output = [] self.svc.get_statistics('employee', callback=fetchline) self.assertGreater(len(output),0) + # fetch only selected tables + stats = self.svc.get_statistics('employee', + show_user_data_pages=True, + tables='COUNTRY') + stats = '\n'.join(self.svc.readlines()) + self.assertIn('COUNTRY',stats) + self.assertNotIn('JOB',stats) + # + stats = self.svc.get_statistics('employee', + show_user_data_pages=True, + tables=('COUNTRY','PROJECT')) + stats = '\n'.join(self.svc.readlines()) + self.assertIn('COUNTRY',stats) + self.assertIn('PROJECT',stats) + self.assertNotIn('JOB',stats) def test_backup(self): def fetchline(line): output.append(line)