From cef93455a01ae322d3a4545ad7924722023bcbd9 Mon Sep 17 00:00:00 2001 From: mattbrown-msb Date: Wed, 26 Jun 2024 17:38:02 -0600 Subject: [PATCH] Opt-in to handle errors caused by long comments on tables. --- lib/odbc_adapter/schema_statements.rb | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/odbc_adapter/schema_statements.rb b/lib/odbc_adapter/schema_statements.rb index 10a02d56..5a0893ff 100644 --- a/lib/odbc_adapter/schema_statements.rb +++ b/lib/odbc_adapter/schema_statements.rb @@ -12,15 +12,27 @@ def native_database_types # Returns an array of table names, for database tables visible on the # current connection. def tables(_name = nil) - stmt = @connection.tables - result = stmt.fetch || [] - stmt.drop + begin + if @config.key?(:silo_fetch_all_tables) && @config[:silo_fetch_all_tables] + stmt = @connection.prepare("SHOW TABLES") + col_idx = stmt.columns.keys.map.with_index.to_h + q_res = stmt.execute.fetch_all + result = q_res.map { |row| [row[col_idx["database_name"]], row[col_idx["schema_name"]], row[col_idx["name"]], row[col_idx["kind"]], row[col_idx["comment"]]] } + else + stmt = @connection.tables + result = stmt.fetch_all || [] + end - result.each_with_object([]) do |row, table_names| - schema_name, table_name, table_type = row[1..3] - next if respond_to?(:table_filtered?) && table_filtered?(schema_name, table_type) + result ||= [] - table_names << format_case(table_name) + result.each_with_object([]) do |row, table_names| + schema_name, table_name, table_type = row[1..3] + next if respond_to?(:table_filtered?) && table_filtered?(schema_name, table_type) + + table_names << format_case(table_name) + end + ensure + stmt.drop end end