import groovy.sql.Sql
sql = Sql.newInstance(
"jdbc:h2:tcp://localhost/~/test",
"sa",
"",
"org.h2.Driver")
tableSchema = "PUBLIC"
tableName = "TEST1"
query = """
select
cols.table_schema,
cols.table_name,
cols.column_name,
cols.type_name || '(' ||
case when (type_info.params = 'LENGTH' OR
type_info.params is null) then
cast(cols.character_maximum_length as varchar)
else
cols.numeric_precision || ', ' || cols.numeric_scale
end || ')' as coltype
from
information_schema.columns cols
join information_schema.type_info
on (cols.type_name = type_info.type_name)
where
cols.table_schema = ${tableSchema}
and cols.table_name = ${tableName}
order by cols.ordinal_position
"""
// カラムを一覧表示する
sql.eachRow(query){
print("${it.table_schema},${it.table_name},")
println("${it.column_name},${it.coltype}")
}
動作環境
groovy 1.7.4, JDK6 Update 21, H2 Database 1.2.143 (2010-09-18)
0 件のコメント:
コメントを投稿