pike.git / lib / modules / Sql.pmod / mysql.pike

version» Context lines:

pike.git/lib/modules/Sql.pmod/mysql.pike:1:   /* -  * $Id: mysql.pike,v 1.31 2006/12/05 11:48:21 grubba Exp $ +  * $Id: mysql.pike,v 1.32 2007/05/03 13:57:35 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:16:   #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    + #ifndef (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.   static 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".   static string send_charset;
pike.git/lib/modules/Sql.pmod/mysql.pike:102:   //!   //! Tip: If you enable @expr{utf8@} on the server side, you need to   //! send raw binary strings as @expr{_binary'...'@}. Otherwise they   //! will get UTF-8 encoded by the server.   //!   //! @note   //! When unicode encode mode is enabled and the connection charset   //! is @expr{latin1@}, the charset accepted by @[big_query] is not   //! quite Unicode since @expr{latin1@} is based on @expr{cp1252@}.   //! The differences are in the range @expr{0x80..0x9f@} where - //! Unicode have control chars. + //! Unicode has control chars.   //!   //! This small discrepancy is not present when the connection   //! charset is @expr{unicode@}.   //!   //! @seealso   //! @[set_unicode_decode_mode], @[set_charset]   {    if (enable)    update_unicode_encode_mode_from_charset (lower_case (get_charset()));    else {
pike.git/lib/modules/Sql.pmod/mysql.pike:149:   //! @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 function is only available if Pike has been compiled with - //! MySQL client library 4.1.0 or later, or if the environment - //! variable @tt{PIKE_BROKEN_MYSQL_UNICODE_MODE@} is set. + //! An error is also thrown if Pike has been compiled with a MySQL + //! client library older than 4.1.0, which lack the necessary + //! support for this.   //!   //! @seealso   //! @[set_unicode_encode_mode]   {   #if !constant (Mysql.mysql.HAVE_MYSQL_FIELD_CHARSETNR) -  if (!getenv("PIKE_BROKEN_MYSQL_UNICODE_MODE")) { -  predef::error("set_unicode_decode_mode not available.\n"); +  // Undocumented feature for old mysql libs. See +  // MySQLBrokenUnicodeWrapper for details. +  if (!(<0, -1>)[enable] && !getenv("PIKE_BROKEN_MYSQL_UNICODE_MODE")) { +  predef::error ("Unicode decode mode not supported - " +  "compiled with MySQL client library < 4.1.0.\n");    }   #endif -  +     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;    }
pike.git/lib/modules/Sql.pmod/mysql.pike:253:   //! @[Locale.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"; +     ::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) +  if (broken_unicode || getenv ("PIKE_BROKEN_MYSQL_UNICODE_MODE")) +  // Undocumented feature for old mysql libs. See +  // MySQLBrokenUnicodeWrapper for details.    utf8_mode |= UNICODE_DECODE_MODE;    else    predef::error ("Unicode decode mode not supported - "    "compiled with MySQL client library < 4.1.0.\n");   #endif    }    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");
pike.git/lib/modules/Sql.pmod/mysql.pike:303:   //! If the returned charset is @expr{latin1@} or @expr{unicode@} and   //! unicode encode mode is enabled (the default) then   //! @expr{character_set_client@} in the server might be either   //! @expr{latin1@} or @expr{utf8@}, depending on the last sent   //! query. See @[set_unicode_encode_mode] for more info.   //!   //! @seealso   //! @[set_charset]   {    if (utf8_mode & UTF8_UNICODE_ENCODE_MODE && send_charset) +  // We don't try to be symmetric with set_charset when the +  // broken-unicode kludge is in use. That since this reflects the +  // setting on the encode side only.    return "unicode";    return ::get_charset();   }      #if constant( Mysql.mysql.MYSQL_NO_ADD_DROP_DB )   // Documented in the C-file.   void create_db( string db )   {    ::big_query( "CREATE DATABASE "+db );   }
pike.git/lib/modules/Sql.pmod/mysql.pike:703:    "usage", "values", "varchar", "variables", "varying", "varbinary",    "with", "write", "when", "where", "year", "year_month", "zerofill",    >)[ lower_case(name) ];   }      static void create(string|void host, string|void database,    string|void user, string|void password,    mapping(string:string|int)|void options)   {    if (options) { -  string charset = options->mysql_charset_name || "latin1"; +  string charset = options->mysql_charset_name ? +  lower_case (options->mysql_charset_name) : "latin1"; +  +  int broken_unicode = charset == "broken-unicode"; +  if (broken_unicode) charset = "unicode"; +     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 (set_unicode_encode_mode) { +  // Undocumented feature for old mysql libs. See +  // MySQLBrokenUnicodeWrapper for details. +  if (broken_unicode || getenv ("PIKE_BROKEN_MYSQL_UNICODE_MODE")) {   #endif    if (charset == "unicode")    utf8_mode |= UNICODE_DECODE_MODE;    else if (options->unicode_decode_mode)    set_unicode_decode_mode (1);   #if !constant (Mysql.mysql.HAVE_MYSQL_FIELD_CHARSETNR)    }    else    if (charset == "unicode" || options->unicode_decode_mode)    predef::error ("Unicode decode mode not supported - "