Implemented drop database
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 30 Jun 2003 19:37:12 +0000 (19:37 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 30 Jun 2003 19:37:12 +0000 (19:37 +0000)
include/zebraapi.h
index/extract.c
index/main.c
index/zebraapi.c
index/zebrash.c
index/zinfo.c
index/zinfo.h

index d619baf..9818c4c 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: zebraapi.h,v 1.8 2003-06-20 14:21:23 heikki Exp $
+/* $Id: zebraapi.h,v 1.9 2003-06-30 19:37:12 adam Exp $
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003
    Index Data Aps
 
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003
    Index Data Aps
 
@@ -184,7 +184,7 @@ YAZ_EXPORT int zebra_string_norm (ZebraHandle zh, unsigned reg_id,
  */                   
           
 YAZ_EXPORT int zebra_create_database (ZebraHandle zh, const char *db);
  */                   
           
 YAZ_EXPORT int zebra_create_database (ZebraHandle zh, const char *db);
-
+YAZ_EXPORT int zebra_drop_database (ZebraHandle zh, const char *db);
 
 YAZ_EXPORT int zebra_admin_shutdown (ZebraHandle zh);
 YAZ_EXPORT int zebra_admin_start (ZebraHandle zh);
 
 YAZ_EXPORT int zebra_admin_shutdown (ZebraHandle zh);
 YAZ_EXPORT int zebra_admin_start (ZebraHandle zh);
index e325528..5a179b8 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: extract.c,v 1.144 2003-04-15 16:46:18 adam Exp $
+/* $Id: extract.c,v 1.145 2003-06-30 19:37:12 adam Exp $
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003
    Index Data Aps
 
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003
    Index Data Aps
 
@@ -1303,8 +1303,9 @@ int explain_extract (void *handle, Record rec, data1_node *n)
     extractCtrl.zebra_maps = zh->reg->zebra_maps;
     extractCtrl.flagShowRecords = 0;
     extractCtrl.handle = handle;
     extractCtrl.zebra_maps = zh->reg->zebra_maps;
     extractCtrl.flagShowRecords = 0;
     extractCtrl.handle = handle;
-    
-    grs_extract_tree(&extractCtrl, n);
+
+    if (n)
+       grs_extract_tree(&extractCtrl, n);
 
     if (rec->size[recInfo_delKeys])
     {
 
     if (rec->size[recInfo_delKeys])
     {
index cf2546d..11dbfb3 100644 (file)
@@ -1,5 +1,5 @@
-/* $Id: main.c,v 1.104 2003-05-20 21:39:57 adam Exp $
-   Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
+/* $Id: main.c,v 1.105 2003-06-30 19:37:12 adam Exp $
+   Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003
    Index Data Aps
 
 This file is part of the Zebra server.
    Index Data Aps
 
 This file is part of the Zebra server.
@@ -96,6 +96,8 @@ int main (int argc, char **argv)
         " update <dir>  Update index with files below <dir>.\n"
        "               If <dir> is empty filenames are read from stdin.\n"
         " delete <dir>  Delete index with files below <dir>.\n"
         " update <dir>  Update index with files below <dir>.\n"
        "               If <dir> is empty filenames are read from stdin.\n"
         " delete <dir>  Delete index with files below <dir>.\n"
+        " create <db>   Create database <db>\n"
+        " drop <db>     Drop database <db>\n"
         " commit        Commit changes\n"
         " clean         Clean shadow files\n"
         "Options:\n"
         " commit        Commit changes\n"
         " clean         Clean shadow files\n"
         "Options:\n"
@@ -172,6 +174,14 @@ int main (int argc, char **argv)
                {
                     zebra_init (zh);
                }
                {
                     zebra_init (zh);
                }
+               else if (!strcmp(arg, "drop"))
+               {
+                   cmd = 'D';
+               }
+               else if (!strcmp(arg, "create"))
+               {
+                   cmd = 'C';
+               }
                 else if (!strcmp (arg, "commit"))
                 {
                     zebra_commit (zh);
                 else if (!strcmp (arg, "commit"))
                 {
                     zebra_commit (zh);
@@ -184,7 +194,7 @@ int main (int argc, char **argv)
                 {
                     zebra_register_statistics (zh,0);
                 }
                 {
                     zebra_register_statistics (zh,0);
                 }
-                else if (!strcmp (arg, "dump") || !strcmp (arg, "dumpdict"))
+                else if (!strcmp (arg, "dumpdict"))
                 {
                     zebra_register_statistics (zh,1);
                 }
                 {
                     zebra_register_statistics (zh,1);
                 }
@@ -221,6 +231,12 @@ int main (int argc, char **argv)
                     zebra_repository_show (zh);
                     nsections = 0;
                     break;
                     zebra_repository_show (zh);
                     nsections = 0;
                     break;
+               case 'C':
+                   zebra_create_database(zh, rGroupDef.path);
+                   break;
+               case 'D':
+                   zebra_drop_database(zh, rGroupDef.path);
+                   break;
                 default:
                     nsections = 0;
                 }
                 default:
                     nsections = 0;
                 }
index 750c326..31c7a9c 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: zebraapi.c,v 1.108 2003-06-23 14:35:41 heikki Exp $
+/* $Id: zebraapi.c,v 1.109 2003-06-30 19:37:12 adam Exp $
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003
    Index Data Aps
 
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003
    Index Data Aps
 
@@ -1098,11 +1098,59 @@ int zebra_admin_exchange_record (ZebraHandle zh,
     return 0;
 }
 
     return 0;
 }
 
+int delete_w_handle(const char *info, void *handle)
+{
+    ZebraHandle zh = (ZebraHandle) handle;
+    ISAMC_P pos;
+
+    if (*info == sizeof(pos))
+    {
+       memcpy (&pos, info+1, sizeof(pos));
+       isamb_unlink(zh->reg->isamb, pos);
+    }
+    return 0;
+}
+
+static int delete_SU_handle(void *handle, int ord)
+{
+    ZebraHandle zh = (ZebraHandle) handle;
+    char ord_buf[20];
+    int ord_len;
+
+    ord_len = key_SU_encode (ord, ord_buf);
+    ord_buf[ord_len] = '\0';
+
+    assert (zh->reg->isamb);
+    dict_delete_subtree(zh->reg->dict, ord_buf,
+                       zh, delete_w_handle);
+    return 0;
+}
+
+int zebra_drop_database  (ZebraHandle zh, const char *database)
+{
+    ASSERTZH;
+    yaz_log(LOG_API,"zebra_drop_database");
+    zh->errCode = 0;
+
+    if (zebra_select_database (zh, database))
+        return -1;
+    if (zebra_begin_trans (zh, 1))
+        return -1;
+    if (zh->reg->isamb)
+    {
+       zebraExplain_curDatabase (zh->reg->zei, database);
+       
+       zebraExplain_trav_ord(zh->reg->zei, zh, delete_SU_handle);
+       zebraExplain_removeDatabase(zh->reg->zei, zh);
+    }
+    zebra_end_trans (zh);
+    return 0;
+}
+
 int zebra_create_database (ZebraHandle zh, const char *database)
 {
 int zebra_create_database (ZebraHandle zh, const char *database)
 {
-    ZebraService zs;
     ASSERTZH;
     ASSERTZH;
-    yaz_log(LOG_API,"zebra_admin_create");
+    yaz_log(LOG_API,"zebra_create_database");
     zh->errCode=0;
 
     if (zebra_select_database (zh, database))
     zh->errCode=0;
 
     if (zebra_select_database (zh, database))
@@ -1110,7 +1158,6 @@ int zebra_create_database (ZebraHandle zh, const char *database)
     if (zebra_begin_trans (zh, 1))
         return -1;
 
     if (zebra_begin_trans (zh, 1))
         return -1;
 
-    zs = zh->service;
     /* announce database */
     if (zebraExplain_newDatabase (zh->reg->zei, database, 0 
                                   /* explainDatabase */))
     /* announce database */
     if (zebraExplain_newDatabase (zh->reg->zei, database, 0 
                                   /* explainDatabase */))
index f86abad..b4ee5d9 100644 (file)
@@ -1,10 +1,29 @@
-/* zebrash.c - command-line interface to zebra API 
- *  $Id: zebrash.c,v 1.13 2003-06-23 15:38:16 adam Exp $
- *
- * Copyrigth 2003 Index Data Aps
- *
- */
+/* $Id: zebrash.c,v 1.14 2003-06-30 19:37:12 adam Exp $
+   Copyright (C) 2002,2003
+   Index Data Aps
+
+This file is part of the Zebra server.
+
+Zebra is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Zebra; see the file LICENSE.zebra.  If not, write to the
+Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.
+*/
+
+/* 
+   zebrash.c - command-line interface to zebra API
+*/
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h> 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h> 
@@ -295,6 +314,18 @@ static int cmd_create_database( char *args[], char *outbuff)
     return zebra_create_database(zh, db);
 }
 
     return zebra_create_database(zh, db);
 }
 
