设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 4119|回复: 0
打印 上一主题 下一主题

[表] 【技巧】解决ACCESS表中含有日文时使用like模糊搜索时出现“内存溢出”

[复制链接]

点击这里给我发消息

跳转到指定楼层
1#
发表于 2015-12-29 22:14:45 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
解决ACCESS表中含有日文时使用like模糊搜索时出现“内存溢出”,大家都知道,ACCESS有个BUG,那就是如果遇到日文或一些乱码文字时在使用 like 进行模糊搜索时就会出现“内存溢出”的问题,提示“80040e14/内存溢出”。


以前也遇到过了,不过那时没怎么在意把含有日文的数据删除了就好了,现在这次的都是些重要的资料不可能删除的,就需要想办法来解决了。
那导致出问题的26个日文:ゴ ガ ギ グ ゲ ザ ジ ズ ヅ デ ド ポ ベ プ ビ パ ヴ ボ ペ ブ ピ バ ヂ ダ ゾ ゼ
说一下解决办法:
1、最笨的方法:删除含有日文的数据
  
这就不用解释了;
2、替换方法:
思路:就是存储进入数据库时把那26个日文替换成别的编码,在从数据库取出来后在反替换回来;
从网上找了个现成的函数:
编码:
Function Jencode(byVal iStr)
if isnull(iStr) or isEmpty(iStr) then
Jencode=""
Exit function
end if
dim F,i,E
' F=array("ゴ","ガ","ギ","グ","ゲ","ザ","ジ","ズ","ヅ","デ",_
' "ド","ポ","ベ","プ","ビ","パ","ヴ","ボ","ペ","ブ","ピ","バ",_
' "ヂ","ダ","ゾ","ゼ")
E=array("Jn0;","Jn1;","Jn2;","Jn3;","Jn4;","Jn5;","Jn6;","Jn7;","Jn8;","Jn9;","Jn10;","Jn11;","Jn12;","Jn13;","Jn14;","Jn15;","Jn16;","Jn17;","Jn18;","Jn19;","Jn20;","Jn21;","Jn22;","Jn23;","Jn24;","Jn25;")
F=array(chr(-23116),chr(-23124),chr(-23122),chr(-23120),_
chr(-23118),chr(-23114),chr(-23112),chr(-23110),_
chr(-23099),chr(-23097),chr(-23095),chr(-23075),_
chr(-23079),chr(-23081),chr(-23085),chr(-23087),_
chr(-23052),chr(-23076),chr(-23078),chr(-23082),_
chr(-23084),chr(-23088),chr(-23102),chr(-23104),_
chr(-23106),chr(-23108))
Jencode=iStr
for i=0 to 25
Jencode=replace(Jencode,F(i),E(i))
next
End Function
解码:
Function Juncode(byVal iStr)
if isnull(iStr) or isEmpty(iStr) then
Juncode=""
Exit function
end if
dim F,i,E
' F=array("ゴ","ガ","ギ","グ","ゲ","ザ","ジ","ズ","ヅ","デ",_
' "ド","ポ","ベ","プ","ビ","パ","ヴ","ボ","ペ","ブ","ピ","バ",_
' "ヂ","ダ","ゾ","ゼ")
E=array("Jn0;","Jn1;","Jn2;","Jn3;","Jn4;","Jn5;","Jn6;","Jn7;","Jn8;","Jn9;","Jn10;","Jn11;","Jn12;","Jn13;","Jn14;","Jn15;","Jn16;","Jn17;","Jn18;","Jn19;","Jn20;","Jn21;","Jn22;","Jn23;","Jn24;","Jn25;")
F=array(chr(-23116),chr(-23124),chr(-23122),chr(-23120),_
chr(-23118),chr(-23114),chr(-23112),chr(-23110),_
chr(-23099),chr(-23097),chr(-23095),chr(-23075),_
chr(-23079),chr(-23081),chr(-23085),chr(-23087),_
chr(-23052),chr(-23076),chr(-23078),chr(-23082),_
chr(-23084),chr(-23088),chr(-23102),chr(-23104),_
chr(-23106),chr(-23108))
Juncode=iStr
for i=0 to 25
Juncode=replace(Juncode,E(i),F(i))'□
next
End Function
3、处理SQL语句:
不要使用like语句,举个例子:
会出问题的SQL:   where title like '%"&keyword&"%'
现在换成下面的就不会出现内存溢出了:where InStr(1,LCase(Title),LCase('"&keyword&"'),0)<>0

