找回密码
 加入
搜索
楼主: mikezunya

[系统综合] 请教一个数据编码转换问题[已解决]

  [复制链接]
发表于 2016-6-23 21:52:45 | 显示全部楼层
回复 16# mikezunya

我沒用過 SQLLITE  只是看到 說明內定是 UTF-8 那就表示 內定是採UNZICODE 方式
如果無法改ANSI  

那我就更肯定 存在資料庫上的東西與 UNCODE 或者 ANSI 無關才對.......

話說回來  方便提供 資料庫與 你的程式與法 我測試看看嗎??
 楼主| 发表于 2016-6-23 22:39:11 | 显示全部楼层
本帖最后由 mikezunya 于 2016-6-24 13:36 编辑

回复 17# kk_lee69



这是数据库与源码,解压密码我私聊发给你了

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2016-6-24 01:39:40 | 显示全部楼层
本帖最后由 kk_lee69 于 2016-6-24 09:53 编辑

回复 18# mikezunya

問題解決了  幫你測試出來了

注意聽好了 要改寫  SQLITE 的UDF

因為  原本的 _SQLite_Exec 會將你輸入的SQL語法轉成 UTF-8  因此 不能用這個
需要自己建立一個 _SQLite_Exec2  然後將裡面 轉換成 UTF-8 的語法 改成 另外一個函數

建立一個 __SQLite_StringToUtf8Struct2  由 _SQLite_Exec2   呼叫這個

然後再將   __SQLite_StringToUtf8Struct2   裡面的 65001 改成 936

然後就可以成功了~~~ 細節我沒測試     你在 自行修改與測試  方向應該沒錯

附上幾段我改的地方

                _SQLite_Exec2($barserverdb, "INSERT INTO tbl_ProcessDenySecurity (Name,Desc,MD5,Size,Type) VALUES ('" & $linshi2[1] & "','" & $linshi2[2] & "','" & $linshi2[3] & "','2048','16');")
                                        GUICtrlCreateListViewItem($linshi2[1] & "|" & $linshi2[2] & "|" & $linshi2[3], $ListView1)
                                        If @error Then
                                                MsgBox(48, "", "數據庫寫入失敗,原因" & @error)
                                                Exit
                                        EndIf


Func _SQLite_Exec2($hDB, $sSQL, $sCallBack = "")
        If __SQLite_hChk($hDB, 2) Then Return SetError(@error, 0, $SQLITE_MISUSE)
        If $sCallBack <> "" Then
                Local $iRows, $iColumns
                Local $aResult = "SQLITE_CALLBACK:" & $sCallBack
                Local $iRval = _SQLite_GetTable2d($hDB, $sSQL, $aResult, $iRows, $iColumns)
                If @error Then Return SetError(3, @error, $iRval)
                Return $iRval
        EndIf
        Local $tSQL8 = __SQLite_StringToUtf8Struct2($sSQL)
    If @error Then Return SetError(4, @error, 0)
        Local $avRval = DllCall($g_hDll_SQLite, "int:cdecl", "sqlite3_exec", _
                        "ptr", $hDB, _ ; An open database
                        "ptr", DllStructGetPtr($tSQL8), _ ; SQL to be executed
                        "ptr", 0, _ ; Callback function
                        "ptr", 0, _ ; 1st argument to callback function
                        "long*", 0) ; Error msg written here
        If @error Then Return SetError(1, @error, $SQLITE_MISUSE) ; Dllcall error
        __SQLite_szFree($avRval[5])        ; free error message
        If $avRval[0] <> $SQLITE_OK Then
                __SQLite_ReportError($hDB, "_SQLite_Exec", $sSQL)
                SetError(-1)
        EndIf
        Return $avRval[0]
EndFunc   ;==>_SQLite_Exec


; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name...........: __SQLite_StringToUtf8Struct
; Description ...: UTF-16 to UTF-8 (as struct) conversion
; Syntax.........: __SQLite_StringToUtf8Struct($sString)
; Parameters ....: $sString     - String to be converted
; Return values .: Success      - Utf8 structure
;                  Failure      - Set @error
; Author ........: jchd
; Modified.......: jpm
; ===============================================================================================================================
Func __SQLite_StringToUtf8Struct2($sString)
        Local $aResult = DllCall("kernel32.dll", "int", "WideCharToMultiByte", "uint", 54936, "dword", 0, "wstr", $sString, "int", -1, _
                                                                "ptr", 0, "int", 0, "ptr", 0, "ptr", 0)
        If @error Then Return SetError(1, @error, "") ; Dllcall error
        Local $tText = DllStructCreate("char[" & $aResult[0] & "]")
        $aResult = DllCall("Kernel32.dll", "int", "WideCharToMultiByte", "uint", 54936, "dword", 0, "wstr", $sString, "int", -1, _
                                                        "ptr", DllStructGetPtr($tText), "int", $aResult[0], "ptr", 0, "ptr", 0)
        If @error Then Return SetError(2, @error, "") ; Dllcall error
        Return $tText
EndFunc   ;==>__SQLite_StringToUtf8Struct


附上 我編譯的程式  你可以測試看看  寫入後 會有錯誤訊息  我沒時間找問題在哪
因為 我的是繁體  測試 還得找 簡體系統 很麻煩
但是  字的編碼問題應該解決了  細節 可能您要研究看看

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×

评分

参与人数 2金钱 +20 收起 理由
nmgwddj + 10
heroxianf + 10 哇 KK原来懂数据库啊,多指教一下。

查看全部评分

发表于 2016-6-24 01:58:01 | 显示全部楼层
回复 18# mikezunya

剛剛再仔細的分析一下   資料其實不太一樣  但是我覺得應該是 用936 的號碼不對

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2016-6-24 02:00:21 | 显示全部楼层
回复 18# mikezunya


   參考一下這個網頁

https://msdn.microsoft.com/zh-tw/library/windows/desktop/dd317756(v=vs.85).aspx
发表于 2016-6-24 02:33:18 | 显示全部楼层
回复 19# kk_lee69

找到正確編碼了 54936

GB18030 Windows XP and later: GB18030 Simplified Chinese (4 byte); Chinese Simplified (GB18030)

评分

参与人数 1金钱 +40 收起 理由
mikezunya + 40 不管怎么说,为你的精神点赞~非常感谢!

查看全部评分

发表于 2016-6-24 12:02:42 | 显示全部楼层
回复 19# kk_lee69


  無法解決你的問題嗎  我認為應該是可以解決才是??
 楼主| 发表于 2016-6-24 13:26:19 | 显示全部楼层
本帖最后由 mikezunya 于 2016-6-24 13:29 编辑

回复 23# kk_lee69


    可以解决,非常感谢。但是程序会有报错,我想应该问题不大,我正在看你写的那个代码的意思。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-6 03:23 , Processed in 0.076970 second(s), 15 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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