Mysql Data Returned Encoding Types

This seems so simple, and I am coding around it, and I’m afraid you guys are going to tell me “Welcome To Xojo!”, BUT… Why is the encoding coming back weird from mysql databases?

I have a simple users_auth table

create table xojo_test.users_auth
(
    id bigint unsigned auto_increment primary key,
    username   varchar(50)                  not null,
    password   varchar(200)                 not null,
    status     tinyint unsigned default (1) not null,
    api_token  varchar(200)                 not null,
    created_at datetime                     null,
    updated_at datetime                     null
)
    collate = utf8mb4_unicode_ci;

Then when I run the select statement like

SELECT * FROM users_auth WHERE username = ‘test’ AND password = ‘myapp!’;

I get the correct row back, then i put certain fields into a dictionary and return it so I can have a different method convert it to a JSON string…

When it writes the values to the dictionary using RowSet.Column(“id”).StringValue for example, its returned with an encoding of “US-ASCII” but the RowSet.Column(“api_token”).StringValue is returned with an encoding of “Nil”

So I have had to go and build a function to convert strings that are returned to utf8 using

DefineEncodings(Encodings.UTF8)

This is now working, but I was wondering if this is common, or if I am just missing something here… Right now I feel like Xojo being advertised for quick coding is actually not very quick in my cases, but im sure i’m just hitting a lot of road blocks… I’m getting around these road blocks, but still.

Early tonight, I had to build a function for converting the WebRequest.Body parameters from a web form into a dictionary so i could query variables easily because WebRequest.Parameter was causing the parameters to come up blank. So when the form submits the username and password for instance, It shows up in the body like

username=test&password=myapp%21&submit=Submit

and then i take it from there and parse the entire thing into a dictionary, taking into account the url encoding as well. I had to go around the world in order to do that when I feel like WebRequest.Parameter(“username”) should have returned it. Parameter does work if the variables are sent as part of the url called (like a GET method instead of a POST method). Then Parameter picks those up. So what am I missing here?

Can anyone speak to any of these? I feel like I could just be missing something. This Web App i’m designing here is just an API in order to return data to other apps (IE: iOS App, Android App, Desktop App, Etc…) …

mysql a some weird encodings parameter
I found that using

ConvertEncoding( DefineEncoding( aValue, Encodings.WindowsANSI), Encodings.UTF8)

you can get your mysql values as utf8 and get your accentuated characters back.

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.