[Groonga-mysql-commit] mroonga/mroonga [master] added data type checking for virtual columns (_id and _score)

Back to archive index

null+****@clear***** null+****@clear*****
2010年 11月 10日 (水) 18:11:30 JST


Tetsuro IKEDA	2010-11-10 09:11:30 +0000 (Wed, 10 Nov 2010)

  New Revision: 4c9e61b3a322fa32c18e68513b0fb59f4a9bedfe

  Log:
    added data type checking for virtual columns (_id and _score)

  Modified files:
    ha_mroonga.cc
    mrnsys.h
    test/sql/r/create_table.result
    test/sql/t/create_table.test

  Modified: ha_mroonga.cc (+35 -3)
===================================================================
--- ha_mroonga.cc    2010-11-10 07:29:25 +0000 (7e7ea32)
+++ ha_mroonga.cc    2010-11-10 09:11:30 +0000 (bb19390)
@@ -690,7 +690,41 @@ ulong ha_mroonga::index_flags(uint idx, uint part, bool all_parts) const
 int ha_mroonga::create(const char *name, TABLE *table, HA_CREATE_INFO *info)
 {
   DBUG_ENTER("ha_mroonga::create");
-  /* First, we must check if database is alreadly opened, created */
+  /* checking data type of virtual columns */
+  int i;
+  uint n_columns = table->s->fields;
+  for (i = 0; i < n_columns; i++) {
+    Field *field = table->s->field[i];
+    const char *col_name = field->field_name;
+    int col_name_size = strlen(col_name);
+    if (strncmp(MRN_ID_COL_NAME, col_name, col_name_size) == 0) {
+      switch (field->type()) {
+      case (MYSQL_TYPE_TINY) :
+      case (MYSQL_TYPE_SHORT) :
+      case (MYSQL_TYPE_INT24) :
+      case (MYSQL_TYPE_LONG) :
+      case (MYSQL_TYPE_LONGLONG) :
+        break;
+      default:
+        GRN_LOG(ctx, GRN_LOG_ERROR, "_id must be numeric data type");
+        my_message(ER_CANT_CREATE_TABLE, "_id must be numeric data type", MYF(0));
+        DBUG_RETURN(ER_CANT_CREATE_TABLE);
+      }        
+    }
+    if (strncmp(MRN_SCORE_COL_NAME, col_name, col_name_size) == 0) {
+      switch (field->type()) {
+      case (MYSQL_TYPE_FLOAT) :
+      case (MYSQL_TYPE_DOUBLE) :
+        break;
+      default:
+        GRN_LOG(ctx, GRN_LOG_ERROR, "_score must be float or double");
+        my_message(ER_CANT_CREATE_TABLE, "_score must be float or double", MYF(0));
+        DBUG_RETURN(ER_CANT_CREATE_TABLE);
+      }        
+    }
+  }
+
+  /* before creating table, we must check if database is alreadly opened, created */
   grn_obj *db_obj;
   char db_name[MRN_MAX_PATH_SIZE];
   char db_path[MRN_MAX_PATH_SIZE];
@@ -774,8 +808,6 @@ int ha_mroonga::create(const char *name, TABLE *table, HA_CREATE_INFO *info)
   }
 
   /* create columns */
-  int i;
-  uint n_columns = table->s->fields;
   for (i = 0; i < n_columns; i++) {
     grn_obj *col_obj, *col_type;
     Field *field = table->s->field[i];

  Modified: mrnsys.h (+2 -0)
===================================================================
--- mrnsys.h    2010-11-10 07:29:25 +0000 (937d2ce)
+++ mrnsys.h    2010-11-10 09:11:30 +0000 (d263ba0)
@@ -30,6 +30,8 @@
 #define MRN_LEX_SUFFIX "_lex"
 #define MRN_HASH_SUFFIX "_hash"
 #define MRN_PAT_SUFFIX "_pat"
+#define MRN_ID_COL_NAME "_id"
+#define MRN_SCORE_COL_NAME "_score"
 
 /* functions */
 int mrn_hash_put(grn_ctx *ctx, grn_hash *hash, const char *key, void *value);

  Modified: test/sql/r/create_table.result (+4 -0)
===================================================================
--- test/sql/r/create_table.result    2010-11-10 07:29:25 +0000 (ee613d2)
+++ test/sql/r/create_table.result    2010-11-10 09:11:30 +0000 (ec2484d)
@@ -150,4 +150,8 @@ c1	set('A','B','AB','O')	YES		NULL
 drop table t1;
 create table `_aaa` (c1 int) engine = groonga;
 ERROR HY000: name can't start with '_' and 0-9, and contains only 0-9, A-Z, a-z, or _
+create table t1 (c1 int, `_id` text) engine = groonga;
+ERROR HY000: _id must be numeric data type
+create table t1 (c1 int, `_score` int) engine = groonga;
+ERROR HY000: _score must be float or double
 uninstall plugin groonga;

  Modified: test/sql/t/create_table.test (+6 -0)
===================================================================
--- test/sql/t/create_table.test    2010-11-10 07:29:25 +0000 (39bdbaf)
+++ test/sql/t/create_table.test    2010-11-10 09:11:30 +0000 (0123dd6)
@@ -119,6 +119,12 @@ drop table t1;
 --error 1005
 create table `_aaa` (c1 int) engine = groonga;
 
+--error 1005
+create table t1 (c1 int, `_id` text) engine = groonga;
+
+--error 1005
+create table t1 (c1 int, `_score` int) engine = groonga;
+
 --disable_warnings
 uninstall plugin groonga;
 --enable_warnings




Groonga-mysql-commit メーリングリストの案内
Back to archive index