+static int cmd_drop_database( char *args[], char *outbuff)
+{
+    char *db=args[1];
+    if (!db)
+        db="Default";
+    strcat(outbuff,"Dropping database ");
+    strcat(outbuff,db);
+    strcat(outbuff,"\n");
+       
+    return zebra_drop_database(zh, db);
+}
+
 static int cmd_begin_trans( char *args[], char *outbuff)
 {
     int rw=0;
 static int cmd_begin_trans( char *args[], char *outbuff)
 {
     int rw=0;
@@ -437,8 +468,11 @@ struct cmdstruct cmds[] = {
       "Selects a database",
       cmd_select_database},    
     { "create_database", "basename",
       "Selects a database",
       cmd_select_database},    
     { "create_database", "basename",
-      "Creates a database",
+      "Create database",
       cmd_create_database},
       cmd_create_database},
+    { "drop_database", "basename",
+      "Drop database",
+      cmd_drop_database},
     { "begin_trans", "[rw]",
       "Begins a transaction. rw=1 means write, otherwise read-only",
       cmd_begin_trans},
     { "begin_trans", "[rw]",
       "Begins a transaction. rw=1 means write, otherwise read-only",
       cmd_begin_trans},
index de9be50..67060ef 100644 (file)
@@ -1,5 +1,5 @@
-/* $Id: zinfo.c,v 1.36 2003-01-15 07:26:40 oleg Exp $
-   Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
+/* $Id: zinfo.c,v 1.37 2003-06-30 19:37:12 adam Exp $
+   Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003
    Index Data Aps
 
 This file is part of the Zebra server.
    Index Data Aps
 
 This file is part of the Zebra server.
@@ -20,8 +20,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 02111-1307, USA.
 */
 
 02111-1307, USA.
 */
 
-
-
 #include <stdlib.h>
 #include <assert.h>
 #include <string.h>
 #include <stdlib.h>
 #include <assert.h>
 #include <string.h>
@@ -273,6 +271,52 @@ void zebraExplain_mergeAccessInfo (ZebraExplainInfo zei, data1_node *n,
     }
 }
 
     }
 }
 
