1

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 := "香港"    
DllCall("LoadLibrary", "Str", A_ScriptDir "\SQLite3.dll", "UPtr")
DllCall("SQLite3\sqlite3_open", "Ptr", myUnicode(":memory:"), "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)   
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) 
{
    Global
    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

Kita Nagoya
  • 100
  • 6
  • Did you [save your AHK script as UTF-8 with BOM](https://www.autohotkey.com/docs/FAQ.htm#nonascii)? – user3419297 Dec 20 '19 at 09:01
  • @user3419297 I do not know. But, when you see the first record of my code, it is written Chinese and it works well.(Sorry I just edited my main post) – Kita Nagoya Dec 20 '19 at 10:09
  • If you have Notepad++ or another advanced editor you can see the format your script is encoding. Maybe changing that format solves the problem. – user3419297 Dec 20 '19 at 10:44
  • @user3419297 Ah..Just changed it into as you mentioned "UTF-8 BOM(I am with Notepad++)". But, no changes. Still blind to Chinese "香港". But, "中国" works well. So, It is not the problem of AHK script itself encoding for sure. Thanks Comment Again. – Kita Nagoya Dec 20 '19 at 10:48
  • @user3419297 How's your side, Is this code "香港" works well ? or not ? I am just wondering. – Kita Nagoya Dec 20 '19 at 10:53
  • 1
    Unfortunatelly I have no experience in this area. I don't even understand how and for what purpose your script is intended to work. All I see if I test your code is an empty message box. So I can't say what is wrong with it. – user3419297 Dec 20 '19 at 11:17
  • @user3419297 No problem. I just wait for the better experienced person. Thanks – Kita Nagoya Dec 20 '19 at 12:00

0 Answers0