Index: trunk/src/sh_database.c
===================================================================
--- trunk/src/sh_database.c	(revision 54)
+++ trunk/src/sh_database.c	(revision 68)
@@ -109,4 +109,6 @@
   char            link_old[1024];
   char            link_new[1024];
+  char            acl_old[1024];
+  char            acl_new[1024];
 
   long            long_data[20];
@@ -204,4 +206,6 @@
   { NULL, N_("attr_old"),     0,  71,   16, 0, offsetof(struct dbins_, attr_old)},
   { NULL, N_("attr_new"),     0,  72,   16, 0, offsetof(struct dbins_, attr_new)},
+  { NULL, N_("acl_old"),      0,  73, 1024, 0, offsetof(struct dbins_, acl_old)},
+  { NULL, N_("acl_new"),      0,  74, 1024, 0, offsetof(struct dbins_, acl_new)},
 
   { NULL, NULL,      0,  0, 0, 0, 0 }
@@ -497,4 +501,5 @@
 static    OCIError  * o_error = NULL;
 static    OCIStmt   * o_statement;
+static    OCIBind   * o_bind = (OCIBind *) 0;
 static    text        o_errormsg[512];
 static    sb4         o_errorcode;
@@ -666,35 +671,17 @@
  oracle_connected:
 
-  /* 
-   * Insert
-   */
+  /* Get row index
+   */
+  sl_strlcpy (row_query, _("SELECT log_log_index_seq.NEXTVAL FROM dual"), 128);
+
 #ifdef DB_DEBUG
   sh_error_handle(SH_ERR_NOTICE, FIL__, __LINE__, 0, MSG_E_SUBGEN,
-		  query, 
+		  row_query, 
 		  _("sh_database_query"));
 #endif
 
   if (OCIStmtPrepare(o_statement, o_error, 
-		     (OraText*) query, sl_strlen(query), 
+		     (OraText*) row_query, sl_strlen(row_query), 
 		     OCI_NTV_SYNTAX, OCI_DEFAULT))
