我們都知道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(Ac9CRS &"' 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