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

version» Context lines:

pike.git/lib/modules/Sql.pmod/sql_util.pmod:84:       array(mixed) args=allocate(sizeof(extraargs));    if (!bindings) bindings = ([]);       int a, new_bindings;    foreach(extraargs; int j; mixed s) {    if (stringp(s) || multisetp(s)) {    string bind_name;    do {    bind_name = ":arg"+(a++); -  } while (!zero_type (bindings[bind_name])); +  } while (has_index (bindings, bind_name));    args[j]=bind_name;    bindings[bind_name] = s;    new_bindings = 1;    continue;    }    if (intp(s) || floatp(s)) {    args[j] = s || zero;    continue;    }    if (objectp (s) && s->is_val_null) {
pike.git/lib/modules/Sql.pmod/sql_util.pmod:127:   //! variables' names.   string emulate_bindings(string query, mapping(string|int:mixed)|void bindings,    void|object driver)   {    array(string)k, v;    if (!bindings)    return query;    function my_quote=(driver&&driver->quote?driver->quote:quote);    v=map(values(bindings),    lambda(mixed m) { -  if(zero_type(m)) +  if(undefinedp(m))    return "NULL";    if (objectp (m) && m->is_val_null)    // Note: Could need bug compatibility here - in some cases    // we might be passed a null object that can be cast to    // "", and before this it would be. This is an observed    // compat issue in comment #7 in [bug 5900].    return "NULL";    if(multisetp(m))    return sizeof(m) ? indices(m)[0] : "";    return "'"+(intp(m)?(string)m:my_quote((string)m))+"'";
pike.git/lib/modules/Sql.pmod/sql_util.pmod:153:    });    return replace(query,k,v);   }      //! Result object wrapper performing utf8 decoding of all fields.   class UnicodeWrapper (    // The wrapped result object.    protected object master_result    )   { +  inherit Sql.Result; +     //! Returns the number of rows in the result.    int num_rows()    {    return master_result->num_rows();    }       //! Returns the number of fields in the result.    int num_fields()    {    return master_result->num_fields();
pike.git/lib/modules/Sql.pmod/sql_util.pmod:191:    //! The table the field is from. Not present from all databases.    //! @member string "default"    //! The default value for the column. Not available from all databases.    //! @endmapping    array(int|mapping(string:mixed)) fetch_fields()    {    if (!field_info) {    field_info = master_result->fetch_fields();    foreach(field_info, int|mapping(string:mixed) field) {    if (mappingp(field)) { -  field->name = utf8_to_string(field->name); +  field->name = utf8_to_string(field->name, 2);    if (field->table) { -  field->table = utf8_to_string(field->table); +  field->table = utf8_to_string(field->table, 2);    }    if (field->default) { -  field->default = utf8_to_string(field->default); +  field->default = utf8_to_string(field->default, 2);    }    }    }    }    return field_info;    }       //! Skip ahead the specified number of rows.    void seek(int rows)    {
pike.git/lib/modules/Sql.pmod/sql_util.pmod:220:    //! 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)) { -  row[i] = utf8_to_string(val); +  row[i] = utf8_to_string(val, 2);    }    }    return row;    }       //! JSON is always utf8 default, do nothing.    int|string fetch_json_result()    {    return master_result->fetch_json_result();    }   }    - #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); +  row[i] = utf8_to_string(val, 2);    }    }    return row;    }   }    - #else -  +    class MySQLBrokenUnicodeWrapper - // This one is used to get a buggy unicode support when compiled with - // an old MySQL client lib that doesn't have the charsetnr property in - // the field info. It looks at the binary flag instead, which is set - // for binary fields but might also be set for text fields (e.g. with - // a definition like "VARCHAR(255) BINARY"). - // - // I.e. the effect of using this one is that text fields with the - // binary flag won't be correctly decoded in unicode decode mode. - // - // This has to be enabled either by passing "broken-unicode" as - // charset to Sql.mysql.create or Sql.mysql.set_charset, by calling - // Sql.mysql.set_unicode_decode_mode(-1), or by defining the - // environment variable PIKE_BROKEN_MYSQL_UNICODE_MODE. That will - // cause this buggy variant to be used if and only if the MySQL client - // lib doesn't support the charsetnr property. + //! This one is used to get a buggy unicode support when compiled with + //! an old MySQL client lib that doesn't have the charsetnr property in + //! the field info. It looks at the binary flag instead, which is set + //! for binary fields but might also be set for text fields (e.g. with + //! a definition like @expr{"VARCHAR(255) BINARY"@}). + //! + //! I.e. the effect of using this one is that text fields with the + //! binary flag won't be correctly decoded in unicode decode mode. + //! + //! This has to be enabled either by passing @expr{"broken-unicode"@} as + //! charset to @[Sql.mysql.create] or @[Sql.mysql.set_charset], by calling + //! @[Sql.mysql.set_unicode_decode_mode(-1)], or by defining the + //! environment variable @tt{PIKE_BROKEN_MYSQL_UNICODE_MODE@}. That will + //! cause this buggy variant to be used if and only if the MySQL client + //! lib doesn't support the charsetnr property.   {    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]->flags &&    !field_info[i]->flags->binary) { -  row[i] = utf8_to_string(val); +  row[i] = utf8_to_string(val, 2);    }    }    return row;    }   } -  - #endif +