Kouhei Sutou
null+****@clear*****
Thu May 2 19:05:54 JST 2013
Kouhei Sutou 2013-05-02 19:05:54 +0900 (Thu, 02 May 2013) New Revision: 5afd15c4bec27ae3eae195aacb56c0e5988f52a0 https://github.com/groonga/groonga/commit/5afd15c4bec27ae3eae195aacb56c0e5988f52a0 Merged b5c0f27: Merge pull request #58 from groonga/support-cast-in-set-value-vector Message: Support vector element cast in grn_obj_set_value() This changes solves the following case: table_create Times TABLE_HASH_KEY Time table_create Sites TABLE_HASH_KEY ShortText column_create Sites modified_times COLUMN_VECTOR Times load --table Sites [ {"_key":"http://groonga.org", ["2013-04-29 00:00:00", "2013-05-02 01:46:48"]} ] Without this change, ["2013-04-29 00:00:00", "2013-05-02 01:46:48"] are broken. Because these strings aren't casted. Note that the above example isn't right. Because "load" command casts ["2013-04-29 00:00:00", "2013-05-02 01:46:48"] before "load" command passes them to grn_obj_set_value(). This problem is caused when groonga is used as a library such as rroonga use case. Modified files: lib/db.c Modified: lib/db.c (+30 -2) =================================================================== --- lib/db.c 2013-05-02 14:00:36 +0900 (0b66b1d) +++ lib/db.c 2013-05-02 19:05:54 +0900 (6a50b32) @@ -5245,12 +5245,40 @@ grn_obj_set_value(grn_ctx *ctx, grn_obj *obj, grn_id id, if (value->u.v.body) { int j; grn_section *v; + grn_obj value_buf, cast_buf; const char *head = GRN_BULK_HEAD(value->u.v.body); + GRN_OBJ_INIT(&value_buf, GRN_BULK, 0, GRN_DB_VOID); + GRN_OBJ_INIT(&cast_buf, GRN_BULK, 0, range); for (j = value->u.v.n_sections, v = value->u.v.sections; j; j--, v++) { - grn_id tid = grn_table_add(ctx, lexicon, - head + v->offset, v->length, NULL); + const char *value_ptr = head + v->offset; + int value_length = v->length; + grn_id tid; + if (range != v->domain) { + GRN_BULK_REWIND(&value_buf); + grn_bulk_write(ctx, &value_buf, value_ptr, value_length); + value_buf.header.domain = v->domain; + rc = grn_obj_cast(ctx, &value_buf, &cast_buf, GRN_TRUE); + if (rc) { + grn_obj *range_obj; + range_obj = grn_ctx_at(ctx, range); + REPORT_CAST_ERROR(obj, range_obj, &value_buf); + grn_obj_unlink(ctx, range_obj); + } else { + value_ptr = GRN_BULK_HEAD(&cast_buf); + value_length = GRN_BULK_VSIZE(&cast_buf); + } + } else { + rc = GRN_SUCCESS; + } + if (rc) { + continue; + } + tid = grn_table_add(ctx, lexicon, + value_ptr, value_length, NULL); grn_bulk_write(ctx, &buf, (char *)&tid, sizeof(grn_id)); } + GRN_OBJ_FIN(ctx, &value_buf); + GRN_OBJ_FIN(ctx, &cast_buf); } rc = grn_ja_put(ctx, (grn_ja *)obj, id, GRN_BULK_HEAD(&buf), GRN_BULK_VSIZE(&buf), flags, NULL); -------------- next part -------------- HTML����������������������������... Télécharger