From: Adam Dickmeiss Date: Thu, 24 Nov 2005 10:04:12 +0000 (+0000) Subject: Added ZOOM example program that illustrates Ext Record Update X-Git-Tag: YAZ.2.1.10~6 X-Git-Url: http://sru.miketaylor.org.uk/?a=commitdiff_plain;h=fc1c67f5c7ba5e39cdfeff0631eb5f9bd8dbb40a;p=yaz-moved-to-github.git Added ZOOM example program that illustrates Ext Record Update --- diff --git a/zoom/Makefile.am b/zoom/Makefile.am index 9212643..f90bac0 100644 --- a/zoom/Makefile.am +++ b/zoom/Makefile.am @@ -1,9 +1,9 @@ -## $Id: Makefile.am,v 1.15 2005-09-07 13:45:15 marc Exp $ +## $Id: Makefile.am,v 1.16 2005-11-24 10:04:12 adam Exp $ ## Copyright (C) 2001, Index Data AM_CPPFLAGS = -I$(top_srcdir)/include -EXTRA_PROGRAMS = zoomtst1 zoomtst2 zoomtst3 zoomtst4 zoomtst5 zoomtst6 zoomtst7 zoomtst8 +EXTRA_PROGRAMS = zoomtst1 zoomtst2 zoomtst3 zoomtst4 zoomtst5 zoomtst6 zoomtst7 zoomtst8 zoomtst9 bin_PROGRAMS = zoomsh zoom-benchmark LDADD = ../src/libyaz.la $(READLINE_LIBS) @@ -16,6 +16,7 @@ zoomtst5_SOURCES = zoomtst5.c zoomtst6_SOURCES = zoomtst6.c zoomtst7_SOURCES = zoomtst7.c zoomtst8_SOURCES = zoomtst8.c +zoomtst9_SOURCES = zoomtst9.c zoomsh_SOURCES = zoomsh.c zoom_benchmark_SOURCES = zoom-benchmark.c diff --git a/zoom/zoomtst9.c b/zoom/zoomtst9.c new file mode 100644 index 0000000..a200d31 --- /dev/null +++ b/zoom/zoomtst9.c @@ -0,0 +1,100 @@ +/* + * $Id: zoomtst9.c,v 1.1 2005-11-24 10:04:12 adam Exp $ + * + * Program which illustrates the use of extended services update + */ + +#include +#include + +#include +#include +#include + +static void usage() +{ + fprintf(stderr, "usage:\n" + "zoomtst9 target [insert|delete|replace|update] id1 rec1 " + "id2 rec2 ..\n"); + + fprintf(stderr, "\nThis program illustrates the usage of" + " extended services Update from ZOOM.\n"); + fprintf(stderr, "\nid " + "is optional opaque record Id and is omitted if empty.\n"); + fprintf(stderr, "\nrec " + "is optional record data and is omitted if empty.\n"); + exit (1); +} + +int main(int argc, char **argv) +{ + ZOOM_connection z; + ZOOM_options o = ZOOM_options_create (); + int error; + const char *errmsg, *addinfo; + + if (argc < 3) + usage(); + + z = ZOOM_connection_create (o); + + /* connect and init */ + ZOOM_connection_connect (z, argv[1], 0); + + if ((error = ZOOM_connection_error(z, &errmsg, &addinfo))) + { + fprintf(stderr, "%s error: %s (%d) %s\n", + ZOOM_connection_option_get(z, "host"), + errmsg, error, addinfo); + } + else + { + ZOOM_package pkg = ZOOM_connection_package(z, 0); + const char *cmd = argv[2]; + int i; + + if (!strcmp(cmd, "insert")) + ZOOM_package_option_set(pkg, "action", "recordInsert"); + else if (!strcmp(cmd, "update")) + ZOOM_package_option_set(pkg, "action", "specialUpdate"); + else if (!strcmp(cmd, "replace")) + ZOOM_package_option_set(pkg, "action", "recordReplace"); + else if (!strcmp(cmd, "delete")) + ZOOM_package_option_set(pkg, "action", "recordDelete"); + else + { + fprintf(stderr, "Bad action %s\n", cmd); + usage(); + } + + i = 3; + while (i < argc-1) + { + ZOOM_package_option_set(pkg, "recordIdOpaque", + argv[i][0] ? argv[i] : 0); + i++; + ZOOM_package_option_set(pkg, "record", + argv[i][0] ? argv[i] : 0); + i++; + ZOOM_package_send(pkg, "update"); /* Update EXT service */ + + if ((error = ZOOM_connection_error(z, &errmsg, &addinfo))) + { + fprintf(stderr, "%s error: %s (%d) %s\n", + ZOOM_connection_option_get(z, "host"), + errmsg, error, addinfo); + } + } + } + ZOOM_connection_destroy (z); + ZOOM_options_destroy(o); + exit (0); +} +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ +