2009年1月4日星期日

[PerlChina] Re: perl读取access数据库时由于值里包含windows路径的"\"导致的问题

感谢分享,也算学到一招了。呵呵
--
blog : http://hi.baidu.com/smallfish7788
bbs : http://bbs.chinaunix.net/forum-55-1.html
smallfish / xiaoyu9805119

--------------------------------------------------
From: "大大" <xiaozuovip@gmail.com>
Sent: Monday, January 05, 2009 10:52 AM
To: "PerlChina 论坛" <perlchina@googlegroups.com>
Subject: [PerlChina] Re: perl读取access数据库时由于值里包含windows路径的"\"导致的问题

> 找到解决方法了,是由于字数限制到的,加上下列内容就ok了,哈哈。
>
> $dbh->{LongReadLen} = 1000000;
> $dbh->{LongTruncOk} = 1;
>
>
> On 1月4日, 下午7时01分, 大大 <xiaozuo...@gmail.com> wrote:
>> 环境:
>>
>> perl读取access数据库
>>
>> 使用DBI建立连接:
>>
>> my $DSN = "driver=Microsoft Access Driver (*.mdb);dbq=d:\\jk\
>> \test.mdb";
>> my $dbh = DBI->connect("dbi:ODBCDSN",'','ytwk')
>> or die "Can't connect to Database: $DBI::errstr";
>>
>> 读取记录:
>>
>> my $sth = $dbh->prepare( q{
>> SELECT * FROM testDB}) or die "Can't prepare statement:
>> $DBI::errstr";
>>
>> my $rc = $sth->execute
>> or die "Can't execute statement: $DBI::errstr";
>>
>> 显示出前三列:
>>
>> print "Query will return $sth->{NUM_OF_FIELDS} fields.\n\n";
>>
>> print "Field names: @{ $sth->{NAME} } \n";
>>
>> my $ary_ref;
>>
>> open (FILE1, ">a.txt";
>>
>> while ( $ary_ref = $sth->fetchrow_arrayref) {
>>
>> print FILE1 ("$ary_ref->[0] : $ary_ref->[1] : $ary_ref->[2] \n";
>> print FILE1 ("$ary_ref->[0] \n";
>>
>> }
>>
>> 当运行的时候报告错误:
>>
>> DBD::ODBC::st fetchrow_arrayref failed: [Microsoft][ODBC Microsoft
>> Access Driver
>> ]字符串数据,右截断 在列号 3 (CopyDetail) (SQL-01004) at D:\jk\test1.pl
>> line 31.
>>
>> [Microsoft][ODBC Microsoft Access Driver]字符串数据,右截断 在列号 3
>> (CopyDetail
>> ) (SQL-01004) at D:\jk\test1.pl line 39.
>>
>> 我检查后发现,是由于第三列内容包含windows路径的"\"导致的,当运行到 while
>> ( $ary_ref = $sth-
>>
>> >fetchrow_arrayref )的时候,就开始报告错误
>>
>> 请问各位,我该怎么做才能使perl正确读取"\"字符呢。
> >
>

--~--~---------~--~----~------------~-------~--~----~
您收到此信息是由于您订阅了 Google 论坛"PerlChina 论坛"论坛。
要在此论坛发帖,请发电子邮件到 perlchina@googlegroups.com
要退订此论坛,请发邮件至 perlchina+unsubscribe@googlegroups.com
更多选项,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问该论坛
-~----------~----~----~----~------~----~------~--~---

没有评论: