-/* $Id: zebraapi.c,v 1.107 2003-06-20 16:27:55 adam Exp $
+/* $Id: zebraapi.c,v 1.114 2003-09-05 10:51:17 adam Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003
Index Data Aps
02111-1307, USA.
*/
-
-
#include <assert.h>
#include <stdio.h>
#ifdef WIN32
return 0;
}
+
+void zebra_pidfname(ZebraService zs, char *path)
+{
+ zebra_lock_prefix (zs->global_res, path);
+ strcat(path, "zebrasrv.pid");
+}
+
static
struct zebra_register *zebra_register_open (ZebraService zs, const char *name,
int rw, int useshadow, Res res,
ZebraRetrievalRecord *recs)
{
ZebraPosSet poset;
- int i, *pos_array;
+ int i, *pos_array, ret = 0;
ASSERTZH;
yaz_log(LOG_API,"zebra_records_retrieve n=%d",num_recs);
zh->errCode=0;
{
zh->errCode = 30;
zh->errString = odr_strdup (stream, setname);
- return 1;
+ return -1;
}
zh->errCode = 0;
if (zebra_begin_read (zh))
- return 1;
+ return -1;
pos_array = (int *) xmalloc (num_recs * sizeof(*pos_array));
for (i = 0; i<num_recs; i++)
logf (LOG_DEBUG, "zebraPosSetCreate error");
zh->errCode = 30;
zh->errString = nmem_strdup (stream->mem, setname);
+ ret = -1;
}
else
{
sprintf (num_str, "%d", pos_array[i]);
zh->errCode = 13;
zh->errString = odr_strdup (stream, num_str);
+ ret = -1;
break;
}
}
}
zebra_end_read (zh);
xfree (pos_array);
- return 0;
+ return ret;
}
int zebra_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
memcpy (recid_z, recid_buf, recid_len);
recid_z[recid_len] = 0;
+ zebra_begin_trans(zh,1);
+
rinfo = dict_lookup (zh->reg->matchDict, recid_z);
if (rinfo)
{
if (action == 1) /* fail if insert */
- return -1;
+ {
+ zebra_end_trans(zh);
+ return -1;
+ }
+
memcpy (&sysno, rinfo+1, sizeof(sysno));
}
else
{
if (action == 2 || action == 3) /* fail if delete or update */
+ {
+ zebra_end_trans(zh);
return -1;
+ }
}
extract_rec_in_mem (zh, "grs.sgml", rec_buf, rec_len, database,
action == 3 ? 1 : 0 /* delete flag */,
{
dict_delete (zh->reg->matchDict, recid_z);
}
+ zebra_end_trans(zh);
+ 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)
+{
+ int ret = 0;
+ 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);
+ }
+ else
+ {
+ yaz_log(LOG_WARN, "drop database only supported for isam:b");
+ ret = -1;
+ }
+ zebra_end_trans (zh);
+ return ret;
+}
+
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 */))
int zebra_begin_trans (ZebraHandle zh, int rw)
{
- yaz_log(LOG_LOG, "zebra_begin_trans rw=%d trans=%d", rw, zh->trans_no);
if (!zh->res)
{
zh->errCode = 2;
odr_destroy(odr);
+ yaz_log(LOG_API,"Hits: %d",hits);
+
if (numhits)
*numhits=hits;
Sort - a simplified interface, with optional read locks.
FIXME - This is a horrible name, will conflict with half the applications
*/
-int zebra_sort_2 (ZebraHandle zh,
- ODR stream,
- const char *sort_spec,
- const char *output_setname,
- const char **input_setnames)
+int zebra_sort_by_specstr (ZebraHandle zh,
+ ODR stream,
+ const char *sort_spec,
+ const char *output_setname,
+ const char **input_setnames)
{
int num_input_setnames = 0;
int sort_status = 0;