insert/delete tests in zebrash, transactions...
authorHeikki Levanto <heikki@indexdata.dk>
Mon, 23 Jun 2003 14:35:41 +0000 (14:35 +0000)
committerHeikki Levanto <heikki@indexdata.dk>
Mon, 23 Jun 2003 14:35:41 +0000 (14:35 +0000)
index/zebraapi.c
index/zebrash.c

index ff6786a..750c326 100644 (file)
@@ -1,4 +1,4 @@
-/* $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
 
@@ -1062,17 +1062,26 @@ int zebra_admin_exchange_record (ZebraHandle zh,
     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 */,
@@ -1085,6 +1094,7 @@ int zebra_admin_exchange_record (ZebraHandle zh,
     {
         dict_delete (zh->reg->matchDict, recid_z);
     }
+    zebra_end_trans(zh);
     return 0;
 }
 
index 79575d5..ecf3c9e 100644 (file)
@@ -1,5 +1,5 @@
 /* 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
  *
@@ -295,7 +295,72 @@ static int cmd_create_database( char *args[], char *outbuff)
        
     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 
  */
 
@@ -375,6 +440,21 @@ struct cmdstruct cmds[] = {
     { "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",