t3lib_db: added calls to t3lib_div::sysLog() and t3lib_div::devLog() if recordset...
authorDmitry Dulepov <dmitry.dulepov@gmail.com>
Sat, 2 Dec 2006 07:40:16 +0000 (07:40 +0000)
committerDmitry Dulepov <dmitry.dulepov@gmail.com>
Sat, 2 Dec 2006 07:40:16 +0000 (07:40 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@1840 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_db.php

index 6d8d3b8..bc042fb 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2006-12-02  Dmitry Dulepov  <dmitry@typo3.org>
+
+       * t3lib_db: added calls to t3lib_div::sysLog() and t3lib_div::devLog() if recordset is not valid
+
 2006-12-01     Kasper Skårhøj  <kasper2006@typo3.com>
 
        * Additionsl to FlexFormTools
index 8bd17ef..e4dd603 100755 (executable)
@@ -787,6 +787,7 @@ class t3lib_DB {
         * @return      integer         Number of resulting rows.
         */
        function sql_num_rows($res)     {
+               $this->debug_check_recordset($res);
                return mysql_num_rows($res);
        }
 
@@ -799,6 +800,7 @@ class t3lib_DB {
         * @return      array           Associative array of result row.
         */
        function sql_fetch_assoc($res)  {
+               $this->debug_check_recordset($res);
                return mysql_fetch_assoc($res);
        }
 
@@ -812,6 +814,7 @@ class t3lib_DB {
         * @return      array           Array with result rows.
         */
        function sql_fetch_row($res)    {
+               $this->debug_check_recordset($res);
                return mysql_fetch_row($res);
        }
 
@@ -824,6 +827,7 @@ class t3lib_DB {
         * @return      boolean         Returns TRUE on success or FALSE on failure.
         */
        function sql_free_result($res)  {
+               $this->debug_check_recordset($res);
                return mysql_free_result($res);
        }
 
@@ -859,6 +863,7 @@ class t3lib_DB {
         * @return      boolean         Returns TRUE on success or FALSE on failure.
         */
        function sql_data_seek($res,$seek)      {
+               $this->debug_check_recordset($res);
                return mysql_data_seek($res,$seek);
        }
 
@@ -872,6 +877,7 @@ class t3lib_DB {
         * @return      string          Returns the name of the specified field index
         */
        function sql_field_type($res,$pointer)  {
+               $this->debug_check_recordset($res);
                return mysql_field_type($res,$pointer);
        }
 
@@ -1096,6 +1102,27 @@ class t3lib_DB {
                        ));
                }
        }
+
+       /**
+        * Checks if recordset is valid and writes debugging inormation into devLog if not.
+        * 
+        * @param resource $res Recordset
+        * @return boolean <code>false</code> if recordset is not valid
+        */
+       function debug_check_recordset($res) {
+               if (!$res) {
+                       t3lib_div::sysLog('Invalid database recordset detected. Install and enable devLog extension to get a full stack trace!', 'Core', 3);
+                       $trace = false;
+                       if (version_compare(phpversion(), '4.3.0', '>=')) {
+                               $trace = debug_backtrace();
+                               array_shift($trace);
+                       }
+                       t3lib_div::devLog('Invalid recordset detected', 'Core/t3lib_db', 3, $trace);
+                       return false;
+               }
+               return true;
+       }
+
 }