Index: includes/database.mysql.inc
===================================================================
--- includes/database.mysql.inc	(revision 1148)
+++ includes/database.mysql.inc	(working copy)
@@ -119,10 +119,21 @@
     print '<p>query: '. $query .'<br />error:'. mysql_error($active_db) .'</p>';
   }
 
-  if (!mysql_errno($active_db)) {
+  $errno = mysql_errno($active_db);
+
+  if (!$errno) {
     return $result;
   }
   else {
+    switch ($errno) {
+      case 1153: //Got a packet bigger than "max_allowed_packet" bytes
+        // If the MySQL Server rejected the query because it's too big,
+        // writing the query to database watchdog will fail as well
+        // Truncate the query ...
+        $query = substr($query, 0, 100);
+        break;
+    }
+
     // Indicate to drupal_error_handler that this is a database error.
     ${DB_ERROR} = TRUE;
     trigger_error(check_plain(mysql_error($active_db) ."\nquery: ". $query), E_USER_WARNING);
Index: includes/database.mysqli.inc
===================================================================
--- includes/database.mysqli.inc	(revision 1148)
+++ includes/database.mysqli.inc	(working copy)
@@ -119,10 +119,21 @@
     print '<p>query: '. $query .'<br />error:'. mysqli_error($active_db) .'</p>';
   }
 
-  if (!mysqli_errno($active_db)) {
+  $errno = mysqli_errno($active_db);
+
+  if (!$errno) {
     return $result;
   }
   else {
+    switch ($errno) {
+      case 1153: //Got a packet bigger than "max_allowed_packet" bytes
+        // If the MySQL Server rejected the query because it's too big,
+        // writing the query to database watchdog will fail as well.
+        // Truncate the query ...
+        $query = substr($query, 0, 100);
+        break;
+    }
+
     // Indicate to drupal_error_handler that this is a database error.
     ${DB_ERROR} = TRUE;
     trigger_error(check_plain(mysqli_error($active_db) ."\nquery: ". $query), E_USER_WARNING);
