1 /* $Id: zoomtst7.c,v 1.19 2007-04-17 20:26:19 adam Exp $ */
4 \brief Mix of operations
11 #include <yaz/xmalloc.h>
16 int main(int argc, char **argv)
21 ZOOM_resultset r[10]; /* and result sets .. */
24 o = ZOOM_options_create ();
26 z = ZOOM_connection_new ("localhost", 9999);
27 if (ZOOM_connection_error (z, 0, 0))
29 printf ("error - couldn't connect?\n");
33 ZOOM_connection_destroy (z);
35 for (block = 0; block < 3; block++)
40 printf ("blocking - not calling ZOOM_events\n");
43 printf ("blocking - calling ZOOM_events\n");
46 printf ("non-blocking - calling ZOOM_events\n");
50 ZOOM_options_set (o, "async", "1");
51 for (i = 0; i<10; i++)
55 printf ("session %2d", i);
56 sprintf (host, "localhost:9999/%d", i);
57 z = ZOOM_connection_create (o);
58 ZOOM_connection_connect (z, host, 0);
60 for (j = 0; j < 10; j++)
64 ZOOM_query s = ZOOM_query_create ();
66 sprintf (query, "i%dr%d", i, j);
68 if (ZOOM_query_prefix (s, query))
70 printf ("bad PQF: %s\n", query);
73 ZOOM_options_set (o, "start", "0");
74 ZOOM_options_set (o, "count", "0");
76 r[j] = ZOOM_connection_search (z, s); /* non-piggy */
78 ZOOM_resultset_records (r[j], recs, 0, 2); /* first two */
80 ZOOM_resultset_records (r[j], recs, 1, 2); /* third */
82 ZOOM_resultset_records (r[j], recs, 0, 0); /* ignored */
84 if (ZOOM_resultset_size (r[j]) > 2)
88 fprintf (stderr, "\nrecord missing\n");
93 ZOOM_query_destroy (s);
97 while (ZOOM_event (1, &z))
100 for (j = 0; j<i; j++)
101 ZOOM_resultset_destroy (r[j]);
102 ZOOM_connection_destroy (z);
104 ZOOM_resultset_destroy (r[j]);
105 printf ("10 searches, 20 presents done\n");
109 for (i = 0; i<1; i++)
111 ZOOM_query q = ZOOM_query_create ();
114 printf ("session %2d", i+10);
115 sprintf (host, "localhost:9999/%d", i);
116 z = ZOOM_connection_create (o);
117 ZOOM_connection_connect (z, host, 0);
119 for (j = 0; j < 10; j++)
123 sprintf (query, "i%dr%d", i, j);
125 ZOOM_options_set (o, "count", "0");
127 r[j] = ZOOM_connection_search_pqf (z, query);
131 while (ZOOM_event (1, &z))
135 ZOOM_connection_destroy (z);
137 for (j = 0; j < 10; j++)
139 ZOOM_resultset_records (r[j], 0, 0, 1);
141 for (j = 0; j < 10; j++)
142 ZOOM_resultset_destroy (r[j]);
143 ZOOM_query_destroy (q);
144 printf ("10 searches, 10 ignored presents done\n");
148 for (i = 0; i<1; i++)
151 ZOOM_scanset scan = 0;
153 printf ("session %2d", i);
154 sprintf (host, "localhost:9999/%d", i);
155 z = ZOOM_connection_create (o);
156 ZOOM_connection_connect (z, host, 0);
158 scan = ZOOM_connection_scan(z, "@attr 1=4 a");
160 while (ZOOM_event (1, &z))
162 printf (" scan size = %ld\n", (long) ZOOM_scanset_size(scan));
163 for (j = 0; j<ZOOM_scanset_size (scan); j++)
167 term = ZOOM_scanset_term (scan, j, &occur, &len);
169 printf ("%d %.*s %d\n", j, len, term, occur);
172 ZOOM_scanset_destroy (scan);
173 ZOOM_connection_destroy (z);
177 ZOOM_options_destroy (o);
184 * indent-tabs-mode: nil
186 * vim: shiftwidth=4 tabstop=8 expandtab