Index: trunk/include/dblayer/functions_mysql.inc.php
===================================================================
--- trunk/include/dblayer/functions_mysql.inc.php	(revision 11364)
+++ trunk/include/dblayer/functions_mysql.inc.php	(revision 11485)
@@ -220,4 +220,5 @@
   if (count($datas) == 0)
     return;
+  
   // depending on the MySQL version, we use the multi table update or N update queries
   if (count($datas) < 10)
@@ -233,5 +234,5 @@
         $separator = $is_first ? '' : ",\n    ";
 
-        if (isset($data[$key]) and $data[$key] !== '')
+        if (isset($data[$key]) and $data[$key] != '')
         {
           $query.= $separator.$key.' = \''.$data[$key].'\'';
@@ -239,5 +240,5 @@
         else
         {
-          if ($flags & MASS_UPDATES_SKIP_EMPTY )
+          if ( $flags & MASS_UPDATES_SKIP_EMPTY )
             continue; // next field
           $query.= "$separator$key = NULL";
@@ -346,4 +347,63 @@
 }
 
+/**
+ * updates one line in a table
+ *
+ * @param string table_name
+ * @param array dbfields
+ * @param array data
+ * @param int flags - if MASS_UPDATES_SKIP_EMPTY - empty values do not overwrite existing ones
+ * @return void
+ */
+function single_update($tablename, $dbfields, $data, $flags=0)
+{
+  if (count($data) == 0)
+    return;
+
+  $query = '
+UPDATE '.$tablename.'
+  SET ';
+  $is_first = true;
+  foreach ($dbfields['update'] as $key)
+  {
+    $separator = $is_first ? '' : ",\n    ";
+
+    if (isset($data[$key]) and $data[$key] != '')
+    {
+      $query.= $separator.$key.' = \''.$data[$key].'\'';
+    }
+    else
+    {
+      if ( $flags & MASS_UPDATES_SKIP_EMPTY )
+        continue; // next field
+      $query.= "$separator$key = NULL";
+    }
+    $is_first = false;
+  }
+  if (!$is_first)
+  {// only if one field at least updated
+    $query.= '
+  WHERE ';
+    $is_first = true;
+    foreach ($dbfields['primary'] as $key)
+    {
+      if (!$is_first)
+      {
+        $query.= ' AND ';
+      }
+      if ( isset($data[$key]) )
+      {
+        $query.= $key.' = \''.$data[$key].'\'';
+      }
+      else
+      {
+        $query.= $key.' IS NULL';
+      }
+      $is_first = false;
+    }
+    pwg_query($query);
+  }
+}
+
 
 /**
@@ -412,4 +472,43 @@
 
 /**
+ * inserts on line in a table
+ *
+ * @param string table_name
+ * @param array dbfields
+ * @param array insert
+ * @return void
+ */
+function single_insert($table_name, $dbfields, $insert)
+{
+  if (count($insert) != 0)
+  {
+    $query = '
+INSERT INTO '.$table_name.'
+  ('.implode(',', $dbfields).')
+  VALUES';
+
+    $query .= '(';
+    foreach ($dbfields as $field_id => $dbfield)
+    {
+      if ($field_id > 0)
+      {
+        $query .= ',';
+      }
+      if (!isset($insert[$dbfield]) or $insert[$dbfield] === '')
+      {
+        $query .= 'NULL';
+      }
+      else
+      {
+        $query .= "'".$insert[$dbfield]."'";
+      }
+    }
+    $query .= ')';
+    
+    pwg_query($query);
+  }
+}
+
+/**
  * Do maintenance on all PWG tables
  *
Index: trunk/include/dblayer/functions_pdo-sqlite.inc.php
===================================================================
--- trunk/include/dblayer/functions_pdo-sqlite.inc.php	(revision 11364)
+++ trunk/include/dblayer/functions_pdo-sqlite.inc.php	(revision 11485)
@@ -279,11 +279,11 @@
       if (isset($data[$key]) and $data[$key] != '')
       {
-	$query.= $separator.$key.' = \''.$data[$key].'\'';
+        $query.= $separator.$key.' = \''.$data[$key].'\'';
       }
       else
       {
-	if ($flags & MASS_UPDATES_SKIP_EMPTY )
-	  continue; // next field
-	$query.= "$separator$key = NULL";
+        if ( $flags & MASS_UPDATES_SKIP_EMPTY )
+          continue; // next field
+        $query.= "$separator$key = NULL";
       }
       $is_first = false;
@@ -296,20 +296,79 @@
       foreach ($dbfields['primary'] as $key)
       {
-	if (!$is_first)
+        if (!$is_first)
         {
-	  $query.= ' AND ';
-	}
-	if ( isset($data[$key]) )
+          $query.= ' AND ';
+        }
+        if ( isset($data[$key]) )
         {
-	  $query.= $key.' = \''.$data[$key].'\'';
-	}
-	else
+          $query.= $key.' = \''.$data[$key].'\'';
+        }
+        else
         {
-	  $query.= $key.' IS NULL';
-	}
-	$is_first = false;
+          $query.= $key.' IS NULL';
+        }
+        $is_first = false;
       }
       pwg_query($query);
     }
+  }
+}
+
+/**
+ * updates on line in a table
+ *
+ * @param string table_name
+ * @param array dbfields
+ * @param array data
+ * @param int flags - if MASS_UPDATES_SKIP_EMPTY - empty values do not overwrite existing ones
+ * @return void
+ */
+function single_update($tablename, $dbfields, $data, $flags=0)
+{
+  if (count($data) == 0)
+    return;
+
+  $query = '
+UPDATE '.$tablename.'
+  SET ';
+  $is_first = true;
+  foreach ($dbfields['update'] as $key)
+  {
+    $separator = $is_first ? '' : ",\n    ";
+    
+    if (isset($data[$key]) and $data[$key] != '')
+    {
+      $query.= $separator.$key.' = \''.$data[$key].'\'';
+    }
+    else
+    {
+      if ( $flags & MASS_UPDATES_SKIP_EMPTY )
+        continue; // next field
+      $query.= "$separator$key = NULL";
+    }
+    $is_first = false;
+  }
+  if (!$is_first)
+  {// only if one field at least updated
+    $query.= '
+  WHERE ';
+    $is_first = true;
+    foreach ($dbfields['primary'] as $key)
+    {
+      if (!$is_first)
+      {
+        $query.= ' AND ';
+      }
+      if ( isset($data[$key]) )
+      {
+        $query.= $key.' = \''.$data[$key].'\'';
+      }
+      else
+      {
+        $query.= $key.' IS NULL';
+      }
+      $is_first = false;
+    }
+    pwg_query($query);
   }
 }
@@ -324,5 +383,4 @@
  * @return void
  */
-
 function mass_inserts($table_name, $dbfields, $datas)
 {
@@ -381,4 +439,43 @@
 
 /**
+ * inserts one line in a table
+ *
+ * @param string table_name
+ * @param array dbfields
+ * @param array insert
+ * @return void
+ */
+function single_insert($table_name, $dbfields, $insert)
+{
+  if (count($insert) != 0)
+  {
+    $query = '
+INSERT INTO '.$table_name.'
+  ('.implode(',', $dbfields).')
+  VALUES';
+
+    $query .= '(';
+    foreach ($dbfields as $field_id => $dbfield)
+    {
+      if ($field_id > 0)
+      {
+        $query .= ',';
+      }
+      if (!isset($insert[$dbfield]) or $insert[$dbfield] === '')
+      {
+        $query .= 'NULL';
+      }
+      else
+      {
+        $query .= "'".$insert[$dbfield]."'";
+      }
+    }
+    $query .= ')';
+    
+    pwg_query($query);
+  }
+}
+
+/**
  * Do maintenance on all PWG tables
  *
Index: trunk/include/dblayer/functions_pgsql.inc.php
===================================================================
--- trunk/include/dblayer/functions_pgsql.inc.php	(revision 11364)
+++ trunk/include/dblayer/functions_pgsql.inc.php	(revision 11485)
@@ -356,5 +356,5 @@
         else
         {
-          if ($flags & MASS_UPDATES_SKIP_EMPTY )
+          if ( $flags & MASS_UPDATES_SKIP_EMPTY )
             continue; // next field
           $query.= "$separator$key = NULL";
@@ -426,4 +426,62 @@
 }
 
+/**
+ * updates on line in a table
+ *
+ * @param string table_name
+ * @param array dbfields
+ * @param array data
+ * @param int flags - if MASS_UPDATES_SKIP_EMPTY - empty values do not overwrite existing ones
+ * @return void
+ */
+function single_update($tablename, $dbfields, $data, $flags=0)
+{
+  if (count($data) == 0)
+    return;
+
+  $query = '
+UPDATE '.$tablename.'
+  SET ';
+  $is_first = true;
+  foreach ($dbfields['update'] as $key)
+  {
+    $separator = $is_first ? '' : ",\n    ";
+
+    if (isset($data[$key]) and $data[$key] != '')
+    {
+      $query.= $separator.$key.' = \''.$data[$key].'\'';
+    }
+    else
+    {
+      if ( $flags & MASS_UPDATES_SKIP_EMPTY )
+        continue; // next field
+      $query.= "$separator$key = NULL";
+    }
+    $is_first = false;
+  }
+  if (!$is_first)
+  {// only if one field at least updated
+    $query.= '
+  WHERE ';
+    $is_first = true;
+    foreach ($dbfields['primary'] as $key)
+    {
+      if (!$is_first)
+      {
+        $query.= ' AND ';
+      }
+      if ( isset($data[$key]) )
+      {
+        $query.= $key.' = \''.$data[$key].'\'';
+      }
+      else
+      {
+        $query.= $key.' IS NULL';
+      }
+      $is_first = false;
+    }
+    pwg_query($query);
+  } 
+}
 
 /**
@@ -435,5 +493,4 @@
  * @return void
  */
-
 function mass_inserts($table_name, $dbfields, $datas)
 {
@@ -492,4 +549,43 @@
 
 /**
+ * inserts on line in a table
+ *
+ * @param string table_name
+ * @param array dbfields
+ * @param array insert
+ * @return void
+ */
+function single_insert($table_name, $dbfields, $insert)
+{
+  if (count($insert) != 0)
+  {
+    $query = '
+INSERT INTO '.$table_name.'
+  ('.implode(',', $dbfields).')
+  VALUES';
+
+    $query .= '(';
+    foreach ($dbfields as $field_id => $dbfield)
+    {
+      if ($field_id > 0)
+      {
+        $query .= ',';
+      }
+      if (!isset($insert[$dbfield]) or $insert[$dbfield] === '')
+      {
+        $query .= 'NULL';
+      }
+      else
+      {
+        $query .= "'".$insert[$dbfield]."'";
+      }
+    }
+    $query .= ')';
+    
+    pwg_query($query);
+  }
+}
+
+/**
  * Do maintenance on all PWG tables
  *
Index: trunk/include/dblayer/functions_sqlite.inc.php
===================================================================
--- trunk/include/dblayer/functions_sqlite.inc.php	(revision 11364)
+++ trunk/include/dblayer/functions_sqlite.inc.php	(revision 11485)
@@ -291,11 +291,11 @@
       if (isset($data[$key]) and $data[$key] != '')
       {
-	$query.= $separator.$key.' = \''.$data[$key].'\'';
+        $query.= $separator.$key.' = \''.$data[$key].'\'';
       }
       else
       {
-	if ($flags & MASS_UPDATES_SKIP_EMPTY )
-	  continue; // next field
-	$query.= "$separator$key = NULL";
+        if ( $flags & MASS_UPDATES_SKIP_EMPTY )
+          continue; // next field
+        $query.= "$separator$key = NULL";
       }
       $is_first = false;
@@ -308,20 +308,79 @@
       foreach ($dbfields['primary'] as $key)
       {
-	if (!$is_first)
+        if (!$is_first)
         {
-	  $query.= ' AND ';
-	}
-	if ( isset($data[$key]) )
+          $query.= ' AND ';
+        }
+        if ( isset($data[$key]) )
         {
-	  $query.= $key.' = \''.$data[$key].'\'';
-	}
-	else
+          $query.= $key.' = \''.$data[$key].'\'';
+        }
+        else
         {
-	  $query.= $key.' IS NULL';
-	}
-	$is_first = false;
+          $query.= $key.' IS NULL';
+        }
+        $is_first = false;
       }
       pwg_query($query);
     }
+  }
+}
+
+/**
+ * updates on line in a table
+ *
+ * @param string table_name
+ * @param array dbfields
+ * @param array data
+ * @param int flags - if MASS_UPDATES_SKIP_EMPTY - empty values do not overwrite existing ones
+ * @return void
+ */
+function single_update($tablename, $dbfields, $data, $flags=0)
+{
+  if (count($data) == 0)
+    return;
+
+  $query = '
+UPDATE '.$tablename.'
+  SET ';
+  $is_first = true;
+  foreach ($dbfields['update'] as $key)
+  {
+    $separator = $is_first ? '' : ",\n    ";
+    
+    if (isset($data[$key]) and $data[$key] != '')
+    {
+      $query.= $separator.$key.' = \''.$data[$key].'\'';
+    }
+    else
+    {
+      if ( $flags & MASS_UPDATES_SKIP_EMPTY )
+        continue; // next field
+      $query.= "$separator$key = NULL";
+    }
+    $is_first = false;
+  }
+  if (!$is_first)
+  {// only if one field at least updated
+    $query.= '
+  WHERE ';
+    $is_first = true;
+    foreach ($dbfields['primary'] as $key)
+    {
+      if (!$is_first)
+      {
+        $query.= ' AND ';
+      }
+      if ( isset($data[$key]) )
+      {
+        $query.= $key.' = \''.$data[$key].'\'';
+      }
+      else
+      {
+        $query.= $key.' IS NULL';
+      }
+      $is_first = false;
+    }
+    pwg_query($query);
   }
 }
@@ -336,5 +395,4 @@
  * @return void
  */
-
 function mass_inserts($table_name, $dbfields, $datas)
 {
@@ -393,4 +451,43 @@
 
 /**
+ * inserts one line in a table
+ *
+ * @param string table_name
+ * @param array dbfields
+ * @param array insert
+ * @return void
+ */
+function single_insert($table_name, $dbfields, $insert)
+{
+  if (count($insert) != 0)
+  {
+    $query = '
+INSERT INTO '.$table_name.'
+  ('.implode(',', $dbfields).')
+  VALUES';
+
+    $query .= '(';
+    foreach ($dbfields as $field_id => $dbfield)
+    {
+      if ($field_id > 0)
+      {
+        $query .= ',';
+      }
+      if (!isset($insert[$dbfield]) or $insert[$dbfield] === '')
+      {
+        $query .= 'NULL';
+      }
+      else
+      {
+        $query .= "'".$insert[$dbfield]."'";
+      }
+    }
+    $query .= ')';
+    
+    pwg_query($query);
+  }
+}
+
+/**
  * Do maintenance on all PWG tables
  *