-    {
-      OCIErrorGet(o_error, 1, NULL, 
-		  &o_errorcode, o_errormsg, sizeof(o_errormsg), 
-		  OCI_HTYPE_ERROR);
-      sh_stripnl (o_errormsg);
-      sh_error_handle((-1), FIL__, __LINE__, (long) o_errorcode, MSG_E_SUBGEN,
-		      o_errormsg, 
-		      _("sh_database_query"));
-      if (retry == 0 && 
-	  (3114 == o_errorcode || 0 == strncmp(o_errormsg, _("ORA-03114"), 9))) 
-	{ 
-	  ++retry; sh_database_reset(); goto oracle_doconnect; 
-	}
-      goto err_out;
-    }
- 
-   if (OCIStmtExecute(o_servicecontext, 
-		      o_statement, o_error, 1,  0, 
-		      NULL, NULL, OCI_COMMIT_ON_SUCCESS))
     {
       OCIErrorGet(o_error, 1, NULL, 
@@ -713,24 +700,6 @@
     }
 
-#ifdef DB_DEBUG
-  sh_error_handle(SH_ERR_NOTICE, FIL__, __LINE__, 0, MSG_E_SUBGEN,
-		  _("No error on insert"), 
-		  _("sh_database_query"));
-#endif
-
-  /* Get row index
-   */
-  sl_strlcpy (row_query, _("SELECT MAX(log_index) FROM "), 128);
-  sl_strlcat (row_query, db_table, 128);
-
-#ifdef DB_DEBUG
-  sh_error_handle(SH_ERR_NOTICE, FIL__, __LINE__, 0, MSG_E_SUBGEN,
-		  row_query, 
-		  _("sh_database_query"));
-#endif
-
-  if (OCIStmtPrepare(o_statement, o_error, 
-		     (OraText*) row_query, sl_strlen(row_query), 
-		     OCI_NTV_SYNTAX, OCI_DEFAULT))
+  if (OCIStmtExecute(o_servicecontext, o_statement, o_error, 
+		     0, 0, NULL, NULL, OCI_DEFAULT))
     {
       OCIErrorGet(o_error, 1, NULL, 
@@ -749,6 +718,7 @@
     }
 
-  if (OCIStmtExecute(o_servicecontext, o_statement, o_error, 
-		     0, 0, NULL, NULL, OCI_DEFAULT))
+  if (OCIDefineByPos (o_statement, &o_define, o_error, 1, 
+		      &result, sizeof(result), 
+		      SQLT_INT, 0, 0, 0, OCI_DEFAULT))
     {
       OCIErrorGet(o_error, 1, NULL, 
@@ -766,8 +736,5 @@
       goto err_out;
     }
-
-  if (OCIDefineByPos (o_statement, &o_define, o_error, 1, 
-		      &result, sizeof(result), 
-		      SQLT_INT, 0, 0, 0, OCI_DEFAULT))
+  if (OCIStmtFetch (o_statement, o_error, 1, OCI_FETCH_NEXT, OCI_DEFAULT))
     {
       OCIErrorGet(o_error, 1, NULL, 
@@ -785,5 +752,44 @@
       goto err_out;
     }
-  if (OCIStmtFetch (o_statement, o_error, 1, OCI_FETCH_NEXT, OCI_DEFAULT))
+  
+#ifdef DB_DEBUG
+  sl_snprintf(row_query, 127, _("Returned value: %d"), result); 
+  sh_error_handle(SH_ERR_NOTICE, FIL__, __LINE__, 0, MSG_E_SUBGEN,
+		  row_query, 
+		  _("sh_database_query"));
+#endif
+
+  *id = result;
+
+  /* do the insert
+   */
+#ifdef DB_DEBUG
+  sh_error_handle(SH_ERR_NOTICE, FIL__, __LINE__, 0, MSG_E_SUBGEN,
+		  query, 
+		  _("sh_database_query"));
+#endif
+
+  if (OCIStmtPrepare(o_statement, o_error, 
+		     (OraText*) query, sl_strlen(query), 
+		     OCI_NTV_SYNTAX, OCI_DEFAULT))
+    {
+      OCIErrorGet(o_error, 1, NULL, 
+		  &o_errorcode, o_errormsg, sizeof(o_errormsg), 
+		  OCI_HTYPE_ERROR);
+      sh_stripnl (o_errormsg);
+      sh_error_handle((-1), FIL__, __LINE__, (long) o_errorcode, MSG_E_SUBGEN,
+		      o_errormsg, 
+		      _("sh_database_query"));
+      if (retry == 0 && 
+	  (3114 == o_errorcode || 0 == strncmp(o_errormsg, _("ORA-03114"), 9))) 
+	{ 
+	  ++retry; sh_database_reset(); goto oracle_doconnect; 
+	}
+      goto err_out;
+    }
+ 
+  if (OCIBindByPos(o_statement, &o_bind, o_error, 1,
+		   (dvoid *) &result, (sword) sizeof(result), SQLT_INT, 
+		   (dvoid *) 0, (ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT))
     {
       OCIErrorGet(o_error, 1, NULL, 
@@ -801,13 +807,29 @@
       goto err_out;
     }
-  
+
+   if (OCIStmtExecute(o_servicecontext, 
+		      o_statement, o_error, 1,  0, 
+		      NULL, NULL, OCI_COMMIT_ON_SUCCESS))
+    {
+      OCIErrorGet(o_error, 1, NULL, 
+		  &o_errorcode, o_errormsg, sizeof(o_errormsg), 
+		  OCI_HTYPE_ERROR);
+      sh_stripnl (o_errormsg);
+      sh_error_handle((-1), FIL__, __LINE__, (long) o_errorcode, MSG_E_SUBGEN,
+		      o_errormsg, 
+		      _("sh_database_query"));
+      if (retry == 0 && 
+	  (3114 == o_errorcode || 0 == strncmp(o_errormsg, _("ORA-03114"), 9))) 
+	  { 
+	    ++retry; sh_database_reset(); goto oracle_doconnect; 
+	  }
+      goto err_out;
+    }
+
 #ifdef DB_DEBUG
-  sl_snprintf(row_query, 127, _("Returned value: %d"), result); 
   sh_error_handle(SH_ERR_NOTICE, FIL__, __LINE__, 0, MSG_E_SUBGEN,
-		  row_query, 
+		  _("No error on insert"), 
 		  _("sh_database_query"));
 #endif
-
-  *id = result;
 
   if (sh_persistent_dbconn == S_FALSE)
@@ -1254,5 +1276,5 @@
   (void)
   sl_snprintf (values, SH_QUERY_MAX,  
-	       _("(%s,%c%s%c,to_date(%c%s%c,'YYYY-MM-DD HH24:MI:SS'),%c%s%c,%c%s%c"),
+	       _("(:1,%s,%c%s%c,to_date(%c%s%c,'YYYY-MM-DD HH24:MI:SS'),%c%s%c,%c%s%c"),
                id >= 0 ? num : _("NULL"),
                '\'', db_entry->host,'\'', 
@@ -1263,5 +1285,5 @@
                '\'');
   (void) sl_snprintf (columns, 1023, 
-		      _("(log_ref,log_host,log_time,log_sev,log_msg"));
+		      _("(log_index,log_ref,log_host,log_time,log_sev,log_msg"));
 #elif defined(WITH_POSTGRES)
   /* Prepare query for PQexecParams
@@ -1495,8 +1517,9 @@
 }
 
-static int is_escaped(unsigned char * p) {
+static int is_escaped(char * p_in) {
 
   int    escp = 0;
   int    retv = S_TRUE;
+  unsigned char * p = (unsigned char *) p_in;
 
   while (*p != '\0') 
