Encoding and MySQL - getting crazy

Hi everyone,

im really getting in trouble with mysql and encodings for more than a month meanwhile. So I really hope, anyone can help.

My problem: I have to read a csv file into a listbox. Next step is to define separators and columns. One click to the “header line” of the csv is used to generate columnnames, which I use for defining the headings of the listbox. Nothong complicated up to this moment…

My last step is creating a MySQL file using sql.execute like

[code] sqlstring = sqlstring + " CREATE table IF NOT EXISTS “+”x"+ WinCustomer.TFid.Text+"_"+TFfileName.Text+" “+”(" _
+"id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, "

// Columns from headings
for i = 0 To lbi.ListCount-1
if lbi.CellState(i,1) = Checkbox.CheckedStates.Checked Then
sqlstring = sqlstring+""+ lbi.Cell(i, 0)+" VARCHAR(100), "
end if
next

sqlstring = sqlstring + "Output VARCHAR (400))"[/code]

In debugger a string (UTF-8) with someting something like

CREATE table IF NOT EXISTS x44_test (id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, ?MEDIENID VARCHAR(100), BEZ_KURZ VARCHAR(100), BEZ_LANG VARCHAR(100), MKURZ VARCHAR(100), Output VARCHAR (400))

has been created. In my next line of code I use it with db.sqlexecute(sqlstring) to create the table.

Now the strange part making me crazy: when I copy that string into mysql workbench for creating the table “by hand” everything works fine

When I´m letting xojo doing this for me wit “db.sqlexecute(mysqlstring” my columnnames are getting special characters like that table description below

id int(11) PK AI
MEDIENID varchar(100)
BEZ_LANG varchar(100)
ART varchar(100)
MKURZ varchar(100)
Output varchar(400)

What difference makes copy and paste or directly from xojo? Why is there that f…  in my column name?

I really need help - my next escalation level will be slitting my wrists (just kidding - hopefully)

Thanks in advance

Christian

First make sure that you read in the CSV file with the correct encoding (and convert the incoming strings to utf8 if necessary).
Then in addition directly after connecting to the MySQL server, send “SET NAMES utf8;” with SQLExecute.

THAT´s what it was - and so simple. Thanx Eli!