flat assembler
Message board for the users of flat assembler.

Index > Windows > mysql + UNICODE

Author
Thread Post new topic Reply to topic
mikado3333



Joined: 31 Oct 2015
Posts: 7
Location: Russian Federation
mikado3333 04 May 2023, 14:59
Hello. Tell me which encoding to choose in "mysql_set_character_set" to receive a response UNICODE fasm strings?

Code:
format PE64 console
stack 1048576,1048576
entry start
include 'win64wx.inc'
include 'encoding\UTF8.INC' 

.....

proc mysqlTest

locals
aResult         dq ?
hMysql  dq ?
nColumns        dq ?
endl
        
        invoke mysql_server_init, 0, 0, 0
        cmp rax, 0
        jnz .error_server
        
        invoke  mysql_init, 0
        cmp rax, 0
        jz .errorInit
        mov [hMysql], rax
        
                
        ; invoke mysql_options, [hMysql], 7, .szUTF8 
        ; cmp rax, 0
        ; jnz .error
        

        
        invoke  mysql_real_connect, [hMysql], .szHost, .szUser, .szPass, .szBase, 0,0,0
        cmp rax, [hMysql]
        jnz .error
                

        invoke  mysql_set_character_set, [hMysql], .szUTF8
        cmp rax, 0
        jnz .error
        
        ; invoke        mysql_query, [hMysql], .szEncoding
        ; cmp   rax, 0
        ; jnz           .error
        
        invoke mysql_query, [hMysql], .szQuery
        cmp rax, 0
        jnz .error

        invoke mysql_store_result, [hMysql]
        cmp rax, 0
        jz .error
        mov [aResult], rax

        ; invoke    mysql_num_fields, [aResult]
        ; mov       [nColumns], rax

@@:     invoke mysql_fetch_row, [aResult]
        cmp rax, 0
        jz @f

        stdcall write, rax, -1, -1
        stdcall write, .sz10, -1, -1
        jmp @b
        
@@:     invoke  mysql_free_result, [aResult]

        invoke  mysql_thread_end 
        invoke  mysql_close, [hMysql]
        invoke  mysql_server_end
        
        ret

.error: 
        invoke       mysql_error, [hMysql]
        invoke  MultiByteToWideChar, CP_ACP, 0, rax, -1, aBuffer, 1024  
        stdcall write, aBuffer, -1, -1
        stdcall write, .sz10 , -1, -1
        ret
        
.errorInit:
        stdcall write, .szTxt1, -1, -1
        ret
                
.error_server:
        stdcall write, .szTxt0, -1, -1
        ret
        
        align 2
        
        .szTxt0  du 'Mysql error:  ,mysql_server_init ', 10, 0
        .szTxt1  du 'Mysql error:  ,mysql_init ', 10, 0
        
        .sz10    du 10, 0
        .szUser  db 'root', 0
        .szBase  db 'Test', 0
        .szHost  db 'localhost', 0
        .szPass  db '1', 0
        .szQuery db 'SHOW DATABASES', 0
        .szUTF8  db 'utf8', 0
        .szEncoding     db "SET NAMES 'utf8'",0         
        
        
endp

    
Post 04 May 2023, 14:59
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3892
Location: vpcmipstrm
bitRAKE 04 May 2023, 16:38
MySQL does not natively support UTF-16, Microsoft widechar (wchar_t) strings.

Looks like you are configuring for UTF-8 and converting to<->from UTF-16?

I think you should be using CP_UTF8 and not CP_ACP.

If you need CP_ACP then you'd need MultiByteToWideChar CP_UTF8, ... and then WideCharToMultiByte CP_ACP, ... As there is not a UTF-8 -> Windows ANSI Code Page function. [This is not a good idea - functionality is just being removed. It's better to use UTF-8/16 to the extent possible and only reduce to other codepages at the interface edge where needed.]
Post 04 May 2023, 16:38
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.