SQLite/AutoHotkey, I have problem with Encoding of sqlite3_result_text return function

不羁的心 提交于 2019-12-24 06:37:17

问题


I am writing a User Define Function with SQLite in AutoHotkey.

It works well as I intended when I use (return) English only.

But, If I use (return) any character with NonEnglish, it makes broken result. The broken result has, for me, some rules - its length is exctly realted with NonEnglish character.

Does any body heard about it ?

I guess it is problem with "sqlite3_result_text" function of SQLite. If so, I'd like to use it properly.

Thanks

[EDIT]

I have tested with "sqlite3_result_text64" too.
And, confirmed the same problem. I do not know what seems to be the root cause of this difficulty. Very hard one.

Following is something in real situation screenshot (a little bit different from sample code, sample code is pretty simplified one for this question post). The first line is working well (English only). The second line is the same content but translated in CJK, so broken perfectly. The first 3 and the last 3 characters of each lines are just to make sure it is treated correctly, as you can see it treated well - treated well as English.

the first image Here

Global myReturn
myReturn := "HK"        ;  "HK" works well. But, "香港" emits problem.
myReturn := "香港"    
FileEncoding, UTF-8
Global pathSQLiteDll := A_ScriptDir "\SQLite3.dll"
myNewFile := "_tempFile.db"
FileDelete, % myNewFile
DllCall("LoadLibrary", "Str", pathSQLiteDll, "UPtr")
DllCall("SQLite3\sqlite3_open", "Ptr", myUnicode(myNewFile), "PtrP", myDbH, "Cdecl Int")
DllCall("SQLite3\sqlite3_create_function_v2", "Ptr", myDbH, "AStr", "UDF", "Int", -1, "Int", 1, "Ptr",, "Ptr", RegisterCallback("myCallBack"), "Ptr", 0, "Ptr", 0)
myQuery .= "CREATE TABLE myT(myC1 TEXT, myC2 TEXT);"                    
myQuery .= "INSERT INTO myT(myC1, myC2) VALUES('China', '中国');"
myQuery .= "INSERT INTO myT(myC1, myC2) VALUES('HongKong', UDF());"
DllCall("SQLite3\sqlite3_exec", "Ptr", myDbH, "Ptr", myUnicode(myQuery), "Int",, "Ptr",, "PtrP",, "Cdecl Int")
MsgBox % myShowResults(myDbH)
DllCall("SQLite3\sqlite3_close", "Ptr", myDbH, "Cdecl Int")         
Return

myCallBack(myDbH)                                                   
{ 
    DllCall("SQLite3\sqlite3_result_text", "Ptr", myDbH, "AStr", myReturn, "Int", -1) 
}
myShowResults(myDbH) 
{
    DllCall("SQLite3\sqlite3_get_table", "Ptr", myDbH, "Ptr", myUnicode("SELECT * FROM myT"), "PtrP", TbAddress, "IntP", myRows, "IntP", myColumns, "PtrP",, "Cdecl Int")   
    myTable := []
    Loop, % myColumns
    myOffset += A_PtrSize
    Loop, % myRows
    {
        i := A_Index, myTable.Rows[i] := []
        Loop, % myColumns
            myTable.Rows[i][A_Index] := StrGet(NumGet(TbAddress+0, myOffset, "UPtr"), "UTF-8"), myOffset += A_PtrSize
    }
    If(myRows = 0)
        Return
    For Each, x In myTable.Rows
        myResult .= x[1] "   " x[2] "`n"
    Return myResult
}
myUnicode(myInput) 
{
    VarSetCapacity(myUnicodeOutput, StrPut(myInput, "UTF-8"), 0)
    StrPut(myInput, &myUnicodeOutput, "UTF-8")
    Return &myUnicodeOutput
}

And, finally, I have confirmed that in case "Only English" has problem too. It has not English, right. But, it is clearly "Unicode".. I got broken result. This is amazing..

the 2nd image Here

来源:https://stackoverflow.com/questions/59422168/sqlite-autohotkey-i-have-problem-with-encoding-of-sqlite3-result-text-return-fu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!