null+****@clear*****
null+****@clear*****
2011年 11月 25日 (金) 13:59:31 JST
Kouhei Sutou 2011-11-25 04:59:31 +0000 (Fri, 25 Nov 2011)
New Revision: 7b6cdaebc61a88891477c5334a341cb03ac2a672
Log:
[rename] support renaming table that has no column.
Modified files:
lib/db.c
test/unit/core/test-rename.c
Modified: lib/db.c (+18 -19)
===================================================================
--- lib/db.c 2011-11-25 04:47:20 +0000 (bdf0e16)
+++ lib/db.c 2011-11-25 04:59:31 +0000 (ccc38c3)
@@ -6198,28 +6198,27 @@ grn_table_rename(grn_ctx *ctx, grn_obj *table, const char *name, unsigned name_s
grn_hash *cols;
if ((cols = grn_hash_create(ctx, NULL, sizeof(grn_id), 0,
GRN_OBJ_TABLE_HASH_KEY|GRN_HASH_TINY))) {
- if (grn_table_columns(ctx, table, "", 0, (grn_obj *)cols)) {
- if (!(rc = grn_obj_rename(ctx, table, name, name_size))) {
- grn_id *key;
- char fullname[GRN_PAT_MAX_KEY_SIZE];
- memcpy(fullname, name, name_size);
- fullname[name_size] = GRN_DB_DELIMITER;
- GRN_HASH_EACH(ctx, cols, id, &key, NULL, NULL, {
- grn_obj *col = grn_ctx_at(ctx, *key);
- if (col) {
- int colname_len = grn_column_name(ctx, col, fullname + name_size + 1,
- GRN_PAT_MAX_KEY_SIZE - name_size - 1);
- if (colname_len) {
- if ((rc = grn_obj_rename(ctx, col, fullname,
- name_size + 1 + colname_len))) {
- break;
- }
+ grn_table_columns(ctx, table, "", 0, (grn_obj *)cols);
+ if (!(rc = grn_obj_rename(ctx, table, name, name_size))) {
+ grn_id *key;
+ char fullname[GRN_PAT_MAX_KEY_SIZE];
+ memcpy(fullname, name, name_size);
+ fullname[name_size] = GRN_DB_DELIMITER;
+ GRN_HASH_EACH(ctx, cols, id, &key, NULL, NULL, {
+ grn_obj *col = grn_ctx_at(ctx, *key);
+ if (col) {
+ int colname_len = grn_column_name(ctx, col, fullname + name_size + 1,
+ GRN_PAT_MAX_KEY_SIZE - name_size - 1);
+ if (colname_len) {
+ if ((rc = grn_obj_rename(ctx, col, fullname,
+ name_size + 1 + colname_len))) {
+ break;
}
}
- });
- }
- grn_hash_close(ctx, cols);
+ }
+ });
}
+ grn_hash_close(ctx, cols);
}
}
GRN_API_RETURN(rc);
Modified: test/unit/core/test-rename.c (+34 -0)
===================================================================
--- test/unit/core/test-rename.c 2011-11-25 04:47:20 +0000 (40a3831)
+++ test/unit/core/test-rename.c 2011-11-25 04:59:31 +0000 (be693d8)
@@ -23,6 +23,7 @@
#include "../lib/grn-assertions.h"
void test_table(void);
+void test_table_with_no_column(void);
void test_column(void);
static gchar *tmp_directory;
@@ -121,6 +122,39 @@ test_table(void)
}
void
+test_table_with_no_column(void)
+{
+ const gchar *actual;
+
+ assert_send_commands("table_create Sites TABLE_PAT_KEY ShortText\n"
+ "load --table Sites\n"
+ "[\n"
+ "[\"_key\"],\n"
+ "[\"groonga.org\"],\n"
+ "[\"razil.jp\"]\n"
+ "]");
+ actual = send_command("select Sites");
+ cut_assert_equal_string("[[[2],"
+ "[[\"_id\",\"UInt32\"],"
+ "[\"_key\",\"ShortText\"]],"
+ "[1,\"groonga.org\"],"
+ "[2,\"razil.jp\"]]]",
+ actual);
+
+ table = grn_ctx_get(context, "Sites", strlen("Sites"));
+ grn_test_assert(grn_table_rename(context, table, "URLs", strlen("URLs")));
+ grn_test_assert_context(context);
+
+ actual = send_command("select URLs");
+ cut_assert_equal_string("[[[2],"
+ "[[\"_id\",\"UInt32\"],"
+ "[\"_key\",\"ShortText\"]],"
+ "[1,\"groonga.org\"],"
+ "[2,\"razil.jp\"]]]",
+ actual);
+}
+
+void
test_column(void)
{
const gchar *actual;