fishdist.sql_tools

combine_single_file_queries(lst, sql_command, table_names=None, db_name='pyTA.db', return_header=False, prepend_frame_nb=True, prepend_file_name=True, output_filename=None)

Combine the results of single file queries into a master data set.

Parameters:
  • lst (list) –

    List of file paths to query.

  • sql_command (str) –

    SQL command to execute for each file.

  • table_names (str or list, default: None ) –

    Names of tables to include in the query. Defaults to None.

  • db_name (str, default: 'pyTA.db' ) –

    Name of the database file. Defaults to 'pyTA.db'.

  • return_header (bool, default: False ) –

    Flag to indicate whether to return the header. Defaults to False.

  • prepend_frame_nb (bool, default: True ) –

    Flag to indicate whether to prepend the frame number to the data. Defaults to True.

  • prepend_file_name (bool, default: True ) –

    Flag to indicate whether to prepend the file name to the data. Defaults to True.

  • output_filename (str, default: None ) –

    Name of the output file to save the combined data. Defaults to None.

Returns:
  • tuple or list: If output_filename is None and return_header is False, returns the combined data as a list. If output_filename is None and return_header is True, returns the header and combined data as a tuple. If output_filename is provided, saves the combined data to the specified file and returns None.

Examples:

>>> lst = ['file1.db', 'file2.db', 'file3.db']

>>> sql_command = 'SELECT * FROM data'

>>> combine_single_file_queries(lst, sql_command, table_names='my_table', output_filename='combined_data.csv')

>>> lst = ['file1.db', 'file2.db', 'file3.db']

>>> sql_command = 'SELECT * FROM data WHERE value > 10'

>>> header, data = combine_single_file_queries(lst, sql_command, return_header=True)

>>> print(header)

>>> print(data)