+/* Explain structure
+    root record
+      of type targetInfo
+      and has sysno = 1
+
+    databaseList (list of databases)
+*/
+/*
+Example root:
+explain:
+  targetInfo: TargetInfo
+    name: Zebra
+    namedResultSets: 1
+    multipleDbSearch: 1
+    nicknames:
+      name: Zebra
+    commonInfo:
+      dateAdded: 20030630190601
+      dateChanged: 20030630190601
+      languageCode: EN
+    accessinfo:
+      unitSystems:
+        string: ISO
+      attributeSetIds:
+        oid: 1.2.840.10003.3.2
+        oid: 1.2.840.10003.3.5
+        oid: 1.2.840.10003.3.1
+      schemas:
+        oid: 1.2.840.10003.13.1000.81.2
+        oid: 1.2.840.10003.13.2
+    zebraInfo:
+      version: 1.3.12
+      databaseList:
+        database:
+          name: Default
+          id: 50
+          attributeDetailsId: 51
+        database:
+          name: IR-Explain-1
+          id: 52
+          attributeDetailsId: 53
+      ordinalSU: 38
+      runNumber: 1
+nextResultSetPosition = 2
+*/
+
 ZebraExplainInfo zebraExplain_open (
     Records records, data1_handle dh,
     Res res,
 ZebraExplainInfo zebraExplain_open (
     Records records, data1_handle dh,
     Res res,
@@ -598,6 +642,45 @@ static void zebraExplain_readDatabase (ZebraExplainInfo zei,
     rec_rm (&rec);
 }
 
     rec_rm (&rec);
 }
 
+int zebraExplain_removeDatabase(ZebraExplainInfo zei, void *update_handle)
+{
+    struct zebDatabaseInfoB **zdip = &zei->databaseInfo;
+
+    while (*zdip)
+    {
+       if (*zdip == zei->curDatabaseInfo)
+       {
+           struct zebDatabaseInfoB *zdi = *zdip;
+           Record rec;
+
+           zei->dirty = 1;
+           zei->updateHandle = update_handle;
+
+           if (zdi->attributeDetails)
+           {
+               /* remove attribute details keys and delete it */
+               zebAttributeDetails zad = zdi->attributeDetails;
+               
+               rec = rec_get(zei->records, zad->sysno);
+               (*zei->updateFunc)(zei->updateHandle, rec, 0);
+               rec_rm(&rec);
+           }
+           /* remove database record keys and delete it */
+           rec = rec_get (zei->records, zdi->sysno);
+           (*zei->updateFunc)(zei->updateHandle, rec, 0);
+           rec_rm(&rec);
+
+           /* remove from list */
+           *zdip = zdi->next;
+
+           /* current database is IR-Explain-1 */
+           return 0;
+       }
+       zdip = &(*zdip)->next;
+    }
+    return -1;
+}
+
 int zebraExplain_curDatabase (ZebraExplainInfo zei, const char *database)
 {
     struct zebDatabaseInfoB *zdi;
 int zebraExplain_curDatabase (ZebraExplainInfo zei, const char *database)
 {
     struct zebDatabaseInfoB *zdi;
@@ -1227,6 +1310,19 @@ int zebraExplain_lookupSU (ZebraExplainInfo zei, int set, int use)
     return -1;
 }
 
     return -1;
 }
 
+int zebraExplain_trav_ord(ZebraExplainInfo zei, void *handle,
+                         int (*f)(void *handle, int ord))
+{
+    struct zebDatabaseInfoB *zdb = zei->curDatabaseInfo;
+    if (zdb)
+    {
+       struct zebSUInfoB *zsui = zdb->attributeDetails->SUInfo;
+       for ( ;zsui; zsui = zsui->next)
+           (*f)(handle,  zsui->info.ordinal);
+    }
+    return 0;
+}
+                         
 int zebraExplain_lookup_ord (ZebraExplainInfo zei, int ord,
                             const char **db, int *set, int *use)
 {
 int zebraExplain_lookup_ord (ZebraExplainInfo zei, int ord,
                             const char **db, int *set, int *use)
 {
index 2f75d5a..25b9c4f 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: zinfo.h,v 1.15 2002-10-22 12:51:08 adam Exp $
+/* $Id: zinfo.h,v 1.16 2003-06-30 19:37:12 adam Exp $
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
    Index Data Aps
 
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
    Index Data Aps
 
@@ -55,6 +55,11 @@ void zebraExplain_flush (ZebraExplainInfo zei, void *updateHandle);
 int zebraExplain_lookup_ord (ZebraExplainInfo zei, int ord,
                             const char **db, int *set, int *use);
 
 int zebraExplain_lookup_ord (ZebraExplainInfo zei, int ord,
                             const char **db, int *set, int *use);
 
+int zebraExplain_trav_ord(ZebraExplainInfo zei, void *handle,
+                         int (*f)(void *handle, int ord));
+
+int zebraExplain_removeDatabase(ZebraExplainInfo zei, void *updateHandle);
+
 typedef struct {
     int recordSize;
     off_t recordOffset;
 typedef struct {
     int recordSize;
     off_t recordOffset;