win32ole with ADO 経由でプライマリキーの取り方が分からん
field 名とカラムタイプの取り方は分かったんだけど、プライマリキーの取得方法が謎・・・
primary = connection.OpenSchema(28 , ["pubs", "dbo", table_name])
配列の引数の pubs と dbo を何か設定すれば良さそうだけど不明。
require 'win32ole' module RecordSet def [] field self.Fields.Item(field).Value end def []= field,value self.Fields.Item(field).Value = value end def each_record if self.EOF or self.BOF return end self.MoveFirst until self.EOF or self.BOF yield self self.MoveNext end end end connection = WIN32OLE.new("ADODB.Connection") connstr = "Driver={Microsoft Access Driver (*.mdb)};DBQ=test.mdb;" connection.Open(connstr) table_name = "Users" # get fields schemas = connection.OpenSchema(4 , [nil, nil, table_name]) schemas.extend RecordSet schemas.each_record{|r| puts r["Column_Name"] + "-" + r["Data_Type"].to_s } # get primary keys primary = connection.OpenSchema(28 , ["pubs", "dbo", table_name]) primary.extend RecordSet primary.each_record{|r| puts r["Column_Name"] }