Removed a warning
[idzebra-moved-to-github.git] / test / api / t7.c
1 /* $Id: t7.c,v 1.2 2004-10-01 09:13:06 heikki Exp $
2    Copyright (C) 2004
3    Index Data Aps
4
5 This file is part of the Zebra server.
6
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
10 version.
11
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
15 for more details.
16
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
20 02111-1307, USA.
21 */
22
23 #include <yaz/log.h>
24 #include <yaz/pquery.h>
25 #include <yaz/sortspec.h>
26 #include <idzebra/api.h>
27
28 /* read zebra.cfg from env var srcdir if it exists; otherwise current dir */
29 static ZebraService start_service()
30 {
31     char cfg[256];
32     char *srcdir = getenv("srcdir");
33     sprintf(cfg, "%.200s%szebra.cfg", srcdir ? srcdir : "", srcdir ? "/" : "");
34     return zebra_start(cfg);
35 }
36         
37 int main(int argc, char **argv)
38 {
39     ZebraService zs;
40     ZebraHandle zh;
41     const char *myrec =
42         "<gils>\n"
43         "  <title>My title</title>\n"
44         "</gils>\n";
45     const char *setname1="set1";
46     const char *setname2="set2";
47     const char *setname3="set3";
48     int status;
49     int rc;
50     ODR odr_input = odr_createmem (ODR_DECODE);    
51     ODR odr_output = odr_createmem (ODR_ENCODE);    
52     YAZ_PQF_Parser parser = yaz_pqf_create();
53     Z_RPNQuery *query = yaz_pqf_parse(parser, odr_input, 
54                                       "@attr 1=4 my");
55     Z_SortKeySpecList *spec = 
56           yaz_sort_spec (odr_output, "@attr 1=4 id");
57     int hits;
58
59     yaz_log_init_file("t7.log");
60
61     nmem_init ();
62     
63     zs = start_service();
64     zh = zebra_open (zs);
65     zebra_select_database(zh, "Default");
66     zebra_init(zh);
67
68     zebra_begin_trans (zh, 1);
69     zebra_add_record (zh, myrec, strlen(myrec));
70     zebra_end_trans (zh);
71
72     zebra_begin_trans (zh, 0);
73         
74     zebra_search_RPN (zh, odr_input, query, setname1, &hits);
75
76     rc=zebra_sort(zh, odr_output, 1, &setname1, setname2, spec, &status);
77     if (rc) { printf("sort A returned %d %d \n",rc,status); exit(1);}
78     rc=zebra_sort(zh, odr_output, 1, &setname2, setname3, spec, &status);
79     if (rc) { printf("sort B returned %d %d \n",rc,status); exit(1);}
80
81     zebra_end_trans (zh);
82     yaz_pqf_destroy(parser);
83
84     /*
85      zebra_deleleResultSet(zh, Z_DeleteRequest_list,
86                           1, &setnamep, &status);
87     */
88     odr_destroy (odr_input);
89     odr_destroy (odr_output);
90
91     zebra_commit (zh);
92     zebra_close (zh);
93     zebra_stop (zs);
94
95     nmem_exit ();
96     xmalloc_trav ("x");
97     exit (0);
98 }