-/* $Id: zebraapi.c,v 1.107 2003-06-20 16:27:55 adam Exp $
+/* $Id: zebraapi.c,v 1.108 2003-06-23 14:35:41 heikki Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003
Index Data Aps
memcpy (recid_z, recid_buf, recid_len);
recid_z[recid_len] = 0;
+ zebra_begin_trans(zh,1);
+
rinfo = dict_lookup (zh->reg->matchDict, recid_z);
if (rinfo)
{
if (action == 1) /* fail if insert */
- return -1;
+ {
+ zebra_end_trans(zh);
+ return -1;
+ }
+
memcpy (&sysno, rinfo+1, sizeof(sysno));
}
else
{
if (action == 2 || action == 3) /* fail if delete or update */
+ {
+ zebra_end_trans(zh);
return -1;
+ }
}
extract_rec_in_mem (zh, "grs.sgml", rec_buf, rec_len, database,
action == 3 ? 1 : 0 /* delete flag */,
{
dict_delete (zh->reg->matchDict, recid_z);
}
+ zebra_end_trans(zh);
return 0;
}
/* zebrash.c - command-line interface to zebra API
- * $Id: zebrash.c,v 1.10 2003-06-20 14:21:23 heikki Exp $
+ * $Id: zebrash.c,v 1.11 2003-06-23 14:35:41 heikki Exp $
*
* Copyrigth 2003 Index Data Aps
*
return zebra_create_database(zh, db);
}
-/**************************************
+
+static int cmd_begin_trans( char *args[], char *outbuff)
+{
+ int rw=0;
+ if (args[1] && ( (args[1][0]=='1') || (args[1][0]=='w') ))
+ rw=1;
+ return zebra_begin_trans(zh,rw);
+}
+static int cmd_end_trans( char *args[], char *outbuff)
+{
+ return zebra_end_trans(zh);
+}
+/*************************************
+ * Inserting and deleting
+ */
+
+static int cmd_record_insert( char *args[], char *outbuff)
+{
+ int sysno=0;
+ char buf[MAX_ARG_LEN];
+ int i;
+ int rc;
+
+ i=1;
+ buf[0]='\0';
+ while (args[i])
+ {
+ strcat(buf, args[i++]);
+ strcat(buf, " ");
+ }
+ rc=zebra_record_insert(zh,buf, strlen(buf), &sysno);
+ if (0==rc)
+ {
+ sprintf(buf,"ok sysno=%d\n",sysno);
+ strcat(outbuff,buf);
+ }
+ return rc;
+}
+
+
+static int cmd_exchange_record( char *args[], char *outbuff)
+{
+ char *base=args[1];
+ char *id = args[2];
+ char *action = args[3];
+ int i=4;
+ int rc;
+ char buf[MAX_ARG_LEN];
+ if (!(base && id && action && args[4] ))
+ {
+ strcat(outbuff,"Missing arguments!\n");
+ onecommand("help exchange_record", outbuff, "");
+ return -90;
+ }
+ while (args[i])
+ {
+ strcat(buf, args[i++]);
+ strcat(buf, " ");
+ }
+ rc=zebra_admin_exchange_record(zh, base, buf, strlen(buf),
+ id, strlen(id), atoi(action));
+ return rc;
+}
+
+
+/**************************************)
* Command table, parser, and help
*/
{ "create_database", "basename",
"Creates a database",
cmd_create_database},
+ { "begin_trans", "[rw]",
+ "Begins a transaction. rw=1 means write, otherwise read-only",
+ cmd_begin_trans},
+ { "end_trans","",
+ "Ends a transaction",
+ cmd_end_trans},
+
+ { "","Updating:","",0},
+ { "record_insert","record",
+ "inserts an sgml record into Default",
+ cmd_record_insert},
+ { "exchange_record","database record-id action record",
+ "inserts (1), updates (2), or deletes (3) a record \n"
+ "record-id must be a unique identifier for the record",
+ cmd_exchange_record},
{ "", "Misc:","", 0},
{ "echo", "string",
"ouputs the string",