Skip to content

Commit cef9345

Browse files
committed
Opt-in to handle errors caused by long comments on tables.
1 parent c57096e commit cef9345

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

lib/odbc_adapter/schema_statements.rb

+19-7
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,27 @@ def native_database_types
1212
# Returns an array of table names, for database tables visible on the
1313
# current connection.
1414
def tables(_name = nil)
15-
stmt = @connection.tables
16-
result = stmt.fetch || []
17-
stmt.drop
15+
begin
16+
if @config.key?(:silo_fetch_all_tables) && @config[:silo_fetch_all_tables]
17+
stmt = @connection.prepare("SHOW TABLES")
18+
col_idx = stmt.columns.keys.map.with_index.to_h
19+
q_res = stmt.execute.fetch_all
20+
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"]]] }
21+
else
22+
stmt = @connection.tables
23+
result = stmt.fetch_all || []
24+
end
1825

19-
result.each_with_object([]) do |row, table_names|
20-
schema_name, table_name, table_type = row[1..3]
21-
next if respond_to?(:table_filtered?) && table_filtered?(schema_name, table_type)
26+
result ||= []
2227

23-
table_names << format_case(table_name)
28+
result.each_with_object([]) do |row, table_names|
29+
schema_name, table_name, table_type = row[1..3]
30+
next if respond_to?(:table_filtered?) && table_filtered?(schema_name, table_type)
31+
32+
table_names << format_case(table_name)
33+
end
34+
ensure
35+
stmt.drop
2436
end
2537
end
2638

0 commit comments

Comments
 (0)