susumu.yata
null+****@clear*****
Fri Jul 10 16:14:36 JST 2015
susumu.yata 2015-07-10 16:14:36 +0900 (Fri, 10 Jul 2015) New Revision: a708570d5ce961a6558ed34e62343b56f3ade871 https://github.com/groonga/grngo/commit/a708570d5ce961a6558ed34e62343b56f3ade871 Message: Add error handling to grngo_table_get_value_info(). GitHub: #12 Modified files: grngo.c grngo.go grngo.h Modified: grngo.c (+22 -31) =================================================================== --- grngo.c 2015-07-10 16:07:37 +0900 (80d31a8) +++ grngo.c 2015-07-10 16:14:36 +0900 (5023446) @@ -84,6 +84,28 @@ grn_rc grngo_table_get_key_info(grn_ctx *ctx, grn_obj *table, } } +grn_rc grngo_table_get_value_info(grn_ctx *ctx, grn_obj *table, + grngo_table_type_info *value_info) { + if (!ctx || !table || !grn_obj_is_table(ctx, table) || !value_info) { + return GRN_INVALID_ARGUMENT; + } + grngo_table_type_info_init(value_info); + grn_id range = grn_obj_get_range(ctx, table); + if (range <= GRNGO_MAX_BUILTIN_TYPE_ID) { + value_info->data_type = range; + return GRN_SUCCESS; + } + grn_obj *ref_table = grn_ctx_at(ctx, range); + if (!ref_table || !grn_obj_is_table(ctx, ref_table)) { + if (ctx->rc != GRN_SUCCESS) { + return ctx->rc; + } + return GRN_UNKNOWN_ERROR; + } + value_info->ref_table = ref_table; + return GRN_SUCCESS; +} + // grngo_init_type_info() initializes the members of type_info. // The initialized type info specifies a valid Void type. static void grngo_init_type_info(grngo_type_info *type_info) { @@ -92,37 +114,6 @@ static void grngo_init_type_info(grngo_type_info *type_info) { type_info->ref_table = NULL; } -grn_bool grngo_table_get_value_info(grn_ctx *ctx, grn_obj *table, - grngo_type_info *value_info) { - grngo_init_type_info(value_info); - if (!table) { - return GRN_FALSE; - } - switch (table->header.type) { - case GRN_TABLE_HASH_KEY: - case GRN_TABLE_PAT_KEY: - case GRN_TABLE_DAT_KEY: - case GRN_TABLE_NO_KEY: { - grn_id range = grn_obj_get_range(ctx, table); - if (range <= GRNGO_MAX_BUILTIN_TYPE_ID) { - value_info->data_type = range; - return GRN_TRUE; - } - value_info->ref_table = grn_ctx_at(ctx, range); - grngo_table_type_info key_info; - if (grngo_table_get_key_info(ctx, value_info->ref_table, &key_info) != GRN_SUCCESS) { - return GRN_FALSE; - } - value_info->data_type = key_info.data_type; - return GRN_TRUE; - } - default: { - // The object is not a table. - return GRN_FALSE; - } - } -} - grn_bool grngo_column_get_value_info(grn_ctx *ctx, grn_obj *column, grngo_type_info *value_info) { grngo_init_type_info(value_info); Modified: grngo.go (+10 -6) =================================================================== --- grngo.go 2015-07-10 16:07:37 +0900 (b9bf95d) +++ grngo.go 2015-07-10 16:14:36 +0900 (408a81c) @@ -748,18 +748,17 @@ func (db *DB) FindTable(name string) (*Table, error) { } keyType = finalTable.keyType } - var valueInfo C.grngo_type_info - if ok := C.grngo_table_get_value_info(db.ctx, obj, &valueInfo); ok != C.GRN_TRUE { - return nil, fmt.Errorf("grngo_table_get_value_info() failed: name = <%s>", name) + var valueInfo C.grngo_table_type_info + rc = C.grngo_table_get_value_info(db.ctx, obj, &valueInfo) + if rc != C.GRN_SUCCESS { + return nil, newGrnError("grngo_table_get_value_info()", &rc, db.ctx) } // Check the value type. valueType := DataType(valueInfo.data_type) // Find the destination table if the value is table reference. var valueTable *Table if valueInfo.ref_table != nil { - if valueType == Void { - return nil, fmt.Errorf("reference to void: name = <%s>", name) - } + defer C.grn_obj_unlink(db.ctx, valueInfo.ref_table) var cValueTableName *C.char rc := C.grngo_table_get_name(db.ctx, valueInfo.ref_table, &cValueTableName) if rc != C.GRN_SUCCESS { @@ -771,6 +770,11 @@ func (db *DB) FindTable(name string) (*Table, error) { if err != nil { return nil, err } + finalTable := valueTable + for finalTable.keyTable != nil { + finalTable = finalTable.keyTable + } + valueType = finalTable.keyType } table := newTable(db, obj, name, keyType, keyTable, valueType, valueTable) db.tables[name] = table Modified: grngo.h (+3 -3) =================================================================== --- grngo.h 2015-07-10 16:07:37 +0900 (041dbd4) +++ grngo.h 2015-07-10 16:14:36 +0900 (c6204ec) @@ -42,10 +42,10 @@ typedef struct { // grngo_table_get_key_info gets information of the table key (_key). grn_rc grngo_table_get_key_info(grn_ctx *ctx, grn_obj *table, grngo_table_type_info *key_info); +// grngo_table_get_value_info gets information of the table value (_value). +grn_rc grngo_table_get_value_info(grn_ctx *ctx, grn_obj *table, + grngo_table_type_info *value_info); -// grngo_table_get_value_info() gets information of the table value. -grn_bool grngo_table_get_value_info(grn_ctx *ctx, grn_obj *table, - grngo_type_info *value_info); // grngo_column_get_value_info() gets information of the column value. grn_bool grngo_column_get_value_info(grn_ctx *ctx, grn_obj *column, grngo_type_info *value_info); -------------- next part -------------- HTML����������������������������...Download