pike.git
/
lib
/
modules
/
Sql.pmod
/
mysql.pike
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/lib/modules/Sql.pmod/mysql.pike:1:
/*
-
* $Id: mysql.pike,v 1.
27
2006/
09
/
18
16
:
05
:
18
mast Exp $
+
* $Id: mysql.pike,v 1.
28
2006/
11
/
17
18:
43
:
13
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:129:
int get_unicode_encode_mode() //! 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) //! Enable or disable unicode decode mode. //! //! In this mode, if the server supports UTF-8 then non-binary text
-
//! strings in results are
are
automatically decoded to (possibly
-
//!
wide)
unicode strings. Not enabled by default.
+
//! 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. //! //! @param enable //! Nonzero enables this feature, zero disables it. //! //! @throws //! Throws an exception if the server doesn't support this, i.e. if //! the statement above fails. The MySQL system variable //! @expr{character_set_results@} was added in MySQL 4.1.1. //! //! @note
-
//! This
mode
is
not
compatible
with
earlier
pike
versions.
You
need
-
//!
to
run
in
compatibility mode <= 7
.
6
to
have it disabled by
-
//! default
.
+
//! This
function
is
only
available
if
Pike
has
been
compiled
with
+
//!
MySQL
client
library
4
.
1.0
or
later
.
//! //! @seealso //! @[set_unicode_encode_mode] { if (enable) { 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; } }
-
+
#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:254:
charset = lower_case (charset); CH_DEBUG("Setting charset to %O.\n", charset); ::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 (charset == "unicode")
{
+
#if constant (Mysql.mysql.HAVE_MYSQL_FIELD_CHARSETNR)
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:628:
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
UnicodeWrapper
for result.\n");
-
return .sql_util.
UnicodeWrapper
(res);
+
CH_DEBUG ("Using
MySQLUnicodeWrapper
for result.\n");
+
return .sql_util.
MySQLUnicodeWrapper
(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:693:
{ 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 (charset == "unicode") utf8_mode |= UNICODE_DECODE_MODE; else if (options->unicode_decode_mode) set_unicode_decode_mode (1);
-
+
#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) */