1 /* $Id: t4.c,v 1.19 2006-03-31 15:58:05 adam Exp $
2 Copyright (C) 1995-2005
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra. If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 /* t4 - insert a small pile of records, search and fetch them */
27 const char *myrec[] = {
29 " <title>My title</title>\n"
33 #define NUMBER_TO_FETCH_MAX 1000
35 static void tst(int argc, char **argv)
38 int number_to_be_inserted = 5;
39 int number_to_fetch = 5;
41 ZebraService zs = tl_start_up(0, argc, argv);
42 ZebraHandle zh = zebra_open(zs, 0);
44 YAZ_CHECK(tl_init_data(zh, myrec));
46 YAZ_CHECK(zebra_begin_trans (zh, 1) == ZEBRA_OK);
48 for (i = 0; i< number_to_be_inserted-1; i++)
49 { /* -1 since already inserted one in init_data */
50 zebra_add_record(zh, myrec[0], strlen(myrec[0]));
52 YAZ_CHECK(zebra_end_trans(zh) == ZEBRA_OK);
57 zs = tl_zebra_start("");
58 zh = zebra_open(zs, 0);
59 YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK);
60 zebra_set_resource(zh, "sortmax", "3"); /* make small sort boundary */
65 ZebraRetrievalRecord retrievalRecord[NUMBER_TO_FETCH_MAX];
68 ODR odr_input = odr_createmem(ODR_DECODE);
69 ODR odr_output = odr_createmem(ODR_DECODE);
70 YAZ_PQF_Parser parser = yaz_pqf_create();
71 Z_RPNQuery *query = yaz_pqf_parse(parser, odr_input, "@attr 1=4 my");
74 sprintf(setname, "s%d", i+1);
75 ret = zebra_search_RPN(zh, odr_input, query, setname, &hits);
78 int code = zebra_errCode(zh);
79 yaz_log(YLOG_WARN, "Unexpected error code=%d", code);
82 if (hits != number_to_be_inserted)
84 yaz_log(YLOG_WARN, "Unexpected hit count " ZINT_FORMAT
85 "(should be %d)", hits, number_to_be_inserted);
89 yaz_pqf_destroy(parser);
91 odr_destroy(odr_input);
93 YAZ_CHECK(zebra_begin_trans(zh, 1) == ZEBRA_OK);
95 for (j = 0; j < number_to_fetch; j++)
96 retrievalRecord[j].position = j+1;
98 ret = zebra_records_retrieve(zh, odr_output, setname, 0,
99 VAL_TEXT_XML, number_to_fetch,
103 int code = zebra_errCode(zh);
104 yaz_log(YLOG_FATAL, "zebra_records_retrieve returned error %d",
109 for (j = 0; j < number_to_fetch; j++)
111 if (!retrievalRecord[j].buf)
113 yaz_log(YLOG_FATAL, "No record buf at position %d", j);
116 if (!retrievalRecord[j].len)
118 yaz_log(YLOG_FATAL, "No record len at position %d", j);
122 odr_destroy(odr_output);
124 YAZ_CHECK(zebra_end_trans(zh) == ZEBRA_OK);
127 YAZ_CHECK(tl_close_down(zh, zs));