pike.git/lib/modules/Sql.pmod/mysql.pike:1:
/*
- * $Id: mysql.pike,v 1.34 2006/11/17 18:43:17 mast Exp $
+ * $Id: mysql.pike,v 1.35 2006/11/27 16:32:41 mast Exp $
*
* Glue for the Mysql-module
*/
//! Implements the glue needed to access the Mysql-module from the generic
//! SQL module.
#pike __REAL_VERSION__
#if constant(Mysql.mysql)
pike.git/lib/modules/Sql.pmod/mysql.pike:131:
//! Returns nonzero if unicode encode mode is enabled, zero otherwise.
//!
//! @seealso
//! @[set_unicode_encode_mode]
{
return !!send_charset;
}
#if constant (Mysql.mysql.HAVE_MYSQL_FIELD_CHARSETNR)
void set_unicode_decode_mode (int enable)
+ #else
+ static void broken_set_unicode_decode_mode (int enable)
+ #endif
//! Enable or disable unicode decode mode.
//!
//! In this mode, if the server supports UTF-8 then non-binary text
//! strings in results are automatically decoded to (possibly wide)
//! unicode strings. Not enabled by default.
//!
//! The statement "@expr{SET character_set_results = utf8@}" is sent
//! to the server to enable the mode. When the mode is disabled,
//! "@expr{SET character_set_results = xxx@}" is sent, where
//! @expr{xxx@} is the connection charset that @[get_charset] returns.
pike.git/lib/modules/Sql.pmod/mysql.pike:168: Inside #if constant (Mysql.mysql.HAVE_MYSQL_FIELD_CHARSETNR)
CH_DEBUG("Enabling unicode decode mode.\n");
::big_query ("SET character_set_results = utf8");
utf8_mode |= UNICODE_DECODE_MODE;
}
else {
CH_DEBUG("Disabling unicode decode mode.\n");
::big_query ("SET character_set_results = " + get_charset());
utf8_mode &= ~UNICODE_DECODE_MODE;
}
}
+
+ #if !constant (Mysql.mysql.HAVE_MYSQL_FIELD_CHARSETNR)
+ // See blurb at MySQLBrokenUnicodeWrapper in sql_util.pmod. The
+ // PIKE_BROKEN_MYSQL_UNICODE_MODE thingy ought to be a define, but
+ // it's an environment variable instead to avoid problems with
+ // overcaching in dumped files.
+ function(int:void) set_unicode_decode_mode =
+ getenv ("PIKE_BROKEN_MYSQL_UNICODE_MODE") &&
+ broken_set_unicode_decode_mode;
#endif
int get_unicode_decode_mode()
//! Returns nonzero if unicode decode mode is enabled, zero otherwise.
//!
//! @seealso
//! @[set_unicode_decode_mode]
{
return utf8_mode & UNICODE_DECODE_MODE;
}
pike.git/lib/modules/Sql.pmod/mysql.pike:259:
::set_charset (charset == "unicode" ? "utf8" : charset);
if (charset == "unicode" ||
utf8_mode & (LATIN1_UNICODE_ENCODE_MODE|UTF8_UNICODE_ENCODE_MODE))
update_unicode_encode_mode_from_charset (charset);
if (charset == "unicode") {
#if constant (Mysql.mysql.HAVE_MYSQL_FIELD_CHARSETNR)
utf8_mode |= UNICODE_DECODE_MODE;
#else
+ if (set_unicode_decode_mode)
+ utf8_mode |= UNICODE_DECODE_MODE;
+ else
predef::error ("Unicode decode mode not supported - "
"compiled with MySQL client library < 4.1.0.\n");
#endif
}
- #if constant (Mysql.mysql.HAVE_MYSQL_FIELD_CHARSETNR)
+
else if (utf8_mode & UNICODE_DECODE_MODE && charset != "utf8")
// This setting has been overridden by ::set_charset, so we need
// to reinstate it.
::big_query ("SET character_set_results = utf8");
- #endif
+
}
string get_charset()
//! Returns the MySQL name for the current connection charset.
//!
//! Returns @expr{"unicode"@} if unicode encode mode is enabled and
//! UTF-8 is used on the server side (i.e. in
//! @expr{character_set_connection@}).
//!
//! @note
pike.git/lib/modules/Sql.pmod/mysql.pike:557:
else {
int n = sizeof (timestr);
if (n >= 12)
return decode_date (timestr[..n-7]) + decode_time (timestr[n-6..n-1]);
else
return decode_date (timestr);
}
}
#if constant (Mysql.mysql.HAVE_MYSQL_FIELD_CHARSETNR)
- #define HAVE_MYSQL_FIELD_CHARSETNR_DO(X...) X
+ #define HAVE_MYSQL_FIELD_CHARSETNR_IFELSE(TRUE, FALSE) TRUE
#else
- #define HAVE_MYSQL_FIELD_CHARSETNR_DO(X...)
+ #define HAVE_MYSQL_FIELD_CHARSETNR_IFELSE(TRUE, FALSE) FALSE
#endif
#define QUERY_BODY(do_query) \
if (bindings) \
query = .sql_util.emulate_bindings(query,bindings,this); \
\
string restore_charset; \
if (charset) { \
restore_charset = send_charset || get_charset(); \
if (charset != restore_charset) { \
pike.git/lib/modules/Sql.pmod/mysql.pike:640:
else { \
CH_DEBUG ("Restoring charset %O.\n", restore_charset); \
::big_query ("SET character_set_client=" + restore_charset); \
/* Can't be changed automatically - has side effects. /mast */ \
/* ::big_query("SET character_set_connection=" + restore_charset); */ \
} \
} \
\
if (!objectp(res)) return res; \
\
- HAVE_MYSQL_FIELD_CHARSETNR_DO ( \
+
if (utf8_mode & UNICODE_DECODE_MODE) { \
- CH_DEBUG ("Using UnicodeWrapper for result.\n"); \
- return .sql_util.UnicodeWrapper(res); \
+ CH_DEBUG ("Using unicode wrapper for result.\n"); \
+ return \
+ HAVE_MYSQL_FIELD_CHARSETNR_IFELSE ( \
+ .sql_util.MySQLUnicodeWrapper(res), \
+ .sql_util.MySQLBrokenUnicodeWrapper (res)); \
} \
- ); \
+
return res;
Mysql.mysql_result big_query (string query,
mapping(string|int:mixed)|void bindings,
void|string charset)
//! Sends a query to the server.
//!
//! @param query
//! The SQL query.
//!
pike.git/lib/modules/Sql.pmod/mysql.pike:757:
{
if (options) {
string charset = options->mysql_charset_name || "latin1";
if (charset == "unicode")
options->mysql_charset_name = "utf8";
::create(host||"", database||"", user||"", password||"", options);
update_unicode_encode_mode_from_charset (lower_case (charset));
- #if constant (Mysql.mysql.HAVE_MYSQL_FIELD_CHARSETNR)
+ #if !constant (Mysql.mysql.HAVE_MYSQL_FIELD_CHARSETNR)
+ if (set_unicode_encode_mode) {
+ #endif
if (charset == "unicode")
utf8_mode |= UNICODE_DECODE_MODE;
else if (options->unicode_decode_mode)
set_unicode_decode_mode (1);
- #else
+ #if !constant (Mysql.mysql.HAVE_MYSQL_FIELD_CHARSETNR)
+ }
+ else
if (charset == "unicode" || options->unicode_decode_mode)
predef::error ("Unicode decode mode not supported - "
"compiled with MySQL client library < 4.1.0.\n");
#endif
} else {
::create(host||"", database||"", user||"", password||"");
update_unicode_encode_mode_from_charset ("latin1");
}
}
#else
constant this_program_does_not_exist=1;
#endif /* constant(Mysql.mysql) */