[Groonga-mysql-commit] mroonga/mroonga at f33199c [master] Support mroonga_command() without the current database

Back to archive index

Kouhei Sutou null+****@clear*****
Sat May 18 18:41:18 JST 2013


Kouhei Sutou	2013-05-18 18:41:18 +0900 (Sat, 18 May 2013)

  New Revision: f33199c9ff9f2e0bdae1bcebc479b02c15e75fb4
  https://github.com/mroonga/mroonga/commit/f33199c9ff9f2e0bdae1bcebc479b02c15e75fb4

  Message:
    Support mroonga_command() without the current database
    
    https://gist.github.com/y-ken/eb49eaad879f47b27cec
    
    Reported by Y.Kentaro. Thanks!!!

  Modified files:
    ha_mroonga.cpp

  Modified: ha_mroonga.cpp (+19 -6)
===================================================================
--- ha_mroonga.cpp    2013-05-16 23:41:10 +0900 (8508cfe)
+++ ha_mroonga.cpp    2013-05-18 18:41:18 +0900 (dfc9930)
@@ -992,9 +992,6 @@ MRN_API my_bool mroonga_command_init(UDF_INIT *initid, UDF_ARGS *args,
                                      char *message)
 {
   CommandInfo *info = NULL;
-  THD *thd = current_thd;
-  // TODO: check thd->db
-  mrn::PathMapper mapper(thd->db, mrn_database_path_prefix);
 
   initid->ptr = NULL;
   if (args->arg_count != 1) {
@@ -1019,9 +1016,25 @@ MRN_API my_bool mroonga_command_init(UDF_INIT *initid, UDF_ARGS *args,
   }
 
   grn_ctx_init(&(info->ctx), 0);
-  // TODO: use cached opened database.
-  grn_db_open(&(info->ctx), mapper.db_path());
-  // TODO: check ctx->rc.
+  {
+    const char *current_db_path = current_thd->db;
+    const char *action;
+    if (current_db_path) {
+      action = "open database";
+      mrn::PathMapper mapper(current_db_path, mrn_database_path_prefix);
+      grn_db_open(&(info->ctx), mapper.db_path());
+    } else {
+      action = "create anonymous database";
+      grn_db_create(&(info->ctx), NULL, NULL);
+    }
+    if (info->ctx.rc != GRN_SUCCESS) {
+      sprintf(message,
+              "mroonga_command(): failed to %s: %s",
+              action,
+              info->ctx.errbuf);
+      goto error;
+    }
+  }
 
   initid->ptr = (char *)info;
 
-------------- next part --------------
HTML����������������������������...
Télécharger 



More information about the Groonga-mysql-commit mailing list
Back to archive index