pike.git/lib/modules/Sql.pmod/mysql.pike:1:
/*
- * $Id: mysql.pike,v 1.23 2006/11/17 18:43:11 mast Exp $
+ * $Id: mysql.pike,v 1.24 2006/11/27 16:28:39 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:637:
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;
- #if constant (Mysql.mysql.HAVE_MYSQL_FIELD_CHARSETNR)
+
if (utf8_mode & UNICODE_DECODE_MODE) {
CH_DEBUG ("Using MySQLUnicodeWrapper for result.\n");
-
+ #if constant (Mysql.mysql.HAVE_MYSQL_FIELD_CHARSETNR)
return .sql_util.MySQLUnicodeWrapper(res);
- }
+ #else
+ return .sql_util.MySQLBrokenUnicodeWrapper (res);
#endif
-
+ }
return res;
}
int(0..1) is_keyword( string name )
//! Return 1 if the argument @[name] is a mysql keyword.
{
// FIXME: Document which version of MySQL this is up-to-date with.
return (<
"action", "add", "aggregate", "all", "alter", "after", "and", "as",
"asc", "avg", "avg_row_length", "auto_increment", "between", "bigint",
pike.git/lib/modules/Sql.pmod/mysql.pike:704:
{
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");
}
}
#endif /* constant(Mysql.mysql) */