-/* $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
*/
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);
-/* $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
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])
{
-/* $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.
" 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"
{
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);
{
zebra_register_statistics (zh,0);
}
- else if (!strcmp (arg, "dump") || !strcmp (arg, "dumpdict"))
+ else if (!strcmp (arg, "dumpdict"))
{
zebra_register_statistics (zh,1);
}
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;
}
-/* $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
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)
{
- ZebraService zs;
ASSERTZH;
- yaz_log(LOG_API,"zebra_admin_create");
+ yaz_log(LOG_API,"zebra_create_database");
zh->errCode=0;
if (zebra_select_database (zh, database))
if (zebra_begin_trans (zh, 1))
return -1;
- zs = zh->service;
/* announce database */
if (zebraExplain_newDatabase (zh->reg->zei, database, 0
/* explainDatabase */))
-/* 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>
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;
"Selects a database",
cmd_select_database},
{ "create_database", "basename",
- "Creates a database",
+ "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},
-/* $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.
02111-1307, USA.
*/
-
-
#include <stdlib.h>
#include <assert.h>
#include <string.h>
}
}
+/* 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,
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;
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)
{
-/* $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
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;