Index: trunk/src/sh_database.c
===================================================================
--- trunk/src/sh_database.c	(revision 34)
+++ trunk/src/sh_database.c	(revision 35)
@@ -870,4 +870,6 @@
   PGresult        * res;
   unsigned int      i;
+  const char      * params[1];
+  char              id_param[32];
   static SH_TIMEOUT sh_timer = { 0, 3600, S_TRUE };
 
@@ -940,26 +942,29 @@
 
 
-  /* do the insert
-   */
-  res = PQexec(conn, query);
-  if (PQresultStatus(res) != PGRES_COMMAND_OK) 
+  /* get the unique row index
+   */
+  res = PQexec(conn, _("SELECT NEXTVAL('log_log_index_seq')"));
+  if (PQresultStatus(res) != PGRES_TUPLES_OK) 
     {
       PQclear(res);
       goto err_out;
     }
+
+  *id = atoi (PQgetvalue(res, 0, 0)); 
   PQclear(res);
 
-  /* get the unique row index
-   */
-  res = PQexec(conn, _("SELECT last_value FROM log_log_index_seq"));
-  if (PQresultStatus(res) != PGRES_TUPLES_OK) 
+  sl_snprintf(id_param, 32, "%ld", *id);
+  params[0] = id_param;
+
+  /* do the insert
+   */
+  res = PQexecParams(conn, query, 1, NULL, params, NULL, NULL, 1);
+  if (PQresultStatus(res) != PGRES_COMMAND_OK) 
     {
       PQclear(res);
       goto err_out;
     }
-
-  *id = atoi (PQgetvalue(res, 0, 0)); 
-
   PQclear(res);
+
   if (S_FALSE == sh_persistent_dbconn)
     {
@@ -1244,5 +1249,5 @@
   /*@+bufferoverflowhigh@*/
 
-#ifdef WITH_ORACLE
+#if defined(WITH_ORACLE)
   /* Oracle needs some help for the time format (fix by Michael Somers)
    */
@@ -1257,4 +1262,21 @@
                (db_entry->msg[0] == '\0' ? _("NULL") : db_entry->msg),
                '\'');
+  (void) sl_snprintf (columns, 1023, 
+		      _("(log_ref,log_host,log_time,log_sev,log_msg"));
+#elif defined(WITH_POSTGRES)
+  /* Prepare query for PQexecParams
+   */
+  (void)
+  sl_snprintf (values, SH_QUERY_MAX, 
+	       _("($1,%s,%c%s%c,%c%s%c,%c%s%c,%c%s%c"),
+	       id >= 0 ? num : _("NULL"),
+	       '\'', db_entry->host,'\'', 
+	       '\'', db_entry->time,'\'', 
+	       '\'', db_entry->sev, '\'',
+	       '\'', 
+	       (db_entry->msg[0] == '\0' ? _("NULL") : db_entry->msg), 
+	       '\'');
+  (void) sl_snprintf (columns, 1023, 
+		      _("(log_index,log_ref,log_host,log_time,log_sev,log_msg"));
 #else
   (void)
@@ -1267,8 +1289,8 @@
 	       (db_entry->msg[0] == '\0' ? _("NULL") : db_entry->msg), 
 	       '\'');
-#endif
-
   (void) sl_snprintf (columns, 1023, 
 		      _("(log_ref,log_host,log_time,log_sev,log_msg"));
+#endif
+
 
   /*@-type@*//* byte* versus char[..] */
@@ -1666,7 +1688,7 @@
 /* recursively enter linked list of messages into database, last first
  */
-int sh_database_insert_rec (dbins * curr, unsigned int depth)
-{
-  long    id = 0;
+long sh_database_insert_rec (dbins * curr, int depth)
+{
+  unsigned long    id = 0;
   dbins * prev;
 
@@ -1700,5 +1722,5 @@
   SH_FREE(curr);
 
-  SL_RETURN(id, _("sh_database_insert"));
+  SL_RETURN(id, _("sh_database_insert_rec"));
 }
 
