Update of /cvsroot/ruby-dbi/src/lib/dbd_db2
In directory sc8-pr-cvs1:/tmp/cvs-serv19370
Modified Files:
Tag: DB2BLOBS
DB2.rb
Log Message:
DB2 driver support for columns(table)
Index: DB2.rb
===================================================================
RCS file: /cvsroot/ruby-dbi/src/lib/dbd_db2/DB2.rb,v
retrieving revision 1.6.4.1
retrieving revision 1.6.4.2
diff -u -r1.6.4.1 -r1.6.4.2
--- DB2.rb 28 Dec 2002 14:36:30 -0000 1.6.4.1
+++ DB2.rb 21 Apr 2003 18:09:08 -0000 1.6.4.2
@@ -149,6 +149,39 @@
}
end
+ def columns(table)
+ tabschema, tabname = nil, nil
+ if md = /([^\.]*)\.(.*)/.match(table)
+ tabschema, tabname = md[1], md[2]
+ else
+ raise 'table name should be in SCHEMA.TABLE notation'
+ end
+ query = %{
+ SELECT colname, typename, length, scale, default, nulls
+ FROM syscat.columns
+ WHERE tabschema = '#{tabschema}' AND tabname = '#{tabname}'
+ }
+ if (arr = execute(query).fetch_all)
+ return arr.collect { |row|
+ #sql_type, type_name = DB2_to_DBI_type_mapping[row[1]] # FIXME: map column names to constants
+ ColumnInfo.new({
+ 'name' => row[0],
+ #'type_name' => type_name,
+ #'sql_type' => sql_type,
+ 'type_name' => row[1],
+ 'sql_type' => row[1],
+ 'precision' => row[2],
+ 'scale' => row[3],
+ 'default' => row[4],
+ 'nullable' => (row[5] == 'Y')
+ #'indexed'
+ #'primary'
+ #'unique'
+ })
+ }
+ end
+ end
+
def ping
begin
stmt = execute("SELECT 1 FROM SYSCAT.TABLES")
@@ -179,8 +212,6 @@
def [](attribute)
@attr[attribute]
end
-
- # TODO: method columns(table)
def commit
rc = SQLEndTran(SQL_HANDLE_DBC, @handle, SQL_COMMIT)
|