Extracted from Pike v7.8 release 866 at 2016-11-06.
pike.ida.liu.se
[Top]
Sql
Sql.mysql

Method Sql.mysql()->set_charset()


Method set_charset

void set_charset(string charset)

Description

Changes the connection charset. Works similar to sending the query SET NAMES charset  but also records the charset on the client side so that various client functions work correctly.

charset is a MySQL charset name or the special value "unicode" (see below). You can use SHOW CHARACTER  SET to get a list of valid charsets.

Specifying "unicode" as charset is the same as "utf8" except that unicode encode and decode modes are enabled too. Briefly, this means that you can send queries as unencoded unicode strings and will get back non-binary text results as unencoded unicode strings. See set_unicode_encode_mode and set_unicode_decode_mode for further details.

Throws

Throws an exception if the server doesn't support this, i.e. if the statement SET NAMES fails. Support for it was added in MySQL 4.1.0.

Note

If charset is "latin1" and unicode encode mode is enabled (the default) then big_query can send wide unicode queries transparently if the server supports UTF-8. See set_unicode_encode_mode .

Note

If unicode decode mode is already enabled (see set_unicode_decode_mode ) then this function won't affect the result charset (i.e. the MySQL system variable character_set_results).

Actually, a query SET character_set_results = utf8 will be sent immediately after setting the charset as above if unicode decode mode is enabled and charset isn't "utf8".

Note

You should always use either this function or the "mysql_charset_name" option to create to set the connection charset, or more specifically the charset that the server expects queries to have (i.e. the MySQL system variable character_set_client). Otherwise big_query might not work correctly.

Afterwards you may change the system variable character_set_connection, and also character_set_results if unicode decode mode isn't enabled.

Note

The MySQL latin1 charset is close to Windows cp1252. The difference from ISO-8859-1 is a bunch of printable chars in the range 0x80..0x9f (which contains control chars in ISO-8859-1). For instance, the euro currency sign is 0x80.

You can use the mysql-latin1 encoding in the Locale.Charset module to do conversions, or just use the special "unicode" charset instead.

See also

get_charset , set_unicode_encode_mode , set_unicode_decode_mode