Fix a query
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sun, 13 Aug 2006 12:32:17 +0000 (12:32 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sun, 13 Aug 2006 12:32:17 +0000 (12:32 +0000)
SQL backtrace 'hover-me' becomes red in case of sql error

git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@810 839d8a87-29fc-0310-9880-83ba4fa771e5

classes/XDB.php
modules/events.php
templates/database-debug.tpl
templates/skin/common.devel.tpl

index edcbed6..299f468 100644 (file)
@@ -40,7 +40,7 @@ class XDB
         $length = 0;
         foreach ($query as $key=>$line) {
             $local = -2;
-            if (preg_match('/^([A-Z]+(?:\s+(?:JOIN|BY))?)\s+(.*)/', $line, $matches)
+            if (preg_match('/^([A-Z]+(?:\s+(?:JOIN|BY|FROM|INTO))?)\s+(.*)/', $line, $matches)
                 && $matches[1] != 'AND' && $matches[1] != 'OR') {
                 $local  = strlen($matches[1]);
                 $line   = $matches[1] . '  ' . $matches[2];
@@ -79,6 +79,9 @@ class XDB
         if ($globals->debug & 1) {
             $trace_data['error'] = mysql_error();
             $GLOBALS['XDB::trace_data'][] = $trace_data;
+            if (mysql_errno()) {
+                $GLOBALS['XDB::error'] = true;
+            }
         }
 
         return $res;
@@ -157,6 +160,7 @@ class XDB
 
     function trace_format(&$page, $template = 'database-debug.tpl') {
         $page->assign('trace_data', $GLOBALS['XDB::trace_data']);
+        $page->assign('db_error', $GLOBALS['XDB::error']);
         return $page->fetch($template);
     }
 }
index 2fba18a..35fe2e9 100644 (file)
@@ -109,16 +109,17 @@ class EventsModule extends PLModule
 
         // cache les evenements lus et raffiche les evenements a relire
         if ($action == 'read' && $eid) {
-            XDB::execute('DELETE FROM evenements_vus AS ev 
-                                     INNER JOIN evenements AS e ON e.id = ev.evt_id
-                                          WHERE peremption < NOW)');
+            XDB::execute('DELETE evenements_vus.*
+                            FROM evenements_vus AS ev 
+                      INNER JOIN evenements AS e ON e.id = ev.evt_id
+                           WHERE peremption < NOW()');
             XDB::execute('REPLACE INTO evenements_vus VALUES({?},{?})',
                                    $eid, S::v('uid'));
         }
 
         if ($action == 'unread' && $eid) {
             XDB::execute('DELETE FROM evenements_vus
-                                          WHERE evt_id = {?} AND user_id = {?}',
+                           WHERE evt_id = {?} AND user_id = {?}',
                                    $eid, S::v('uid'));
         }
 
index bf6d610..944ad65 100644 (file)
@@ -33,7 +33,7 @@
   {if $query.error}
   <tr>
     <td>
-      <strong>ERROR:</strong><br />
+      <strong style="color: #f00">ERROR:</strong><br />
       {$query.error|nl2br}
     </td>
   </tr>
index 209690f..750f036 100644 (file)
@@ -24,7 +24,9 @@
 {if $db_trace && $db_trace neq "\n\n"}
   <div id="db-trace">
     <h1>
+      {if $db_error}<span style="color: #f00">{/if}
       Trace de l'exĂ©cution de cette page sur mysql (hover me)
+      {if $db_error}</span>{/if}
     </h1>
     <div class="hide">
       {$db_trace|smarty:nodefaults}