Select Git revision
mysql.pike 32.06 KiB
/*
* $Id$
*
* Glue for the Mysql-module
*/
//! Implements the glue needed to access the Mysql-module from the generic
//! SQL module.
#pike __REAL_VERSION__
// Cannot dump this since the #if constant(...) check below may depend
// on the presence of system libs at runtime.
constant dont_dump_program = 1;
#if constant(Mysql.mysql)
inherit Mysql.mysql;
#define UNICODE_DECODE_MODE 1 // Unicode decode mode
#define LATIN1_UNICODE_ENCODE_MODE 2 // Unicode encode mode with latin1 charset
#define UTF8_UNICODE_ENCODE_MODE 4 // Unicode encode mode with utf8 charset
#ifdef MYSQL_CHARSET_DEBUG
#define CH_DEBUG(X...) werror("Sql.mysql: " + X)
#else
#define CH_DEBUG(X...)
#endif
#if !constant (Mysql.mysql.HAVE_MYSQL_FIELD_CHARSETNR)
// Recognition constant to tell that the unicode decode mode would use
// the buggy MySQLBrokenUnicodeWrapper if it would be enabled through
// any of the undocumented methods.
constant unicode_decode_mode_is_broken = 1;
#endif
// Set to the above if the connection is requested to be in one of the
// unicode modes. latin1 unicode encode mode is enabled by default; it
// should be compatible with earlier pike versions.
protected int utf8_mode;
// The charset, either "latin1" or "utf8", currently assigned to
// character_set_client when unicode encode mode is enabled. Zero when
// the connection charset has been set to something else than "latin1"
// or "unicode".
protected string send_charset;
protected void update_unicode_encode_mode_from_charset (string charset)
{
switch (charset) { // Lowercase assumed.
case "latin1":
utf8_mode |= LATIN1_UNICODE_ENCODE_MODE;
utf8_mode &= ~UTF8_UNICODE_ENCODE_MODE;
send_charset = "latin1";
CH_DEBUG ("Entering latin1 encode mode.\n");
break;
case "unicode":
utf8_mode |= UTF8_UNICODE_ENCODE_MODE;
utf8_mode &= ~LATIN1_UNICODE_ENCODE_MODE;
send_charset = "utf8";
CH_DEBUG ("Entering unicode encode mode.\n");
break;
default:
// Wrong charset - the mode can't be used.
utf8_mode |= LATIN1_UNICODE_ENCODE_MODE|UTF8_UNICODE_ENCODE_MODE;
send_charset = 0;
CH_DEBUG ("Not entering latin1/unicode encode mode "
"due to incompatible charset %O.\n", charset);
break;
}