null+****@clear*****
null+****@clear*****
2010年 8月 27日 (金) 00:14:38 JST
Kouhei Sutou 2010-08-26 15:14:38 +0000 (Thu, 26 Aug 2010)
New Revision: 74c35721daa3bf829f6bf2912eeb8ce1eeb68242
Log:
delete command: support record deletion with no text key table.
Reported by Itagaki Takahiro. Thanks!!!
Modified files:
lib/proc.c
test/unit/core/test-command-delete.c
Modified: lib/proc.c (+12 -2)
===================================================================
--- lib/proc.c 2010-08-26 09:14:38 +0000 (66d04f9)
+++ lib/proc.c 2010-08-26 15:14:38 +0000 (cccd1df)
@@ -1328,8 +1328,18 @@ proc_delete(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
if (GRN_TEXT_LEN(VAR(1)) && GRN_TEXT_LEN(VAR(2))) {
ERR(GRN_INVALID_ARGUMENT, "both id and key are specified");
} else if (GRN_TEXT_LEN(VAR(1))) {
- rc = grn_table_delete(ctx, table, GRN_TEXT_VALUE(VAR(1)),
- GRN_TEXT_LEN(VAR(1)));
+ grn_obj *p_key = VAR(1);
+ grn_obj key;
+ if (p_key->header.domain != table->header.domain) {
+ GRN_OBJ_INIT(&key, GRN_BULK, 0, table->header.domain);
+ grn_obj_cast(ctx, p_key, &key, GRN_FALSE);
+ p_key = &key;
+ }
+ rc = grn_table_delete(ctx, table,
+ GRN_BULK_HEAD(p_key), GRN_BULK_VSIZE(p_key));
+ if (p_key == &key) {
+ GRN_OBJ_FIN(ctx, &key);
+ }
} else if (GRN_TEXT_LEN(VAR(2))) {
const char *end;
grn_id id = grn_atoui(GRN_TEXT_VALUE(VAR(2)),
Modified: test/unit/core/test-command-delete.c (+19 -0)
===================================================================
--- test/unit/core/test-command-delete.c 2010-08-26 09:14:38 +0000 (088f64f)
+++ test/unit/core/test-command-delete.c 2010-08-26 15:14:38 +0000 (7f71aa8)
@@ -26,6 +26,7 @@
void test_by_id(void);
void test_by_key(void);
void test_referenced_record(void);
+void test_uint64(void);
static gchar *tmp_directory;
@@ -142,3 +143,21 @@ test_referenced_record(void)
send_command("select Users "
"--output_columns _key"));
}
+
+void
+test_uint64(void)
+{
+ assert_send_command("table_create Students TABLE_HASH_KEY UInt64");
+ assert_send_command("load --table Students --columns '_key'\n"
+ "[\n"
+ " [29],\n"
+ " [2929]\n"
+ "]");
+ assert_send_command("delete Students 2929");
+ cut_assert_equal_string("[[[1],"
+ "[[\"_key\",\"UInt64\"]],"
+ "[29]]]",
+ send_command("select Students "
+ "--output_columns _key"));
+}
+