def columns(table_name, name = nil)
jdbc_connection = @connection.connection
@unquoted_schema ||= select_one("show search_path")['search_path']
table_results = jdbc_connection.meta_data.get_tables(
jdbc_connection.catalog,
@unquoted_schema,
table_name,
["TABLE","VIEW","SYNONYM"].to_java(:string)
)
table_exists = table_results.next
table_results.close
raise "table '#{table_name}' not found" unless table_exists
column_results = jdbc_connection.meta_data.get_columns(
jdbc_connection.catalog,
@unquoted_schema,
table_name,
nil
)
columns = []
while column_results.next
type_clause = column_results.get_string('TYPE_NAME')
precision = column_results.get_int('COLUMN_SIZE')
scale = column_results.get_int('DECIMAL_DIGITS')
if precision > 0
type_clause += "(#{precision}#{scale > 0 ? ",#{scale}" : ""})"
end
columns << ::ActiveRecord::ConnectionAdapters::JdbcColumn.new(
@config,
column_results.get_string('COLUMN_NAME'),
column_results.get_string('COLUMN_DEF'),
type_clause,
column_results.get_string('IS_NULLABLE').strip == "NO"
)
end
column_results.close
columns
end