Fix SQL when ANSI_QUOTES is enabled in mysql config.

http://dev.mysql.com/doc/refman/5.1/en/server-sql-mode.html#sqlmode_ansi_quotes

When ANSI_QUOTES is enabled Mysql treats double quotes the same as backtick quotes, ie as an identifier.

This patch changes quotes round anything that is not an identifier and makes the SQL work with ANSI_QUOTES on & off.