2 * $Id: zoomtst9.c,v 1.1 2005-11-24 10:04:12 adam Exp $
4 * Program which illustrates the use of extended services update
11 #include <yaz/xmalloc.h>
16 fprintf(stderr, "usage:\n"
17 "zoomtst9 target [insert|delete|replace|update] id1 rec1 "
20 fprintf(stderr, "\nThis program illustrates the usage of"
21 " extended services Update from ZOOM.\n");
22 fprintf(stderr, "\nid "
23 "is optional opaque record Id and is omitted if empty.\n");
24 fprintf(stderr, "\nrec "
25 "is optional record data and is omitted if empty.\n");
29 int main(int argc, char **argv)
32 ZOOM_options o = ZOOM_options_create ();
34 const char *errmsg, *addinfo;
39 z = ZOOM_connection_create (o);
41 /* connect and init */
42 ZOOM_connection_connect (z, argv[1], 0);
44 if ((error = ZOOM_connection_error(z, &errmsg, &addinfo)))
46 fprintf(stderr, "%s error: %s (%d) %s\n",
47 ZOOM_connection_option_get(z, "host"),
48 errmsg, error, addinfo);
52 ZOOM_package pkg = ZOOM_connection_package(z, 0);
53 const char *cmd = argv[2];
56 if (!strcmp(cmd, "insert"))
57 ZOOM_package_option_set(pkg, "action", "recordInsert");
58 else if (!strcmp(cmd, "update"))
59 ZOOM_package_option_set(pkg, "action", "specialUpdate");
60 else if (!strcmp(cmd, "replace"))
61 ZOOM_package_option_set(pkg, "action", "recordReplace");
62 else if (!strcmp(cmd, "delete"))
63 ZOOM_package_option_set(pkg, "action", "recordDelete");
66 fprintf(stderr, "Bad action %s\n", cmd);
73 ZOOM_package_option_set(pkg, "recordIdOpaque",
74 argv[i][0] ? argv[i] : 0);
76 ZOOM_package_option_set(pkg, "record",
77 argv[i][0] ? argv[i] : 0);
79 ZOOM_package_send(pkg, "update"); /* Update EXT service */
81 if ((error = ZOOM_connection_error(z, &errmsg, &addinfo)))
83 fprintf(stderr, "%s error: %s (%d) %s\n",
84 ZOOM_connection_option_get(z, "host"),
85 errmsg, error, addinfo);
89 ZOOM_connection_destroy (z);
90 ZOOM_options_destroy(o);
96 * indent-tabs-mode: nil
98 * vim: shiftwidth=4 tabstop=8 expandtab