# # # # get_table_exists() # # # subroutine(get_table_exists( string profile_name, string table_id, node collected_whitelist_objects), ( debug_message("\n\n#### get_table_exists() START\n\n"); bool table_exists = false; bool table_exists_in_database = false; bool table_exists_in_whitelist = false; # Check if the table is in disk whitelist or in memory whitelist in case that it hasn't been checked-out to disk yet. if (?("profiles_cache." . profile_name . ".whitelist.tables." . table_id) or ?(collected_whitelist_objects . ".tables." . table_id)) then ( table_exists_in_whitelist = true; ); table tables_like_table_id = ssql_query("SHOW TABLES LIKE " . table_id); # DEBUG_BEGIN # debug_message( # string the_table_string = table_as_string(tables_like_table_id); # "\n" . the_table_string . "\n"; # ); # DEBUG_END for (int i = 0; i < table_get_num_rows(tables_like_table_id); i++) ( debug_message("check table existance table name: " . table_get_cell_string_value(tables_like_table_id, i, 0) . "\n"); if (table_get_cell_string_value(tables_like_table_id, i, 0) eq table_id) then ( table_exists_in_database = true; last; ); ); unload_table(tables_like_table_id); if (table_exists_in_database and table_exists_in_whitelist) then ( table_exists = true; ) else if (table_exists_in_database and !table_exists_in_whitelist) then ( # This table has most likely been created while some error/crash occured because # it does not exist in the whitelist but in the database. So we delete this table # prior a new one is created. debug_message("#### get_table_exists() - DROP TABLE BECAUSE IT IS NOT IN WHITELIST\n\n"); ssql_query("DROP TABLE " . table_id); ); debug_message("#### get_table_exists() - table_exists_in_database: " . table_exists_in_database . "\n"); debug_message("#### get_table_exists() - table_exists_in_whitelist: " . table_exists_in_whitelist . "\n"); debug_message("#### get_table_exists() - table_exists: " . table_exists . "\n"); table_exists; debug_message("#### get_table_exists() END\n\n"); ));