# # # # get_xref_table_exists_info() # # # include "templates.statistics.util.get_xref_table_id"; include "templates.statistics.util.get_table_exists"; include "templates.util.base_util"; subroutine(get_xref_table_exists_info( string session_id, string profile_name, node used_database_fields, string root_table_id, string sort_by_database_field_name, string sort_direction, int starting_row, int ending_row, int first_weekday, node collected_whitelist_objects), ( debug_message("\n#### get_xref_table_exists_info() \n"); # This checks if an xref table exists for the given used_database_fields, sort_by and sort_direction. # If the xref table exists it will also check for a cached table for the given row numbers, or will # perform a new query if no table exists. bool is_xref_table = false; string xref_source_table_id; string xref_root_table_id; node extended_profile_dat = get_extended_profile_dat_node_reference(session_id, profile_name); node cross_reference_groups_table_lookup = extended_profile_dat{"cross_reference_groups_table_lookup"}; # Get the xref_table_id string xref_table_id = get_xref_table_id(used_database_fields, sort_by_database_field_name, sort_direction, first_weekday); if (cross_reference_groups_table_lookup?{xref_table_id}) then ( is_xref_table = true; # The xref table source table exists xref_source_table_id = @cross_reference_groups_table_lookup{xref_table_id}; # Get a final xref root table id xref_root_table_id = root_table_id; xref_root_table_id .= "XREF_ID=" . xref_table_id; # This ID includes database fields, sort_by and sort_direction xref_root_table_id .= "STARTING_ROW=" . starting_row; xref_root_table_id .= "ENDING_ROW=" . ending_row; xref_root_table_id = md5_digest(xref_root_table_id); # Check if xref root table exists bool xref_root_table_exists = get_table_exists(profile_name, xref_root_table_id, collected_whitelist_objects); if (!xref_root_table_exists) then ( # Perform query now int first_ssql_row = starting_row - 1; int number_of_rows = ending_row - first_ssql_row; string qs = "CREATE TABLE " . xref_root_table_id . " "; qs .= "SELECT * "; qs .= "FROM " . xref_source_table_id . " "; qs .= "LIMIT " . first_ssql_row . ", " . number_of_rows; debug_message("#### get_xref_table_exists_info() qs: " . qs . "\n"); ssql_query(qs); # Add new table to collected_whitelist_objects @collected_whitelist_objects{"tables"}{xref_root_table_id} = true; ); ); node n = new_node(); @n{"is_xref_table"} = is_xref_table; @n{"xref_root_table_id"} = xref_root_table_id; @n{"xref_source_table_id"} = xref_source_table_id; # Return n; ));