2011-03-07 30 views
1

是否有一種便攜的方式在Perl中列出*.mdb文件 (即Microsoft Jet數據庫,也稱爲「Access數據庫」)中的表名?如何在Perl中使用DBI列出Jet數據庫的表名?

通常我用Cygwin在Windows上運行我的Perl腳本。

我可以使用DBD::ODBC模塊在*.mdb數據庫上運行SQL查詢,但它沒有實現DBI的table_info函數,該函數完全符合我的需要。 DBD::ADO和/或Win32::OLE模塊可能可以用來代替,但他們拒絕在Cygwin下安裝,我寧願有一個可移植的解決方案 - 理想情況下,它甚至可以在Linux上工作。

DBIx::Class::Schema::Loader模塊可用於做到這一點,我理解它正在進行升級,它實際上在*.mdb文件的工作,但它有,我真的不希望依賴一個巨大的列表,安裝,無論我跑我的腳本只是爲了獲得這個單一的功能。

你有沒有編寫Perl代碼列出*.mdb文件中的表名? 你使用了哪種技術?爲什麼?

回答

4

哪裏有這個傳言來自那些DBD :: ODBC不支持table_info - 這是在一週內第三次我已經看到了它:

perl -le 'use DBI; my $h = DBI->connect("dbi:ODBC:access_sample"); my $t = $h->table_info(undef, undef, undef, "TABLE");print DBI::dump_results($t);' 

'/home/martin/test.mdb', undef, 'A', 'TABLE', undef 
'/home/martin/test.mdb', undef, 'MSysNavPaneGroupCategories', 'TABLE', undef 
'/home/martin/test.mdb', undef, 'MSysNavPaneGroupToObjects', 'TABLE', undef 
'/home/martin/test.mdb', undef, 'MSysNavPaneGroups', 'TABLE', undef 
'/home/martin/test.mdb', undef, 'MSysNavPaneObjectIDs', 'TABLE', undef 
'/home/martin/test.mdb', undef, 'PERL_DBD_TABLE1', 'TABLE', undef 
'/home/martin/test.mdb', undef, 'PERL_DBD_TEST', 'TABLE', undef 
'/home/martin/test.mdb', undef, 'TestTable', 'TABLE', undef 
'/home/martin/test.mdb', undef, 'X', 'TABLE', undef 
'/home/martin/test.mdb', undef, 'unicode', 'TABLE', undef 
10 rows 
+0

嗯,在我的情況,我得到了錯誤:'DBD :: ODBC :: db table_info失敗:[Microsoft] [ODBC Microsoft Access驅動程序]未實現的可選功能(SQL-HYC00)(...)'...但我沒有提供undef作爲前三個參數。我錯誤地解釋了錯誤消息意味着整個'table_info'函數不被支持。 – reinierpost 2011-03-07 14:42:05

相關問題