Branch: Tag:

2006-11-17

2006-11-17 18:43:13 by Martin Stjernholm <mast@lysator.liu.se>

Added support for the charsetnr column attribute. Fixed proper recognition
of binary fields in unicode decode mode by using charsetnr instead of the
binary flag (which might be set for nonbinary columns too, e.g. "VARCHAR(17)
BINARY").

Unfortunately this means that unicode decode mode is disabled if Pike is
compiled with a client lib without support for the charsetnr attribute. That
means libs before 4.1.0.

Rev: lib/modules/Sql.pmod/mysql.pike:1.23
Rev: lib/modules/Sql.pmod/sql_util.pmod:1.12
Rev: src/modules/Mysql/acconfig.h:1.16
Rev: src/modules/Mysql/configure.in:1.46
Rev: src/modules/Mysql/mysql.c:1.83
Rev: src/modules/Mysql/result.c:1.32

1:   /* -  * $Id: sql_util.pmod,v 1.11 2006/08/15 14:52:34 grubba Exp $ +  * $Id: sql_util.pmod,v 1.12 2006/11/17 18:43:11 mast Exp $    *    * Some SQL utility functions.    * They are kept here to avoid circular references.
61:   }      //! Result object wrapper performing utf8 decoding of all fields. - //! - //! Useful for eg Mysql connections which have been set to utf8-mode - //! using eg @expr{"SET NAMES 'utf8'"@}. +    class UnicodeWrapper (    //! The wrapped result object.    static object master_result
135:    if (!arrayp(row)) return row;    array(int|mapping(string:mixed)) field_info = fetch_fields();    foreach(row; int i; string|int val) { -  if (stringp(val) && field_info[i]->flags && -  !field_info[i]->flags->binary) { +  if (stringp(val)) {    row[i] = utf8_to_string(val);    }    }    return row;    }   } -  +  + #if constant (Mysql.mysql.HAVE_MYSQL_FIELD_CHARSETNR) + class MySQLUnicodeWrapper + //! Result wrapper for MySQL that performs UTF-8 decoding of all + //! nonbinary fields. Useful if the result charset of the connection + //! has been set to UTF-8. + //! + //! @note + //! There's normally no need to use this class directly. It's used + //! automatically when @[Mysql.set_unicode_decode_mode] is activated. + { +  inherit UnicodeWrapper; +  +  int|array(string) fetch_row() +  { +  int|array(string) row = master_result->fetch_row(); +  if (!arrayp(row)) return row; +  array(int|mapping(string:mixed)) field_info = fetch_fields(); +  foreach(row; int i; string|int val) { +  if (stringp(val) && field_info[i]->charsetnr != 63) { +  row[i] = utf8_to_string(val); +  } +  } +  return row; +  } + } + #endif