首页 > 学院 > 开发设计 > 正文

自动清除替换ACCESS(MDB)数据库的日文字符的ASP代码

2019-11-17 04:33:43
字体:
来源:转载
供稿:网友

我们都知道accessasp的亲密伙伴。因为两种最简单的东西碰在一起总能迸发出火花。
然而,当我们过滤不严格的时候经常出现日文字符,这个时候搜索之后就会出现日文溢出。
此时我们通常能想到的想法是找一个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
'www.dc9.cn http://www.devdao.com/ 07/11/28
End Function

Function 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=source
End Function


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表