i am saving a string, that, you guessed it, looks like a time to my mysql database in a “varchar(45)” type field
when it saves it looks like this:
2:40 PM
when i pull it back up, it looks the same. Is that some kind of DB column break or something?
My guess is that your database is not handling the string encoding correctly.
I remember reading that there are some changes on time formats and instead of using a regular space between the time and AM/PM now sometimes a non-breaking space is used, so the UTF8 value is multi-character.
Will you ever need to do calculations on such value? Select with an order on said time value?
Would be better to save time as digits such as “14:40:00”
You can then easily read it into a Datetime object or split into integers for hour, minute, seconds.
It is never a good idea to store a localized version of a value.
2:40 PM is a localized time value.
i literally want a “timestamp” of the time of day a test is run on a patient. it will only be stored and really probably never changed/updated or searched. it can be stored as a text string, in fact thats what i am trying to do.
Do you need to have PM/AM on it or is 14:23:56 something you can use?
Do you want to solve the encoding for your database (to avoid future problems) or just want to use ‘regular’ (single byte characters) strings?
It seems like the timestamp function is quirky- maybe sets itself or resets itself automatically (when you don’t ask it to.)
I did play with that a little. I’d like the am/pm to be displayed (currently making a work around… aka reinventing the wheel)
I know some my questions are so beginner level- am sorry for that …. Ugh
Do you need to manually enter the timestamp for a test or is it acceptable to use now() as timestamp?
In any case I would store this information as timestamp or separate date/ time columns as it makes formatting during query a breeze…and also sorting based on timestamp.
As said, it needs to be called after every connection, to ensure that all parts, client (Xojo) and Server (MySQL) are “talking” the same specs.
Your sample was like Xojo sent UTF-8, MySQL stored “whatever”, and sent back Latin1 or something. It wasn’t UTF-8 source, UTF-8 sent, UTF-8 stored, UTF-8 retrieved back.
" set names utf8mb4 collate utf8mb4_general_ci;" says to MySQL that the client is talking UTF-8 and the server should too, as a short form to:
SET character_set_client = utf8mb4 ;
SET character_set_results = utf8mb4 ;
SET character_set_connection = utf8mb4 ;
SET collation_connection = utf8mb4_general_ci;