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

version» Context lines:

pike.git/lib/modules/Sql.pmod/sql_util.pmod:1:   /* -  * $Id: sql_util.pmod,v 1.15 2006/08/11 11:08:44 grubba Exp $ +  * $Id: sql_util.pmod,v 1.16 2006/11/17 18:43:17 mast Exp $    *    * Some SQL utility functions.    * They are kept here to avoid circular references.    *    * Henrik Grubbström 1999-07-01    */      #pike __REAL_VERSION__      //! Some SQL utility functions
pike.git/lib/modules/Sql.pmod/sql_util.pmod:54:    });    // Throws if mapping key is empty string.    k=map(indices(bindings),lambda(string s){    return ( (stringp(s)&&s[0]==':') ?    s : ":"+s);    });    return replace(query,k,v);   }      //! 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    )   {    //! Returns the number of rows in the result.    int num_rows()    {    return master_result->num_rows();    }
pike.git/lib/modules/Sql.pmod/sql_util.pmod:128:       //! Fetch the next row from the result.    //!    //! All strings in the result are decoded from UTF8.    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]->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