`
buliedian
  • 浏览: 1193445 次
  • 性别: Icon_minigender_2
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

BULK INSERT时发生错误 异常的EOF,原因是有空行!

J# 
阅读更多

BULK INSERT时发生错误 异常的EOF,原因是有空行!

或者文本结束时没0x0D0A。

//特别写一个过程来进行处理,找出这些问题。

long ll_rows,i,ll_read_len,ll_linecount,j
string ls_path

long ll_filehandle
blob{10485760} bl
byte bt[10485760]

ll_rows = dw_2.rowcount()

if ll_rows <1 then return
for i = 1 to ll_rows
yield()

if ib_stop then return

dw_2.selectrow(0,false)
dw_2.selectrow(i,true)

ls_path = dw_2.getitemstring(i,6) //filepath
ll_filehandle = FileOpen(ls_path, &
StreamMode!, read!,shared!, append!)

if ll_filehandle < 1 then continue

//先判断文件尾是否是0x0D0A
FileSeek64 (ll_filehandle,-2,FromEnd!)

filereadex(ll_filehandle,bl,2)

if byte(blobmid(bl,1,1)) <> 13 or byte(blobmid(bl,2,1)) <> 10 then
dw_2.setitem(i,2,dw_2.getitemstring(i,2) + "---结尾不为\r\n")
//messagebox("异常","文件:~n" + ls_path + "~n结尾不为\r\n")
fileclose(ll_filehandle)
continue
end if

//判断文件中间是否存在连续的0D0A0D0A这样的空行(跳行),其实严格地说,还有其他不可打印字符(控制字符是否跳行没测试)也可能引起。我遇到的问题就是别人导给我的数据,有一列的汉字被切掉了一半!搞死人了。我叫他先把那一栏加个因为字符,再切掉一个字符(等于切掉半个汉字了),他有不肯定搞,还是他根本不晓得导出的结果会那样。再说几百兆的文件他也不可能逐行去看。所以其他跳行原因请具体分析。


FileSeek64 (ll_filehandle,1,FromBeginning!)


DO while(true)
ll_read_len = filereadex(ll_filehandle,bl,10485760)
bt = GetByteArray(bl)//这里很关键,用blobmid去逐个取字符很慢。
if ll_read_len <4 then exit

ll_read_len -=3

for j = 1 to ll_read_len
yield()

if ib_stop then
fileclose(ll_filehandle)
return
end if

if mod(j,100000) = 0 then
st_odoa.text = "0x0D0A:" + string(ll_linecount)
st_ij.text = "J: " + string(j)
end if

if bt[j]<>13 then continue

if bt[j + 1] = 10 then
ll_linecount ++
else
continue
end if

if bt[j + 2] = 13 and bt[j + 3] = 10 then
dw_2.setitem(i,2,dw_2.getitemstring(i,2) + "---存在空行,在" + string(ll_linecount) + "行处!")
//messagebox("异常","文件:~n" + ls_path +&
//"~n在中间存在空行~n位置: 第:" + string(ll_rowcount) +&
//"行处!",question!,yesno!)
exit
end if
next

FileSeek64 (ll_filehandle,-3,FromCurrent!) //回退
loop

fileclose(ll_filehandle)
next
messagebox("提示","文件检查结束")

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics