1

My VBA code snippet is:

        Set rsRecords = CreateObject("ADODB.Recordset")
        strQuery = Printf("INSERT INTO `parameters` (`name`) VALUES ('%s');", Cells(Row, 1).Text)
        MsgBox (strQuery)
        rsRecords.Open strQuery, oConn

The MsgBox properly displays the symbol (°) but MySQL Workbench shows me a (?) has been inserted instead. I can use Workbench to replace the ? with °, so I know it's not an issue with the DB table.

It appears the issue is in ADODB. Any ideas on how to fix?

Dan

Danny Holstein
  • 144
  • 1
  • 14
  • 2
    Welcome to world of SQL Injection. What if user writes `x');DROP DATABASE db_name;--`? – Lukasz Szozda Oct 04 '17 at 16:36
  • Did you see the post re Unicode / ANSI - " use MySQL ODBC UNICODE Driver instead of ANSI" https://stackoverflow.com/questions/25777214/vba-adodb-query-mysql-returns-character-corruption – Wayne G. Dunn Oct 04 '17 at 16:38
  • What type is the `name` column? Is it a unicode type or a `varchar`? Also, use parameterized queries. – Mathieu Guindon Oct 04 '17 at 16:41
  • Very very curious about that `Printf` function. If it's anything like [this](https://stackoverflow.com/a/14534361/1188513) then it's a very cool thing to have, but not for anything that involves SQL strings. – Mathieu Guindon Oct 04 '17 at 16:42
  • The `name` column is VarChar and I was always able to store ° in it, I switched it to NVarChar and nothing changed. I am able to store ° in it from Workbench The print function yields a string that includes °, I checked it with MsgBox. – Danny Holstein Oct 04 '17 at 19:00
  • @WayneG.Dunn You nailed it, thanks! – Danny Holstein Oct 04 '17 at 19:11
  • See "question mark" in https://stackoverflow.com/questions/38363566/trouble-with-utf-8-characters-what-i-see-is-not-what-i-stored – Rick James Oct 05 '17 at 22:35

0 Answers0