摘自网络。


补充:

当access数据库的字段内包含了26个日文片假名字符任意一个时,就会导致在执行SQL语句中包含了[字段] like '%aaaaa%' 或 inStr(1,[字段],'aaaaa',1)类似查询时,出现了"Microsoft JET Database Engine 错误 ‘80040e14'内存溢出"的错误。

这个问题在ASP中有一个折中的解决办法就是将日文代码转换成对应的代码,比如:

  •         source=Replace(source,"ガ","ガ")


我们都知道ACCESS是ASP的亲密伙伴。因为两种最简单的东西碰在一起总能迸发出火花。然而,当我们过滤不严格的时候经常出现日文字符,这个时候搜索之后就会出现日文溢出。此时我们通常能想到的想法是找一个exe程序,把这个问题解决掉。我原来用C#写过这样一个类似的程序。Google里面应该能找到我以前写的那个。就不说了。后来某一天,我发现ASP就能实现。我当时真的觉得自己太屎了。不过ASP的这种方法很不好。容易造成系统崩溃(如果数据库大)。所以只是写在这里。算是抛砖引玉。'下面我解释一下下:Function TransferJapanDc9CnInDB() On Error Resume Next Err.Clear Dim objRS,i Set objRS=Server.CreateObject("ADODB.Recordset") objRS.CursorType = adOpenKeyset objRS.LockType = adLockReadOnly objRS.ActiveConnection=objConn objRS.Source="SELECT * FROM [blog_Comment]" objRS.Open() If (Not objRS.bof) And (Not objRS.eof) Then For i=1 to objRS.RecordCount'遍历,看看有没有日文,如果有,就溢出了,随便搜索一个东西就行了。搜什么无所谓。因为是遍历ACCESS只要指针移动到日文就溢出。 objConn.Execute("SELECT * FROM [blog_Comment] WHERE comm_ID="&objRS("comm_ID")&" AND [comm_Content] LIKE '%URL%'") If Err.Number=-2147217900 Then'因为是on err继续 所以这里找到溢出的错误代码,这个是自己debug出来的,实际上不是从什么地方找的。 objConn.Execute("UPDATE [blog_Comment] SET [comm_Content]='"&FilterSQL(Japan2Html(objRS("comm_Content")))&"',[comm_Author]='"&FilterSQL(Japan2Dc9CnHtml(objRS("comm_Author")))&"' WHERE comm_ID="&objRS("comm_ID")&" ")'这个就是把日文替换一下,思路是不是很巧妙。恩。不过数据库庞大的化,反复溢出就会很出问题的。内存宝宝会哭的。 Err.Clear End If objRS.MoveNext Next End If objRS.Close Set objRS=Nothing'   End FunctionFunction Japan2Dc9CnHtml(source) source=Replace(source,"ガ","ガ") source=Replace(source,"ギ","ギ") source=Replace(source,"ア","ア") source=Replace(source,"ゲ","ゲ") source=Replace(source,"ゴ","ゴ") source=Replace(source,"ザ","ザ") source=Replace(source,"ジ","ジ") source=Replace(source,"ズ","ズ") source=Replace(source,"ゼ","ゼ") source=Replace(source,"ゾ","ゾ") source=Replace(source,"ダ","ダ") source=Replace(source,"ヂ","ヂ") source=Replace(source,"ヅ","ヅ") source=Replace(source,"デ","デ") source=Replace(source,"ド","ド") source=Replace(source,"バ","バ") source=Replace(source,"パ","パ") source=Replace(source,"ビ","ビ") source=Replace(source,"ピ","ピ") source=Replace(source,"ブ","ブ") source=Replace(source,"ブ","ブ") source=Replace(source,"プ","プ") source=Replace(source,"ベ","ベ") source=Replace(source,"ペ","ペ") source=Replace(source,"ボ","ボ") source=Replace(source,"ポ","ポ") source=Replace(source,"ヴ","ヴ") Japan2Html=sourceEnd Function





分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-11-25 07:24 , Processed in 0.099128 second(s), 29 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表