gpt4 book ai didi

perl - 数据库 fetchrow_array 失败长截断 DBI 属性

转载 作者:行者123 更新时间:2023-12-02 03:17:03 26 4
gpt4 key购买 nike

我正在使用 Perl 脚本从数据库中提取 URL,其中使用 fetchrow_array 从数据库中提取 URL,该脚本工作正常,直到我遇到一个很长的 URL georgelog24.blog.iskreni。 net/?bid=6744d9dcf85991ed2e4b8a258153a1ab&lid=ff9963b9a798ea335b75b5f7c0c295d1
然后它开始给我这个错误。

DBD::ODBC::st fetchrow_array failed: st_fetch/SQLFetch (long truncated DBI attribute LongTruncOk not set and/or LongReadLen too small) (SQL-HY000) [state was HY000 now 01004]
[Microsoft][ODBC SQL Server Driver]String data, right truncation (SQL-01004) at C:\test\multihashtest2.pl line 44.

我相信这是在数据库方面,因为我用来提取 URL 的代码之前已经工作过。我使用的数据库是MSSQL server 2005。

数据库中的URL列当前使用text类型,但我尝试将其更改为varchar(max)nvarchar(max) 但错误仍然存​​在。

经过一番尝试和错误后,我发现使用 fetchrow_array 成功查询的 url 最大长度为 81 个字符。由于 URL 有时可能会超出荒谬的长度,因此我无法对 URL 长度进行限制。

有人可以帮助我理解并建议解决这个问题吗?

仅供引用:第 44 行是下面代码中的第一行

while (($myid,$url) = $statement_handle->fetchrow_array()) { # executes as many threads as there are jobs to do 
my $thread = threads->create(\&webcrawl); #initiate thread
my $tid = $thread->tid;
print " - Thread $tid started\n"; #obtain thread no. and print
push (@Threads, $thread); #push thread into array for "housekeeping" later on
}

最佳答案

尝试:

#not anymore errors if content is truncated - you don't necessarily want this
$statement_handle->{'LongTruncOk'} = 1;

#nice, hard coded constant for the length of data to be read from Longs
$statement_handle->{'LongReadLen'} = 20000;
while (($myid,$url) = $statement_handle->fetchrow_array()) { # executes as many threads as there are jobs to do
my $thread = threads->create(\&webcrawl); #initiate thread
my $tid = $thread->tid;
print " - Thread $tid started\n"; #obtain thread no. and print
push (@Threads, $thread); #push thread into array for "housekeeping" later on
}

另外,我建议您尝试Parallel::ForkManager用于并行化作业 - 我发现它比线程更直观且易于使用

关于perl - 数据库 fetchrow_array 失败长截断 DBI 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12315397/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com