null+****@clear*****
null+****@clear*****
2010年 8月 23日 (月) 11:29:10 JST
Kouhei Sutou 2010-08-23 02:29:10 +0000 (Mon, 23 Aug 2010)
New Revision: 39a5b65c95183635d9cb6aa802b68f57624e0ae8
Log:
report error on failing to delete a record. #428
Modified files:
lib/db.c
test/unit/core/test-command-delete.c
test/unit/lib/grn-assertions.h
test/unit/lib/grn-test-shortcut.h
Modified: lib/db.c (+13 -2)
===================================================================
--- lib/db.c 2010-08-22 04:52:13 +0000 (e94f1c6)
+++ lib/db.c 2010-08-23 02:29:10 +0000 (0e12196)
@@ -1207,9 +1207,20 @@ is_deletable(grn_ctx *ctx, grn_obj *table, grn_id id)
grn_obj *col = grn_ctx_at(ctx, *key);
if (col && col->header.type == GRN_COLUMN_INDEX &&
(esize = grn_ii_estimate_size(ctx, (grn_ii *)col, id))) {
- GRN_LOG(ctx, GRN_WARN, "undeletable record(%d:%d) has value (%d:%d)",
- DB_OBJ(table)->id, id, *key, esize);
+ int len;
+ char table_name[GRN_PAT_MAX_KEY_SIZE];
+ char column_name[GRN_PAT_MAX_KEY_SIZE];
+ len = grn_obj_name(ctx, table, table_name, GRN_PAT_MAX_KEY_SIZE);
+ table_name[len] = '\0';
+ len = grn_column_name(ctx, col, column_name, GRN_PAT_MAX_KEY_SIZE);
+ column_name[len] = '\0';
+ GRN_LOG(ctx, GRN_WARN,
+ "undeletable record (%s:%d) has value (%s:%d)",
+ table_name, id, column_name, esize);
LOGTRACE(ctx, GRN_WARN);
+ ERR(GRN_OPERATION_NOT_PERMITTED,
+ "undeletable record (%s:%d) has value (%s:%d)",
+ table_name, id, column_name, esize);
res = 0;
}
});
Modified: test/unit/core/test-command-delete.c (+35 -4)
===================================================================
--- test/unit/core/test-command-delete.c 2010-08-22 04:52:13 +0000 (c0bae5f)
+++ test/unit/core/test-command-delete.c 2010-08-23 02:29:10 +0000 (088f64f)
@@ -25,6 +25,7 @@
void test_by_id(void);
void test_by_key(void);
+void test_referenced_record(void);
static gchar *tmp_directory;
@@ -55,11 +56,20 @@ static void
setup_data(void)
{
assert_send_command("table_create Users TABLE_HASH_KEY ShortText");
+ assert_send_command("table_create Bookmarks TABLE_HASH_KEY ShortText");
+ assert_send_command("column_create Bookmarks user COLUMN_SCALAR Users");
+ assert_send_command("column_create Users bookmarks COLUMN_INDEX "
+ "Bookmarks user");
assert_send_command("load --table Users --columns '_key'\n"
"[\n"
" [\"mori\"],\n"
" [\"tapo\"]\n"
"]");
+ assert_send_command("load --table Bookmarks --columns '_key, user'\n"
+ "[\n"
+ " [\"http://groonga.org/\", \"yu\"],\n"
+ " [\"http://cutter.sourceforge.net/\", \"tasukuchan\"]\n"
+ "]");
}
void
@@ -94,9 +104,11 @@ void
test_by_id(void)
{
assert_send_command("delete Users --id 1");
- cut_assert_equal_string("[[[1],"
+ cut_assert_equal_string("[[[3],"
"[[\"_key\",\"ShortText\"]],"
- "[\"tapo\"]]]",
+ "[\"tapo\"],"
+ "[\"yu\"],"
+ "[\"tasukuchan\"]]]",
send_command("select Users "
"--output_columns _key"));
}
@@ -105,9 +117,28 @@ void
test_by_delete(void)
{
assert_send_command("delete Users tapo");
- cut_assert_equal_string("[[[1],"
+ cut_assert_equal_string("[[[3],"
+ "[[\"_key\",\"ShortText\"]],"
+ "[\"mori\"],"
+ "[\"yu\"],"
+ "[\"tasukuchan\"]]]",
+ send_command("select Users "
+ "--output_columns _key"));
+}
+
+void
+test_referenced_record(void)
+{
+ assert_send_command_error(GRN_OPERATION_NOT_PERMITTED,
+ "undeletable record (Users:3) "
+ "has value (bookmarks:1)",
+ "delete Users yu");
+ cut_assert_equal_string("[[[4],"
"[[\"_key\",\"ShortText\"]],"
- "[\"mori\"]]]",
+ "[\"mori\"],"
+ "[\"tapo\"],"
+ "[\"yu\"],"
+ "[\"tasukuchan\"]]]",
send_command("select Users "
"--output_columns _key"));
}
Modified: test/unit/lib/grn-assertions.h (+1 -1)
===================================================================
--- test/unit/lib/grn-assertions.h 2010-08-22 04:52:13 +0000 (8bbd749)
+++ test/unit/lib/grn-assertions.h 2010-08-23 02:29:10 +0000 (8a49da4)
@@ -152,7 +152,7 @@
#define grn_test_assert_send_command_error(context, expected_rc, \
expected_message, command, \
- ...) \
+ ...) \
cut_trace_with_info_expression( \
cut_test_with_user_message( \
grn_test_assert_send_command_error_helper((context), \
Modified: test/unit/lib/grn-test-shortcut.h (+6 -0)
===================================================================
--- test/unit/lib/grn-test-shortcut.h 2010-08-22 04:52:13 +0000 (a5a30bc)
+++ test/unit/lib/grn-test-shortcut.h 2010-08-23 02:29:10 +0000 (755f069)
@@ -32,6 +32,12 @@
__VA_ARGS__), \
grn_assert_send_command(context, command))
+#define assert_send_command_error(expected_rc, expected_message, \
+ command, ...) \
+ grn_test_assert_send_command_error(context, \
+ expected_rc, expected_message, \
+ command, __VA_ARGS__)
+
#define assert_send_commands(commands, ...) \
cut_trace_with_info_expression( \
cut_test_with_user_message( \