3

I try to sync a MySQL DB with my documents in Google Drive. I wrote a small script on Google App Script to do this job.

I encounter some problem when dealing with character encoding (the default charset is UTF-8 with collate "general_ci"). I tried different ways (encodeURIComponent, small UTF-8 tool class, Blob, ...) but nothing works. Here is small sample code :

var title = result.getString("title");
title = Utilities.newBlob(title, Utilities.Charset.UTF_8);
if(title.getDataAsString() != file.getName()) {
          Logger.log('Updating title for document %s from %s to %s', file.getId(), title.getDataAsString(),          file.getName());
          stmt_update_title.setObject(2, file.getId());
          stmt_update_title.setObject(1, Utilities.newBlob(file.getName(), Utilities.Charset.UTF_8).getDataAsString());
          stmt_update_title.addBatch();
        }

When I retrieve from MySQL, I get an incorrect string with "?" instead of accented characters ('é', 'è', 'à'). When I update, the string is corrupted (but it prints well in the logs).

Thanks by advance for your help.

arnaud.breton
  • 2,054
  • 1
  • 24
  • 39
  • Suggestion: maybe this post could help: http://stackoverflow.com/questions/11332816/google-apps-script-utf8/11338569#11338569 – Serge insas Dec 17 '12 at 16:17
  • 1
    Hi Serge, Thanks for the answer. I already found this question and as you can see in the sample code I tried to use this solution. – arnaud.breton Dec 18 '12 at 08:27

1 Answers1

4

You need use the special connection string for the JDBC object like

jdbc:mysql://host:port/instance?useUnicode=true&characterEncoding=UTF-8
contributorpw
  • 4,739
  • 5
  • 27
  • 50
  • Thanks for this - I can pass along all English text using this, but I get an error (Incorrect string value: '\xD7\x94\xD7\x99! ...' for column 'Text' at row 1 (line 29, file "registration_text")) when trying to pass Hebrew text. Your help is greatly appreciated, thanks :) – Anna Dunietz Sep 05 '17 at 12:18
  • @AnnaDunietz, sorry I don't have an idea. Tweet me (at)oshliaer May be I can help. – contributorpw Sep 05 '17 at 16:39