Skip to content

Commit

Permalink
- Added support for isc_spb_sts_table option : PYFB-68
Browse files Browse the repository at this point in the history
  • Loading branch information
pcisar committed Nov 24, 2016
1 parent c37c256 commit 8782c5f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
11 changes: 10 additions & 1 deletion fdb/services.py
Expand Up @@ -29,6 +29,7 @@
import struct
import warnings
import datetime
import types

api = None

Expand Down Expand Up @@ -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)**
Expand All @@ -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`
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions test/testfdb.py
Expand Up @@ -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)
Expand Down

0 comments on commit 8782c5f

Please sign in to comment.