From: Adam Dickmeiss Date: Wed, 14 Mar 2007 11:48:31 +0000 (+0000) Subject: Changed record update API . It is now handled by function X-Git-Tag: ZEBRA.2.0.14~33 X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=commitdiff_plain;h=21f90a8618faec6bee8d125c12088b74db8eb8b9 Changed record update API . It is now handled by function zebra_record_update which does insert/replace/delete/update of records . This function replaces zebra_record_{insert,delete} and zebra_admin_exchange_record. --- diff --git a/NEWS b/NEWS index 4fdd756..8d0404c 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,8 @@ +Changed record update API . It is now handled by function +zebra_record_update which does insert/replace/delete/update of +records . This function replaces zebra_record_{insert,delete} and +zebra_admin_exchange_record. + --- 2.0.12 2007/03/07 Fixed bug with indexing of attributes for rec.grs-class of filters. diff --git a/debian/rules b/debian/rules index 78f3687..6642a89 100755 --- a/debian/rules +++ b/debian/rules @@ -91,7 +91,7 @@ binary-arch: build install dh_fixperms # dh_perl # dh_python - dh_makeshlibs -V 'libidzebra-2.0 (>= 2.0.2)' -X mod- + dh_makeshlibs -V 'libidzebra-2.0 (>= 2.0.13)' -X mod- dh_installdeb dh_shlibdeps -L libidzebra-2.0 -l debian/libidzebra-2.0/usr/lib dh_gencontrol diff --git a/include/idzebra/api.h b/include/idzebra/api.h index f1c7e84..8179b44 100644 --- a/include/idzebra/api.h +++ b/include/idzebra/api.h @@ -1,4 +1,4 @@ -/* $Id: api.h,v 1.46 2007-01-17 15:35:47 adam Exp $ +/* $Id: api.h,v 1.47 2007-03-14 11:48:31 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -36,6 +36,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include +#include YAZ_BEGIN_CDECL @@ -364,13 +365,6 @@ YAZ_EXPORT ZEBRA_RES zebra_admin_import_end(ZebraHandle zh); YAZ_EXPORT -ZEBRA_RES zebra_admin_exchange_record(ZebraHandle zh, - const char *rec_buf, - size_t rec_len, - const char *recid_buf, size_t recid_len, - int action); - -YAZ_EXPORT ZEBRA_RES zebra_begin_trans(ZebraHandle zh, int rw ) ZEBRA_GCC_ATTR((warn_unused_result)); @@ -403,30 +397,35 @@ ZEBRA_RES zebra_repository_delete(ZebraHandle zh, const char *path); YAZ_EXPORT ZEBRA_RES zebra_repository_show(ZebraHandle zh, const char *path); +/** \brief Simple update record + \param zh session handle + \param buf record buffer + \param buf_size record buffer size + + This function is a simple wrapper or zebra_update_record with + action=action_update (insert or replace) . +*/ +YAZ_EXPORT YAZ_EXPORT ZEBRA_RES zebra_add_record(ZebraHandle zh, const char *buf, int buf_size); -YAZ_EXPORT -ZEBRA_RES zebra_insert_record(ZebraHandle zh, - const char *recordType, - zint *sysno, const char *match, - const char *fname, - const char *buf, int buf_size, - int force_update); +/** \brief Updates record + \param zh session handle + \param action (insert,replace,delete or update (replace/insert) + \param recordType filter type (0 indicates default) + \param sysno system id (0 may be passed for no known id) + \param match match criteria (0 may be passed for no known criteria) + \param fname filename to be printed for logging (0 may be passed) + \param buf record buffer + \param buf_size record buffer size +*/ YAZ_EXPORT ZEBRA_RES zebra_update_record(ZebraHandle zh, - const char *recordType, - zint *sysno, const char *match, - const char *fname, - const char *buf, int buf_size, - int force_update); -YAZ_EXPORT -ZEBRA_RES zebra_delete_record(ZebraHandle zh, - const char *recordType, - zint *sysno, const char *match, + enum zebra_recctrl_action_t action, + const char *recordType, + zint *sysno, const char *match, const char *fname, - const char *buf, int buf_size, - int force_update); + const char *buf, int buf_size); YAZ_EXPORT ZEBRA_RES zebra_sort(ZebraHandle zh, ODR stream, diff --git a/include/idzebra/recctrl.h b/include/idzebra/recctrl.h index 8a147ba..ac5f448 100644 --- a/include/idzebra/recctrl.h +++ b/include/idzebra/recctrl.h @@ -1,4 +1,4 @@ -/* $Id: recctrl.h,v 1.31 2007-03-01 10:35:46 adam Exp $ +/* $Id: recctrl.h,v 1.32 2007-03-14 11:48:31 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -85,6 +85,13 @@ struct ZebraRecStream { void (*destroy)(struct ZebraRecStream *s); }; +enum zebra_recctrl_action_t { + action_insert = 1, + action_replace, + action_delete, + action_update /* insert or replace as needed */ +}; + /** \brief record extract for indexing */ struct recExtractCtrl { struct ZebraRecStream *stream; diff --git a/index/extract.c b/index/extract.c index 65a6be9..f6fab5d 100644 --- a/index/extract.c +++ b/index/extract.c @@ -1,4 +1,4 @@ -/* $Id: extract.c,v 1.251 2007-03-13 13:46:11 adam Exp $ +/* $Id: extract.c,v 1.252 2007-03-14 11:48:32 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -321,14 +321,12 @@ static void all_matches_add(struct recExtractCtrl *ctrl) ZEBRA_RES zebra_extract_records_stream(ZebraHandle zh, struct ZebraRecStream *stream, - int delete_flag, + enum zebra_recctrl_action_t action, int test_mode, const char *recordType, zint *sysno, const char *match_criteria, const char *fname, - int force_update, - int allow_update, RecType recType, void *recTypeClientData); @@ -432,14 +430,13 @@ ZEBRA_RES zebra_extract_file(ZebraHandle zh, zint *sysno, const char *fname, zebra_create_stream_fd(streamp, fd, 0); } r = zebra_extract_records_stream(zh, streamp, - deleteFlag, + deleteFlag ? + action_delete : action_update, 0, /* tst_mode */ zh->m_record_type, sysno, 0, /*match_criteria */ fname, - 1, /* force_update */ - 1, /* allow_update */ recType, recTypeClientData); if (streamp) stream.destroy(streamp); @@ -456,14 +453,12 @@ ZEBRA_RES zebra_extract_file(ZebraHandle zh, zint *sysno, const char *fname, ZEBRA_RES zebra_buffer_extract_record(ZebraHandle zh, const char *buf, size_t buf_size, - int delete_flag, + enum zebra_recctrl_action_t action, int test_mode, const char *recordType, zint *sysno, const char *match_criteria, - const char *fname, - int force_update, - int allow_update) + const char *fname) { struct ZebraRecStream stream; ZEBRA_RES res; @@ -500,14 +495,12 @@ ZEBRA_RES zebra_buffer_extract_record(ZebraHandle zh, zebra_create_stream_mem(&stream, buf, buf_size); res = zebra_extract_records_stream(zh, &stream, - delete_flag, + action, test_mode, recordType, sysno, match_criteria, fname, - force_update, - allow_update, recType, clientData); stream.destroy(&stream); return res; @@ -515,14 +508,12 @@ ZEBRA_RES zebra_buffer_extract_record(ZebraHandle zh, ZEBRA_RES zebra_extract_records_stream(ZebraHandle zh, struct ZebraRecStream *stream, - int delete_flag, + enum zebra_recctrl_action_t action, int test_mode, const char *recordType, zint *sysno, const char *match_criteria, const char *fname, - int force_update, - int allow_update, RecType recType, void *recTypeClientData) { @@ -531,14 +522,12 @@ ZEBRA_RES zebra_extract_records_stream(ZebraHandle zh, { int more = 0; res = zebra_extract_record_stream(zh, stream, - delete_flag, + action, test_mode, recordType, sysno, match_criteria, fname, - force_update, - allow_update, recType, recTypeClientData, &more); if (!more) { @@ -556,14 +545,12 @@ ZEBRA_RES zebra_extract_records_stream(ZebraHandle zh, ZEBRA_RES zebra_extract_record_stream(ZebraHandle zh, struct ZebraRecStream *stream, - int delete_flag, + enum zebra_recctrl_action_t action, int test_mode, const char *recordType, zint *sysno, const char *match_criteria, const char *fname, - int force_update, - int allow_update, RecType recType, void *recTypeClientData, int *more) @@ -703,14 +690,14 @@ ZEBRA_RES zebra_extract_record_stream(ZebraHandle zh, if (! *sysno) { /* new record */ - if (delete_flag) + if (action == action_delete) { yaz_log (YLOG_LOG, "delete %s %s " ZINT_FORMAT, recordType, pr_fname, (zint) start_offset); yaz_log (YLOG_WARN, "cannot delete record above (seems new)"); return ZEBRA_FAIL; } - else if (!force_update) + else if (action == action_replace) { yaz_log (YLOG_LOG, "update %s %s " ZINT_FORMAT, recordType, pr_fname, (zint) start_offset); @@ -749,7 +736,7 @@ ZEBRA_RES zebra_extract_record_stream(ZebraHandle zh, /* record already exists */ zebra_rec_keys_t delkeys = zebra_rec_keys_open(); zebra_rec_keys_t sortKeys = zebra_rec_keys_open(); - if (!allow_update) + if (action == action_insert) { yaz_log (YLOG_LOG, "skipped %s %s " ZINT_FORMAT, recordType, pr_fname, (zint) start_offset); @@ -778,7 +765,7 @@ ZEBRA_RES zebra_extract_record_stream(ZebraHandle zh, extract_flush_sort_keys(zh, *sysno, 0, sortKeys); extract_flush_record_keys(zh, *sysno, 0, delkeys, recordAttr->staticrank); - if (delete_flag) + if (action == action_delete) { /* record going to be deleted */ if (zebra_rec_keys_empty(delkeys)) @@ -806,7 +793,7 @@ ZEBRA_RES zebra_extract_record_stream(ZebraHandle zh, return ZEBRA_OK; } else - { + { /* update or special_update */ if (show_progress) yaz_log(YLOG_LOG, "update %s %s " ZINT_FORMAT, recordType, pr_fname, (zint) start_offset); diff --git a/index/index.h b/index/index.h index ed414bc..32ded3e 100644 --- a/index/index.h +++ b/index/index.h @@ -1,4 +1,4 @@ -/* $Id: index.h,v 1.195 2007-02-06 09:34:56 adam Exp $ +/* $Id: index.h,v 1.196 2007-03-14 11:48:32 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -320,25 +320,21 @@ void zebra_index_merge(ZebraHandle zh); ZEBRA_RES zebra_buffer_extract_record(ZebraHandle zh, const char *buf, size_t buf_size, - int delete_flag, + enum zebra_recctrl_action_t action, int test_mode, const char *recordType, zint *sysno, const char *match_criteria, - const char *fname, - int force_update, - int allow_update); + const char *fname); ZEBRA_RES zebra_extract_record_stream(ZebraHandle zh, struct ZebraRecStream *stream, - int delete_flag, + enum zebra_recctrl_action_t action, int test_mode, const char *recordType, zint *sysno, const char *match_criteria, const char *fname, - int force_update, - int allow_update, RecType recType, void *recTypeClientData, int *more); diff --git a/index/zebraapi.c b/index/zebraapi.c index 12bbae0..d3fdab2 100644 --- a/index/zebraapi.c +++ b/index/zebraapi.c @@ -1,4 +1,4 @@ -/* $Id: zebraapi.c,v 1.250 2007-03-13 13:46:11 adam Exp $ +/* $Id: zebraapi.c,v 1.251 2007-03-14 11:48:32 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -1400,13 +1400,14 @@ ZEBRA_RES zebra_admin_import_segment (ZebraHandle zh, Z_Segment *segment) Odr_oct *oct = fragment->u.notExternallyTagged; sysno = 0; - if (zebra_update_record(zh, - 0, /* record Type */ - &sysno, - 0, /* match */ - 0, /* fname */ - (const char *) oct->buf, oct->len, - 0) == ZEBRA_FAIL) + if (zebra_update_record( + zh, + action_update, + 0, /* record Type */ + &sysno, + 0, /* match */ + 0, /* fname */ + (const char *) oct->buf, oct->len) == ZEBRA_FAIL) res = ZEBRA_FAIL; } } @@ -1414,99 +1415,6 @@ ZEBRA_RES zebra_admin_import_segment (ZebraHandle zh, Z_Segment *segment) return res; } -ZEBRA_RES zebra_admin_exchange_record(ZebraHandle zh, - const char *rec_buf, - size_t rec_len, - const char *recid_buf, size_t recid_len, - int action) - /* 1 = insert. Fail it already exists */ - /* 2 = replace. Fail it does not exist */ - /* 3 = delete. Fail if does not exist */ - /* 4 = update. Insert/replace */ -{ - ZEBRA_RES res; - zint sysno = 0; - char *rinfo = 0; - char recid_z[256]; - int db_ord; - ZEBRA_CHECK_HANDLE(zh); - assert(action>0 && action <=4); - assert(rec_buf); - - yaz_log(log_level, "zebra_admin_exchange_record ac=%d", action); - - 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; - - if (zebra_begin_trans(zh, 1) == ZEBRA_FAIL) - return ZEBRA_FAIL; - - db_ord = zebraExplain_get_database_ord(zh->reg->zei); - rinfo = dict_lookup_ord(zh->reg->matchDict, db_ord, recid_z); - if (rinfo) - { - if (action == 1) /* fail if insert */ - { - if (zebra_end_trans(zh) != ZEBRA_OK) - yaz_log(YLOG_WARN, "zebra_end_trans failed"); - zebra_setError(zh, YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED, - "Cannot insert record: already exist"); - return ZEBRA_FAIL; - } - - memcpy (&sysno, rinfo+1, sizeof(sysno)); - } - else - { - if (action == 2 || action == 3) /* fail if delete or update */ - { - if (zebra_end_trans(zh) != ZEBRA_OK) - yaz_log(YLOG_WARN, "zebra_end_trans failed"); - 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).. */ - } - res = zebra_buffer_extract_record(zh, rec_buf, rec_len, - action == 3 ? 1 : 0 /* delete flag */, - 0, /* test mode */ - 0, /* recordType */ - &sysno, - 0, /* match */ - 0, /* fname */ - 1, /* 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_ord(zh->reg->matchDict, db_ord, recid_z, - sizeof(sysno), &sysno); - } - else if (action == 3) - { - dict_delete_ord(zh->reg->matchDict, db_ord, recid_z); - } - if (zebra_end_trans(zh) != ZEBRA_OK) - { - yaz_log(YLOG_WARN, "zebra_end_trans failed"); - res = ZEBRA_FAIL; - } - return res; -} - int delete_w_handle(const char *info, void *handle) { ZebraHandle zh = (ZebraHandle) handle; @@ -2305,48 +2213,20 @@ void zebra_set_shadow_enable (ZebraHandle zh, int value) ZEBRA_RES zebra_add_record(ZebraHandle zh, const char *buf, int buf_size) { - return zebra_update_record(zh, 0, 0 /* sysno */, 0, 0, buf, buf_size, 1); -} - -ZEBRA_RES zebra_insert_record(ZebraHandle zh, - const char *recordType, - zint *sysno, const char *match, - const char *fname, - const char *buf, int buf_size, int force_update) -{ - ZEBRA_RES res; - ASSERTZH; - assert(sysno); - assert(buf); - yaz_log(log_level, "zebra_insert_record sysno=" ZINT_FORMAT, *sysno); - - if (buf_size < 1) - buf_size = strlen(buf); - - if (zebra_begin_trans(zh, 1) == ZEBRA_FAIL) - return ZEBRA_FAIL; - res = zebra_buffer_extract_record(zh, buf, buf_size, - 0, /* delete_flag */ - 0, /* test_mode */ - recordType, - sysno, - match, fname, - 1, - 0); /* allow_update */ - if (zebra_end_trans(zh) != ZEBRA_OK) - { - yaz_log(YLOG_WARN, "zebra_end_trans failed"); - res = ZEBRA_FAIL; - } - return res; + return zebra_update_record(zh, action_update, + 0 /* record type */, + 0 /* sysno */ , + 0 /* match */, + 0 /* fname */, + buf, buf_size); } ZEBRA_RES zebra_update_record(ZebraHandle zh, + enum zebra_recctrl_action_t action, const char *recordType, zint *sysno, const char *match, const char *fname, - const char *buf, int buf_size, - int force_update) + const char *buf, int buf_size) { ZEBRA_RES res; @@ -2358,18 +2238,18 @@ ZEBRA_RES zebra_update_record(ZebraHandle zh, if (sysno) yaz_log(log_level, " sysno=" ZINT_FORMAT, *sysno); - if (buf_size < 1) buf_size = strlen(buf); + if (buf_size < 1) + buf_size = strlen(buf); if (zebra_begin_trans(zh, 1) == ZEBRA_FAIL) return ZEBRA_FAIL; res = zebra_buffer_extract_record(zh, buf, buf_size, - 0, /* delete_flag */ + action, 0, /* test_mode */ recordType, sysno, - match, fname, - force_update, - 1); /* allow_update */ + match, + fname); if (zebra_end_trans(zh) != ZEBRA_OK) { yaz_log(YLOG_WARN, "zebra_end_trans failed"); @@ -2378,42 +2258,6 @@ ZEBRA_RES zebra_update_record(ZebraHandle zh, return res; } -ZEBRA_RES zebra_delete_record(ZebraHandle zh, - const char *recordType, - zint *sysno, const char *match, - const char *fname, - const char *buf, int buf_size, - int force_update) -{ - ZEBRA_RES res; - - ZEBRA_CHECK_HANDLE(zh); - - assert(buf); - yaz_log(log_level, "zebra_delete_record"); - if (sysno) - yaz_log(log_level, " sysno=" ZINT_FORMAT, *sysno); - - if (buf_size < 1) buf_size = strlen(buf); - - if (zebra_begin_trans(zh, 1) == ZEBRA_FAIL) - return ZEBRA_FAIL; - res = zebra_buffer_extract_record(zh, buf, buf_size, - 1, /* delete_flag */ - 0, /* test_mode */ - recordType, - sysno, - match,fname, - force_update, - 1); /* allow_update */ - if (zebra_end_trans(zh) != ZEBRA_OK) - { - yaz_log(YLOG_WARN, "zebra_end_trans failed"); - res = ZEBRA_FAIL; - } - return res; -} - /* --------------------------------------------------------------------------- Searching */ diff --git a/index/zebrash.c b/index/zebrash.c index 73cc7d4..2374646 100644 --- a/index/zebrash.c +++ b/index/zebrash.c @@ -1,4 +1,4 @@ -/* $Id: zebrash.c,v 1.42 2007-01-15 15:10:17 adam Exp $ +/* $Id: zebrash.c,v 1.43 2007-03-14 11:48:32 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -355,14 +355,14 @@ static int cmd_record_insert( char *args[], WRBUF outbuff) int rc; char *rec=restargs(args,1); - rc = zebra_insert_record(zh, + rc = zebra_update_record(zh, + action_insert, 0, /* record type */ &sysno, 0, /* match */ 0, /* fname */ rec, - strlen(rec), - 0); + strlen(rec)); if (0==rc) { wrbuf_printf(outbuff,"ok sysno=" ZINT_FORMAT "\n",sysno); @@ -383,8 +383,12 @@ static int cmd_exchange_record( char *args[], WRBUF outbuff) onecommand("help exchange_record", outbuff, ""); return -90; } - rc=zebra_admin_exchange_record(zh, rec, strlen(rec), - id, strlen(id), atoi(action)); + + rc = zebra_update_record(zh, action_update, 0 /* record_type */, + 0 /* sysno */, + id /* match */, + 0 /* fname */, + rec, strlen(rec)); return rc; } diff --git a/index/zebrasrv.c b/index/zebrasrv.c index 0980f8e..cf3a4db 100644 --- a/index/zebrasrv.c +++ b/index/zebrasrv.c @@ -1,4 +1,4 @@ -/* $Id: zebrasrv.c,v 1.11 2007-03-13 13:46:11 adam Exp $ +/* $Id: zebrasrv.c,v 1.12 2007-03-14 11:48:32 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -652,120 +652,56 @@ int bend_esrequest (void *handle, bend_esrequest_rr *rr) } if (rec->which == Z_External_octet) { - int action = 0; + enum zebra_recctrl_action_t action = action_update; + char recid_str[256]; + const char *match_criteria = 0; + ZEBRA_RES res; if (*toKeep->action == Z_IUOriginPartToKeep_recordInsert) - action = 1; - if (*toKeep->action == + action = action_insert; + else if (*toKeep->action == Z_IUOriginPartToKeep_recordReplace) - action = 2; - if (*toKeep->action == + action = action_replace; + else if (*toKeep->action == Z_IUOriginPartToKeep_recordDelete) - action = 3; - if (*toKeep->action == + action = action_delete; + else if (*toKeep->action == Z_IUOriginPartToKeep_specialUpdate) - action = 4; - - if (!action) + action = action_update; + else { rr->errcode = YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED; rr->errstring = "unsupported ES Update action"; break; } - else if (opaque_recid) + + if (opaque_recid) { - int r = zebra_admin_exchange_record ( - zh, - (const char *) rec->u.octet_aligned->buf, - rec->u.octet_aligned->len, - (const char *) opaque_recid->buf, - opaque_recid->len, - action); - if (r) + size_t l = opaque_recid->len; + if (l >= sizeof(recid_str)) { - zebra_result(zh, &rr->errcode, - &rr->errstring); + rr->errcode = YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED; + rr->errstring = "opaque record ID too large"; break; } - } - else - { - ZEBRA_RES r = ZEBRA_FAIL; - switch(action) { - case 1: - r = zebra_insert_record( - zh, - 0, /* recordType */ - sysno, - 0, /* match */ - 0, /* fname */ - (const char *) rec->u.octet_aligned->buf, - rec->u.octet_aligned->len, - 0); - if (r == ZEBRA_FAIL) - { - rr->errcode = - YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED; - rr->errstring = "insert_record failed"; - } - break; - case 2: - r = zebra_update_record( - zh, - 0, /* recordType */ - sysno, - 0, /* match */ - 0, /* fname */ - (const char *) rec->u.octet_aligned->buf, - rec->u.octet_aligned->len, - 0 /* force_update=0: action is a replace, so abort update if no corresponding record exists */ - ); - if (r == ZEBRA_FAIL) - { - rr->errcode = - YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED; - rr->errstring = "update_record failed"; - } - break; - case 3: - r = zebra_delete_record( - zh, - 0, /* recordType */ - sysno, - 0, /* match */ - 0, /* fname */ - (const char *) rec->u.octet_aligned->buf, - rec->u.octet_aligned->len, - 0); - if (r == ZEBRA_FAIL) - { - rr->errcode = - YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED; - rr->errstring = "delete_record failed"; - } - break; - case 4: - r = zebra_update_record( - zh, - 0, /* recordType */ - sysno, - 0, /* match */ - 0, /* fname */ - (const char *) rec->u.octet_aligned->buf, - rec->u.octet_aligned->len, - 1 /* force_update=1: action is a specialUpdate, so allow replace or insert */ - ); - if (r == ZEBRA_FAIL) - { - rr->errcode = - YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED; - rr->errstring = "update_record failed"; - } - break; - } - } + memcpy(recid_str, opaque_recid->buf, l); + recid_str[l] = '\0'; + match_criteria = recid_str; + } + res = zebra_update_record( + zh, action, + 0, /* recordType */ + sysno, match_criteria, 0, /* fname */ + (const char *) rec->u.octet_aligned->buf, + rec->u.octet_aligned->len); + if (res == ZEBRA_FAIL) + { + rr->errcode = + YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED; + rr->errstring = "update_record failed"; + } } } if (zebra_end_trans (zh) != ZEBRA_OK) diff --git a/test/api/t13.c b/test/api/t13.c index d0d7730..c58b0bc 100644 --- a/test/api/t13.c +++ b/test/api/t13.c @@ -1,4 +1,4 @@ -/* $Id: t13.c,v 1.13 2007-03-13 13:46:11 adam Exp $ +/* $Id: t13.c,v 1.14 2007-03-14 11:48:32 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -97,12 +97,12 @@ static void tst_no_config(void) zebra_set_resource(zh, "profilePath", "${srcdir:-.}/../../tab"); - YAZ_CHECK_EQ(zebra_insert_record(zh /* handle */, + YAZ_CHECK_EQ(zebra_update_record(zh /* handle */, + action_insert, "grs.sgml" /* record type */, &sysno, 0 /* match */, 0 /* fname */, - xml_buf, strlen(xml_buf), - 1 /* force_update */), + xml_buf, strlen(xml_buf)), ZEBRA_OK); zebra_close(zh); diff --git a/test/api/t14.c b/test/api/t14.c index 67382d6..cd43023 100644 --- a/test/api/t14.c +++ b/test/api/t14.c @@ -1,4 +1,4 @@ -/* $Id: t14.c,v 1.6 2007-01-15 15:10:20 adam Exp $ +/* $Id: t14.c,v 1.7 2007-03-14 11:48:32 adam Exp $ Copyright (C) 2004-2007 Index Data ApS @@ -30,16 +30,24 @@ static void create_search_drop(ZebraHandle zh) YAZ_CHECK(zebra_create_database (zh, "Default") == ZEBRA_OK); /* bug #447 */ - YAZ_CHECK(zebra_admin_exchange_record ( - zh, rec, strlen(rec), - opaque_id, strlen(opaque_id), - 1) == ZEBRA_OK); /* insert */ - - YAZ_CHECK(zebra_admin_exchange_record ( - zh, rec, strlen(rec), - opaque_id, strlen(opaque_id), - 4) == ZEBRA_OK); /* update/insert */ - + YAZ_CHECK(zebra_update_record( + zh, action_update, + 0 /* record type */, + 0 /* sysno */, + opaque_id, + 0 /* fname */, + rec, strlen(rec)) + == ZEBRA_OK); /* insert really */ + + YAZ_CHECK(zebra_update_record( + zh, action_update, + 0 /* record type */, + 0 /* sysno */, + opaque_id, + 0 /* fname */, + rec, strlen(rec)) + == ZEBRA_OK); /* replace really */ + YAZ_CHECK(tl_query(zh, "@attr 1=4 some", 1)); zebra_drop_database(zh, "Default");