[問題] Perl -> Win32::ODBC -> Access MDB

看板Perl作者 (ing)時間17年前 (2007/11/21 21:57), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/1
是這樣的 因為某些歷史包袱 現在小弟得用 Perl -> ODBC -> Access MDB 的方式 存取資料 需要存取的 MDB 裡面有五六個表格 在google之後 有找到使用 Win32::ODBC 的方式 可是 下 select * from 表格 之後 回來的record 數目 跟 mdb 裡實際的資料數不合 大概是這樣的情況 表格 A B C D 資料筆數 24 4000 120 20 select * 回來的筆數 20 2 120 20 表格 A 是目前第一步要查詢的資料 裡面有 五欄 共 24 筆資料 (編號,名稱,數量,安全存量,是否下訂) 可是 表格 A 如果下的是 " select * from 表格 " 回來的筆數有 20 筆 如果下的是 "select * from 表格 order by 編號" 回來的筆數卻只有12筆 而且 以 " select * from 表格 where 數量 < 安全存量 " 查詢的話 在前12筆記錄 也就是 select * 會回來的那12筆裡 符合條件的都會被查到 但是另外的12筆就好像消失一樣 完全看不到 想請教這個可能是哪邊的設定有誤需要調整呢? 在此先謝過m(_._)m 附上code ======== #!c:\perl\bin\perl.exe -w use Win32::ODBC; $dsn = "cart"; $table = "表格A"; # ====== Check if the database can be opened correctly if (!($db = new Win32::ODBC($dsn))) { print "Error in opening DSN \"$dsn\"!\n"; print "Error: " . Win32::ODBC::Error(). "\n"; exit; } # ====== Select all fields from the given table #$sql = "select B_name from $table;"; #$sql = "select * from $table order by Category;"; $sql = "select * from $table;"; # ====== Check if the SQL query is correct if ($db->Sql($sql)) { print "Error in SQL query: \"$sql\"!\n"; print "Error: " . $db->Error() . "\n"; $db->Close(); exit; } # ====== Print field data print "Content-type: text/html\n\n"; print "<html><body><pre>\n"; $count = 1; @FieldNames = $db->FieldNames(); while ($db->FetchRow()) { print "Record $count\n"; # ($newsSiteID, $classID) = $db->Data("newsSiteID", "classID"); # undef %Data; %Data = $db->DataHash(); foreach $x (@FieldNames) { if(!defined($x)) {$x='NOT';} print "$x: $Data{$x}\n"; } print "\n"; $count++; } $db->Close(); print "</pre></body></html>\n"; -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.134.36.154

11/27 03:20, , 1F
有點要轉MySQL的哀傷
11/27 03:20, 1F
文章代碼(AID): #17H3aoDN (Perl)
文章代碼(AID): #17H3aoDN (Perl)