pike.git/lib/modules/Sql.pmod/mysql.pike:1:
/*
- * $Id$
- *
+
* Glue for the Mysql-module
*/
//! This class encapsulates a connection to a MySQL server, and
//! implements the glue needed to access the Mysql module from the
//! generic SQL module.
//!
//! @section Typed mode
//!
//! When query results are returned in typed mode, the MySQL data
pike.git/lib/modules/Sql.pmod/mysql.pike:47:
//! @item String types
//! All string types are returned as pike strings. The MySQL glue
//! can handle charset conversions for text strings - see
//! @[set_charset] and @[set_unicode_decode_mode].
//!
//! @enddl
//!
//! @endsection
#pike __REAL_VERSION__
+ #require constant(Mysql.mysql)
- // Cannot dump this since the #if constant(...) check below may depend
- // on the presence of system libs at runtime.
+ // Cannot dump this since the #require check 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)
+ #define CH_DEBUG(X...) \
+ werror(replace (sprintf ("%O", this), "%", "%%") + ": " + 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
pike.git/lib/modules/Sql.pmod/mysql.pike:303:
//! @expr{character_set_results@} if unicode decode mode isn't
//! enabled.
//!
//! @note
//! The MySQL @expr{latin1@} charset is close to Windows
//! @expr{cp1252@}. The difference from ISO-8859-1 is a bunch of
//! printable chars in the range @expr{0x80..0x9f@} (which contains
//! control chars in ISO-8859-1). For instance, the euro currency
//! sign is @expr{0x80@}.
//!
- //! You can use the @expr{mysql-latin1@} encoding in the
- //! @[Locale.Charset] module to do conversions, or just use the
- //! special @expr{"unicode"@} charset instead.
+ //! You can use the @expr{mysql-latin1@} encoding in the @[Charset]
+ //! module to do conversions, or just use the special
+ //! @expr{"unicode"@} charset instead.
//!
//! @seealso
//! @[get_charset], @[set_unicode_encode_mode], @[set_unicode_decode_mode]
{
charset = lower_case (charset);
CH_DEBUG("Setting charset to %O.\n", charset);
int broken_unicode = charset == "broken-unicode";
if (broken_unicode) charset = "unicode";
pike.git/lib/modules/Sql.pmod/mysql.pike:659:
CH_DEBUG ("Switching charset from %O to %O (due to charset arg).\n", \
restore_charset, charset); \
::big_query ("SET character_set_client=" + charset); \
/* Can't be changed automatically - has side effects. /mast */ \
/* ::big_query("SET character_set_connection=" + charset); */ \
} else \
restore_charset = 0; \
} \
\
else if (send_charset) { \
- string new_send_charset; \
+ string new_send_charset = send_charset; \
\
if (utf8_mode & LATIN1_UNICODE_ENCODE_MODE) { \
if (String.width (query) == 8) \
new_send_charset = "latin1"; \
else { \
CH_DEBUG ("Converting (mysql-)latin1 query to utf8.\n"); \
query = utf8_encode_query (query, latin1_to_utf8); \
new_send_charset = "utf8"; \
} \
} \
\
else { /* utf8_mode & UTF8_UNICODE_ENCODE_MODE */ \
- if (_can_send_as_latin1 (query)) \
- new_send_charset = "latin1"; \
- else { \
+ /* NB: The send_charset may only be upgraded from \
+ * "latin1" to "utf8", not the other way around. \
+ * This is to avoid extraneous charset changes \
+ * where the charset is changed from query to query. \
+ */ \
+ if ((send_charset == "utf8") || !_can_send_as_latin1(query)) { \
CH_DEBUG ("Converting query to utf8.\n"); \
query = utf8_encode_query (query, string_to_utf8); \
new_send_charset = "utf8"; \
} \
} \
\
if (new_send_charset != send_charset) { \
CH_DEBUG ("Switching charset from %O to %O.\n", \
send_charset, new_send_charset); \
if (mixed err = catch { \
pike.git/lib/modules/Sql.pmod/mysql.pike:701:
predef::error ("The query is a wide string " \
"and the MySQL server doesn't support UTF-8: %s\n", \
describe_error (err)); \
else \
throw (err); \
} \
send_charset = new_send_charset; \
} \
} \
\
- CH_DEBUG ("Sending query with charset %O: %O.\n", \
- charset || send_charset, query); \
+ CH_DEBUG ("Sending query with charset %O: %s.\n", \
+ charset || send_charset, \
+ (sizeof (query) > 200 ? \
+ sprintf ("%O...", query[..200]) : \
+ sprintf ("%O", query))); \
\
int|object res = ::do_query(query); \
\
if (restore_charset) { \
if (send_charset && (<"latin1", "utf8">)[charset]) \
send_charset = charset; \
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 */ \
pike.git/lib/modules/Sql.pmod/mysql.pike:933: Inside #if !constant (Mysql.mysql.HAVE_MYSQL_FIELD_CHARSETNR)
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) */
+