| 導購 | 订阅 | 在线投稿
分享
 
 
 

自動清除替換ACCESS(MDB)數據庫的日文字符的ASP代碼

來源:互聯網  2008-06-01 03:16:19  評論

我們都知道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

'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

我們都知道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 '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
󰈣󰈤
王朝萬家燈火計劃
期待原創作者加盟
 
 
 
>>返回首頁<<
 
 
 
 
 熱帖排行
 
 
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有