X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Fzebraapi.c;h=32b47935dd2e63f8c11172605e158b043e4fb647;hb=3c32ec08b365ba1cbfa705d7cbefca5b7b4afe28;hp=d419085e21b8e5653ab69d0650d12c8b90d78423;hpb=593927cb1897c1e3163c284448eff7fee6ddad51;p=idzebra-moved-to-github.git diff --git a/index/zebraapi.c b/index/zebraapi.c index d419085..32b4793 100644 --- a/index/zebraapi.c +++ b/index/zebraapi.c @@ -1,4 +1,4 @@ -/* $Id: zebraapi.c,v 1.192 2005-10-28 07:25:30 adam Exp $ +/* $Id: zebraapi.c,v 1.198 2005-12-09 10:56:59 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -326,18 +326,13 @@ struct zebra_register *zebra_register_open(ZebraService zs, const char *name, reg->key_buf = 0; -#if NEW_REC_KEYS reg->keys = zebra_rec_keys_open(); -#else - reg->keys.buf_max = 0; - reg->keys.buf = 0; - reg->keys.codec_handle = iscz1_start(); -#endif +#if NATTR + reg->sortKeys = zebra_rec_keys_open(); +#else reg->sortKeys.buf = 0; reg->sortKeys.buf_max = 0; -#if NATTR - reg->sortKeys.codec_handle = iscz1_start(); #endif reg->records = 0; @@ -500,17 +495,11 @@ static void zebra_register_close (ZebraService zs, struct zebra_register *reg) bfs_destroy (reg->bfs); data1_destroy (reg->dh); - xfree(reg->sortKeys.buf); -#if NEW_REC_KEYS zebra_rec_keys_close(reg->keys); -#else - xfree(reg->keys.buf); - if (reg->keys.codec_handle) - iscz1_stop(reg->keys.codec_handle); #if NATTR - if (reg->sortKeys.codec_handle) - iscz1_stop(reg->sortKeys.codec_handle); -#endif + zebra_rec_keys_close(reg->sortKeys); +#else + xfree(reg->sortKeys.buf); #endif xfree(reg->key_buf); @@ -1110,7 +1099,7 @@ ZEBRA_RES zebra_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, assert(is_partial); assert(entries); yaz_log(log_level, "zebra_scan"); - zebra_clearError(zh); + if (zebra_begin_read (zh) == ZEBRA_FAIL) { *entries = 0; @@ -1150,7 +1139,7 @@ ZEBRA_RES zebra_sort (ZebraHandle zh, ODR stream, assert(sort_sequence); assert(sort_status); yaz_log(log_level, "zebra_sort"); - zebra_clearError(zh); + if (zebra_begin_read(zh) == ZEBRA_FAIL) return ZEBRA_FAIL; res = resultSetSort(zh, stream->mem, num_input_setnames, input_setnames, @@ -1335,7 +1324,11 @@ ZEBRA_RES zebra_admin_exchange_record (ZebraHandle zh, zebra_clearError(zh); if (!recid_buf || recid_len <= 0 || recid_len >= sizeof(recid_z)) + { + zebra_setError(zh, YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED, + "no record ID or empty record ID"); return ZEBRA_FAIL; + } memcpy (recid_z, recid_buf, recid_len); recid_z[recid_len] = 0; @@ -1348,8 +1341,10 @@ ZEBRA_RES zebra_admin_exchange_record (ZebraHandle zh, { if (action == 1) /* fail if insert */ { - zebra_end_trans(zh); - return ZEBRA_FAIL; + zebra_end_trans(zh); + zebra_setError(zh, YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED, + "Cannot insert record: already exist"); + return ZEBRA_FAIL; } memcpy (&sysno, rinfo+1, sizeof(sysno)); @@ -1359,6 +1354,8 @@ ZEBRA_RES zebra_admin_exchange_record (ZebraHandle zh, if (action == 2 || action == 3) /* fail if delete or update */ { zebra_end_trans(zh); + zebra_setError(zh, YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED, + "Cannot delete/update record: does not exist"); return ZEBRA_FAIL; } action = 1; /* make it an insert (if it's an update).. */ @@ -1370,9 +1367,14 @@ ZEBRA_RES zebra_admin_exchange_record (ZebraHandle zh, &sysno, 0, /* match */ 0, /* fname */ - 0, /* force update */ + 0, /* force update */ 1 /* allow update */ ); + if (res == ZEBRA_FAIL) + { + zebra_setError(zh, YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED, + "Unable to parse record"); + } if (action == 1) { dict_insert (zh->reg->matchDict, recid_z, sizeof(sysno), &sysno); @@ -1419,7 +1421,6 @@ ZEBRA_RES zebra_drop_database(ZebraHandle zh, const char *db) ZEBRA_RES ret = ZEBRA_OK; ASSERTZH; yaz_log(log_level, "zebra_drop_database %s", db); - zebra_clearError(zh); if (zebra_select_database (zh, db) == ZEBRA_FAIL) return ZEBRA_FAIL; @@ -1435,6 +1436,8 @@ ZEBRA_RES zebra_drop_database(ZebraHandle zh, const char *db) else { yaz_log(YLOG_WARN, "drop database only supported for isam:b"); + zebra_setError(zh, YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED, + "drop database only supported for isam:b"); ret = ZEBRA_FAIL; } zebra_end_trans (zh); @@ -1446,7 +1449,6 @@ ZEBRA_RES zebra_create_database (ZebraHandle zh, const char *db) ASSERTZH; yaz_log(log_level, "zebra_create_database %s", db); assert(db); - zebra_clearError(zh); if (zebra_select_database (zh, db) == ZEBRA_FAIL) return ZEBRA_FAIL; @@ -1473,7 +1475,7 @@ int zebra_string_norm (ZebraHandle zh, unsigned reg_id, assert(input_str); assert(output_str); yaz_log(log_level, "zebra_string_norm "); - zebra_clearError(zh); + if (!zh->reg->zebra_maps) return -1; wrbuf = zebra_replace(zh->reg->zebra_maps, reg_id, "", @@ -1496,7 +1498,6 @@ static void zebra_set_state (ZebraHandle zh, int val, int seqno) FILE *f; ASSERTZH; yaz_log(log_level, "zebra_set_state v=%d seq=%d", val, seqno); - zebra_clearError(zh); sprintf (state_fname, "state.%s.LCK", zh->reg_name); fname = zebra_mk_fname (res_get(zh->res, "lockDir"), state_fname); @@ -1516,7 +1517,7 @@ static void zebra_get_state (ZebraHandle zh, char *val, int *seqno) ASSERTZH; yaz_log(log_level, "zebra_get_state "); - zebra_clearError(zh); + sprintf (state_fname, "state.%s.LCK", zh->reg_name); fname = zebra_mk_fname (res_get(zh->res, "lockDir"), state_fname); f = fopen (fname, "r"); @@ -1622,8 +1623,6 @@ ZEBRA_RES zebra_begin_trans(ZebraHandle zh, int rw) } zh->trans_w_no = zh->trans_no; - zebra_clearError(zh); - zh->records_inserted = 0; zh->records_updated = 0; zh->records_deleted = 0; @@ -1717,7 +1716,6 @@ ZEBRA_RES zebra_begin_trans(ZebraHandle zh, int rw) zebra_flush_reg (zh); return ZEBRA_OK; } - zebra_clearError(zh); #if HAVE_SYS_TIMES_H times (&zh->tms1); #endif @@ -2155,8 +2153,7 @@ NOTE: Now returns 0 at success and updates sysno, which is an int* int zebra_add_record(ZebraHandle zh, const char *buf, int buf_size) { - SYSNO sysno = 0; - return zebra_update_record(zh, 0, &sysno, 0, 0, buf, buf_size, 0); + return zebra_update_record(zh, 0, 0 /* sysno */, 0, 0, buf, buf_size, 0); } ZEBRA_RES zebra_insert_record (ZebraHandle zh, @@ -2197,10 +2194,11 @@ ZEBRA_RES zebra_update_record (ZebraHandle zh, { ZEBRA_RES res; ASSERTZH; - assert(sysno); assert(buf); - yaz_log(log_level, "zebra_update_record sysno=" ZINT_FORMAT, *sysno); + yaz_log(log_level, "zebra_update_record"); + if (sysno) + yaz_log(log_level, " sysno=" ZINT_FORMAT, *sysno); if (buf_size < 1) buf_size = strlen(buf);