null+****@clear*****
null+****@clear*****
2011年 6月 6日 (月) 16:55:25 JST
Kouhei Sutou 2011-06-06 07:55:25 +0000 (Mon, 06 Jun 2011)
New Revision: a2c474c8cf7b16377d91bf0c826be91d54bed925
Log:
[column][create] add nonexistent type name to error message. refs #952
Modified files:
lib/db.c
lib/proc.c
test/unit/core/test-command-column-create.c
Modified: lib/db.c (+5 -1)
===================================================================
--- lib/db.c 2011-06-06 06:30:44 +0000 (b7ad6c3)
+++ lib/db.c 2011-06-06 07:55:25 +0000 (4b5c48d)
@@ -2806,7 +2806,11 @@ grn_column_create(grn_ctx *ctx, grn_obj *table,
ERR(GRN_INVALID_ARGUMENT, "[column][create]: table is missing");
goto exit;
}
- if (!type || !name || !name_size) {
+ if (!type) {
+ ERR(GRN_INVALID_ARGUMENT, "[column][create]: type is missing");
+ goto exit;
+ }
+ if (!name || !name_size) {
ERR(GRN_INVALID_ARGUMENT, "missing type or name");
goto exit;
}
Modified: lib/proc.c (+9 -1)
===================================================================
--- lib/proc.c 2011-06-06 06:30:44 +0000 (7f491c8)
+++ lib/proc.c 2011-06-06 07:55:25 +0000 (ee83222)
@@ -638,7 +638,7 @@ proc_table_remove(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_d
static grn_obj *
proc_column_create(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
{
- grn_obj *column, *table, *type;
+ grn_obj *column, *table = NULL, *type = NULL;
const char *rest;
grn_obj_flags flags = grn_atoi(GRN_TEXT_VALUE(VAR(2)),
GRN_BULK_CURR(VAR(2)), &rest);
@@ -656,6 +656,12 @@ proc_column_create(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_
}
type = grn_ctx_get(ctx, GRN_TEXT_VALUE(VAR(3)),
GRN_TEXT_LEN(VAR(3)));
+ if (!type) {
+ ERR(GRN_INVALID_ARGUMENT,
+ "[column][create]: type doesn't exist: <%.*s>",
+ GRN_TEXT_LEN(VAR(3)), GRN_TEXT_VALUE(VAR(3))) ;
+ goto exit;
+ }
if (GRN_TEXT_LEN(VAR(1))) { flags |= GRN_OBJ_PERSISTENT; }
column = grn_column_create(ctx, table,
GRN_TEXT_VALUE(VAR(1)),
@@ -693,6 +699,8 @@ proc_column_create(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_
}
exit:
GRN_OUTPUT_BOOL(!ctx->rc);
+ if (table) { grn_obj_unlink(ctx, table); }
+ if (type) { grn_obj_unlink(ctx, type); }
return NULL;
}
Modified: test/unit/core/test-command-column-create.c (+12 -0)
===================================================================
--- test/unit/core/test-command-column-create.c 2011-06-06 06:30:44 +0000 (bed136d)
+++ test/unit/core/test-command-column-create.c 2011-06-06 07:55:25 +0000 (9e0cf16)
@@ -25,6 +25,7 @@
void test_invalid_name(void);
void test_nonexistent_table(void);
+void test_nonexistent_type(void);
static gchar *tmp_directory;
static const gchar *database_path;
@@ -98,3 +99,14 @@ test_nonexistent_table(void)
"[column][create]: table doesn't exist: <Users>",
"column_create Users name COLUMN_SCALAR ShortText");
}
+
+void
+test_nonexistent_type(void)
+{
+ assert_send_command("table_create Users");
+ grn_test_assert_send_command_error(
+ context,
+ GRN_INVALID_ARGUMENT,
+ "[column][create]: type doesn't exist: <VeryShortText>",
+ "column_create Users name COLUMN_SCALAR VeryShortText");
+}