X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Fzebraapi.c;h=436240902d877692ee60f94dc16dfa43d4e16d37;hb=8435c4aa3528b121b17304862a883bc322f75576;hp=74fa36c048f717e3472efd10c583e05695bf0779;hpb=eb8857cfa2ceaa2635f14888b95d6f71b8def045;p=idzebra-moved-to-github.git diff --git a/index/zebraapi.c b/index/zebraapi.c index 74fa36c..4362409 100644 --- a/index/zebraapi.c +++ b/index/zebraapi.c @@ -1,4 +1,4 @@ -/* $Id: zebraapi.c,v 1.90 2003-03-05 00:08:04 adam Exp $ +/* $Id: zebraapi.c,v 1.98 2003-04-24 19:46:59 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003 Index Data Aps @@ -241,6 +241,7 @@ struct zebra_register *zebra_register_open (ZebraService zs, const char *name, zebraRankInstall (reg, rank1_class); zebraRankInstall (reg, rankzv_class); + zebraRankInstall (reg, rankliv_class); recordCompression = res_get_def (res, "recordCompression", "none"); if (!strcmp (recordCompression, "none")) @@ -753,6 +754,9 @@ void zebra_search_rpn (ZebraHandle zh, ODR decode, ODR stream, if (zebra_begin_read (zh)) return; + + zebra_livcode_transform(zh, query); + resultSetAddRPN (zh, decode, stream, query, zh->num_basenames, zh->basenames, setname); @@ -846,7 +850,7 @@ void zebra_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, } rpn_scan (zh, stream, zapt, attributeset, zh->num_basenames, zh->basenames, position, - num_entries, entries, is_partial); + num_entries, entries, is_partial, 0, 0); zebra_end_read (zh); } @@ -1124,6 +1128,12 @@ void zebra_end_read (ZebraHandle zh) int zebra_begin_trans (ZebraHandle zh, int rw) { + if (!zh->res) + { + zh->errCode = 2; + zh->errString = "zebra_begin_trans: no database selected"; + return -1; + } ASSERTZHRES; assert (zh->res); if (rw) @@ -1139,7 +1149,7 @@ int zebra_begin_trans (ZebraHandle zh, int rw) if (zh->trans_no != 1) { zh->errCode = 2; - zh->errString = "write trans not allowed within read trans"; + zh->errString = "zebra_begin_trans: write trans not allowed within read trans"; return -1; } zh->trans_w_no = zh->trans_no; @@ -1210,8 +1220,8 @@ int zebra_begin_trans (ZebraHandle zh, int rw) zh->reg = zebra_register_open (zh->service, zh->reg_name, 1, rval ? 1 : 0, zh->res, zh->path_reg); - - zh->reg->seqno = seqno; + if (zh->reg) + zh->reg->seqno = seqno; } else { @@ -1284,12 +1294,13 @@ int zebra_begin_trans (ZebraHandle zh, int rw) return 0; } -void zebra_end_trans (ZebraHandle zh) { - ZebraTransactionStatus dummy; - zebra_end_transaction(zh, &dummy); +int zebra_end_trans (ZebraHandle zh) +{ + ZebraTransactionStatus dummy; + return zebra_end_transaction(zh, &dummy); } -void zebra_end_transaction (ZebraHandle zh, ZebraTransactionStatus *status) +int zebra_end_transaction (ZebraHandle zh, ZebraTransactionStatus *status) { char val; int seqno; @@ -1304,11 +1315,17 @@ void zebra_end_transaction (ZebraHandle zh, ZebraTransactionStatus *status) status->utime = 0; status->stime = 0; + if (!zh->res || !zh->reg) + { + zh->errCode = 2; + zh->errString = "zebra_end_trans: no open transaction"; + return -1; + } if (zh->trans_no != zh->trans_w_no) { zh->trans_no--; if (zh->trans_no != 0) - return; + return 0; /* release read lock */ @@ -1364,6 +1381,7 @@ void zebra_end_transaction (ZebraHandle zh, ZebraTransactionStatus *status) status->utime = (long) (zh->tms2.tms_utime - zh->tms1.tms_utime); status->stime = (long) (zh->tms2.tms_stime - zh->tms1.tms_stime); #endif + return 0; } void zebra_repository_update (ZebraHandle zh) @@ -1389,7 +1407,7 @@ void zebra_repository_show (ZebraHandle zh) repositoryShow (zh); } -int zebra_commit (ZebraHandle zh) +static int zebra_commit_ex (ZebraHandle zh, int clean_only) { int seqno; char val; @@ -1422,13 +1440,18 @@ int zebra_commit (ZebraHandle zh) bf_cache (bfs, rval); if (bf_commitExists (bfs)) { - zebra_set_state (zh, 'c', seqno); - - logf (LOG_LOG, "commit start"); - bf_commitExec (bfs); + if (clean_only) + zebra_set_state (zh, 'd', seqno); + else + { + zebra_set_state (zh, 'c', seqno); + + logf (LOG_LOG, "commit start"); + bf_commitExec (bfs); #ifndef WIN32 - sync (); + sync (); #endif + } logf (LOG_LOG, "commit clean"); bf_commitClean (bfs, rval); seqno++; @@ -1445,6 +1468,16 @@ int zebra_commit (ZebraHandle zh) return 0; } +int zebra_clean (ZebraHandle zh) +{ + return zebra_commit_ex(zh, 1); +} + +int zebra_commit (ZebraHandle zh) +{ + return zebra_commit_ex(zh, 0); +} + int zebra_init (ZebraHandle zh) { const char *rval; @@ -1489,12 +1522,10 @@ int zebra_compact (ZebraHandle zh) int zebra_record_insert (ZebraHandle zh, const char *buf, int len) { int sysno = 0; - int olderr; ASSERTZH; zh->errCode=0; - zebra_begin_trans (zh, 1); - if (zh->errCode) - return 0; /* bad sysno */ + if (zebra_begin_trans (zh, 1)) + return 0; extract_rec_in_mem (zh, "grs.sgml", buf, len, "Default", /* database */ @@ -1504,10 +1535,8 @@ int zebra_record_insert (ZebraHandle zh, const char *buf, int len) 1 /* store_keys */, 1 /* store_data */, 0 /* match criteria */); - olderr=zh->errCode; - zebra_end_trans (zh); - if (olderr) - zh->errCode=olderr; + if (zebra_end_trans (zh)) + return 0; return sysno; } @@ -1571,7 +1600,7 @@ void zebra_set_resource(ZebraHandle zh, const char *name, const char *value) } const char *zebra_get_resource(ZebraHandle zh, - const char *name, const char *defaultvalue) + const char *name, const char *defaultvalue) { ASSERTZH; zh->errCode=0; @@ -1776,11 +1805,38 @@ void api_records_retrieve (ZebraHandle zh, ODR stream, If not, and a record is provided, then sysno is got from there */ +int zebra_insert_record (ZebraHandle zh, + struct recordGroup *rGroup, + const char *recordType, + int sysno, const char *match, const char *fname, + const char *buf, int buf_size, + int force_update) /* This one is ignored */ + +{ + int res; + + if (buf_size < 1) buf_size = strlen(buf); + + zebra_begin_trans(zh, 1); + res=bufferExtractRecord (zh, buf, buf_size, rGroup, + 0, /* delete_flag */ + 0, /* test_mode */ + recordType, + &sysno, + match, fname, + force_update, + 0); /* allow_update */ + zebra_end_trans(zh); + if (res < 0) return (res); + return sysno; +} + int zebra_update_record (ZebraHandle zh, struct recordGroup *rGroup, const char *recordType, int sysno, const char *match, const char *fname, - const char *buf, int buf_size) + const char *buf, int buf_size, + int force_update) { int res; @@ -1789,20 +1845,25 @@ int zebra_update_record (ZebraHandle zh, zebra_begin_trans(zh, 1); res=bufferExtractRecord (zh, buf, buf_size, rGroup, - 0, // delete_flag - 0, // test_mode, + 0, /* delete_flag */ + 0, /* test_mode */ recordType, &sysno, - match, fname); + match, fname, + force_update, + 1); /* allow_update */ zebra_end_trans(zh); return sysno; } + + int zebra_delete_record (ZebraHandle zh, struct recordGroup *rGroup, const char *recordType, int sysno, const char *match, const char *fname, - const char *buf, int buf_size) + const char *buf, int buf_size, + int force_update) { int res; @@ -1810,11 +1871,13 @@ int zebra_delete_record (ZebraHandle zh, zebra_begin_trans(zh, 1); res=bufferExtractRecord (zh, buf, buf_size, rGroup, - 1, // delete_flag - 0, // test_mode, + 1, /* delete_flag */ + 0, /* test_mode */ recordType, &sysno, - match,fname); + match,fname, + force_update, + 1); /* allow_update */ zebra_end_trans(zh); return sysno; }