[dev] horde/scripts/alarms.php

Matt Selsky selsky at columbia.edu
Thu Jul 10 18:56:48 UTC 2008


>> Likely we need to call MDB2's free() on our prepared statements. And we
>> may need to call freePrepared() on the DB prepared statements.
>
> It seems so....

Please try the attached patch.


-- 
Matt
-------------- next part --------------
Index: sql.php
===================================================================
RCS file: /repository/framework/Share/Share/sql.php,v
retrieving revision 1.43
diff -u -r1.43 sql.php
--- sql.php	10 Jul 2008 18:44:06 -0000	1.43
+++ sql.php	10 Jul 2008 18:55:34 -0000
@@ -115,12 +115,12 @@
     function _getShareUsers(&$share)
     {
         if ($this->_hasUsers($share)) {
-            $query = $this->_db->prepare('SELECT user_uid, perm FROM ' . $this->_table . '_users WHERE share_id = ?');
-            if (is_a($query, 'PEAR_Error')) {
-                Horde::logMessage($query, __FILE__, __LINE__, PEAR_LOG_ERR);
-                return $query;
+            $stmt = $this->_db->prepare('SELECT user_uid, perm FROM ' . $this->_table . '_users WHERE share_id = ?');
+            if (is_a($stmt, 'PEAR_Error')) {
+                Horde::logMessage($stmt, __FILE__, __LINE__, PEAR_LOG_ERR);
+                return $stmt;
             }
-            $result = $query->execute(array($share['share_id']));
+            $result = $stmt->execute(array($share['share_id']));
             if (is_a($result, 'PEAR_Error')) {
                 Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
                 return $result;
@@ -129,6 +129,8 @@
                     $share['perm']['users'][$row['user_uid']] = (int)$row['perm'];
                 }
             }
+            $stmt->free();
+            $result->free();
         }
     }
 
@@ -141,12 +143,12 @@
     {
         if ($this->_hasGroups($share)) {
             // Get groups permissions
-            $query = $this->_db->prepare('SELECT group_uid, perm FROM ' . $this->_table . '_groups WHERE share_id = ?');
-            if (is_a($query, 'PEAR_Error')) {
-                Horde::logMessage($query, __FILE__, __LINE__, PEAR_LOG_ERR);
-                return $query;
+            $stmt = $this->_db->prepare('SELECT group_uid, perm FROM ' . $this->_table . '_groups WHERE share_id = ?');
+            if (is_a($stmt, 'PEAR_Error')) {
+                Horde::logMessage($stmt, __FILE__, __LINE__, PEAR_LOG_ERR);
+                return $stmt;
             }
-            $result = $query->execute(array($share['share_id']));
+            $result = $stmt->execute(array($share['share_id']));
             if (is_a($result, 'PEAR_Error')) {
                 Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
                 return $result;
@@ -155,6 +157,8 @@
                     $share['perm']['groups'][(int)$row['group_uid']] = (int)$row['perm'];
                 }
             }
+            $stmt->free();
+            $result->free();
         }
     }
 
@@ -168,12 +172,12 @@
      */
     function &_getShare($name)
     {
-        $query = $this->_db->prepare('SELECT * FROM ' . $this->_table . ' WHERE share_name = ?');
-        if (is_a($query, 'PEAR_Error')) {
-            Horde::logMessage($query, __FILE__, __LINE__, PEAR_LOG_ERR);
-            return $query;
+        $stmt = $this->_db->prepare('SELECT * FROM ' . $this->_table . ' WHERE share_name = ?');
+        if (is_a($stmt, 'PEAR_Error')) {
+            Horde::logMessage($stmt, __FILE__, __LINE__, PEAR_LOG_ERR);
+            return $stmt;
         }
-        $results = $query->execute(array($name));
+        $results = $stmt->execute(array($name));
         if (is_a($results, 'PEAR_Error')) {
             Horde::logMessage($results, __FILE__, __LINE__, PEAR_LOG_ERR);
             return $results;
@@ -185,6 +189,8 @@
         } elseif (empty($data)) {
             return PEAR::RaiseError(sprintf(_("Share \"%s\" does not exist."), $name));
         }
+        $stmt->free();
+        $results->free();
 
         // Convert charset
         $data = $this->_fromDriverCharset($data);
@@ -227,12 +233,12 @@
     function &_getShareById($id)
     {
         $params = array($id);
-        $query = $this->_db->prepare('SELECT * FROM ' . $this->_table . ' WHERE share_id = ?');
-        if (is_a($query, 'PEAR_Error')) {
-            Horde::logMessage($query, __FILE__, __LINE__, PEAR_LOG_ERR);
-            return $query;
+        $stmt = $this->_db->prepare('SELECT * FROM ' . $this->_table . ' WHERE share_id = ?');
+        if (is_a($stmt, 'PEAR_Error')) {
+            Horde::logMessage($stmt, __FILE__, __LINE__, PEAR_LOG_ERR);
+            return $stmt;
         }
-        $results = $query->execute($params);
+        $results = $stmt->execute($params);
         if (is_a($results, 'PEAR_Error')) {
             Horde::logMessage($results, __FILE__, __LINE__, PEAR_LOG_ERR);
             return $results;
@@ -245,6 +251,9 @@
             return PEAR::RaiseError(sprintf(_("Share ID %d does not exist."), $id));
         }
 
+        $stmt->free();
+        $results->free();
+
         // Convert charset
         $data = $this->_fromDriverCharset($data);
 
@@ -560,16 +569,18 @@
         foreach ($tables as $table) {
 
             /* Remove the share entry */
-            $query = $this->_write_db->prepare('DELETE FROM ' . $table . ' WHERE share_id = ?', null, MDB2_PREPARE_MANIP);
-            if (is_a($query, 'PEAR_Error')) {
-                Horde::logMessage($query, __FILE__, __LINE__, PEAR_LOG_ERR);
-                return $query;
+            $stmt = $this->_write_db->prepare('DELETE FROM ' . $table . ' WHERE share_id = ?', null, MDB2_PREPARE_MANIP);
+            if (is_a($stmt, 'PEAR_Error')) {
+                Horde::logMessage($stmt, __FILE__, __LINE__, PEAR_LOG_ERR);
+                return $stmt;
             }
-            $result = $query->execute($params);
+            $result = $stmt->execute($params);
             if (is_a($result, 'PEAR_Error')) {
                 Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
                 return $result;
             }
+            $stmt->free();
+            $result->free();
         }
 
         return true;
@@ -584,19 +595,25 @@
      */
     function _exists($share)
     {
-        $query = $this->_db->prepare('SELECT 1 FROM ' . $this->_table
+        $stmt = $this->_db->prepare('SELECT 1 FROM ' . $this->_table
                  . ' WHERE share_name = ?');
 
-        if (is_a($query, 'PEAR_Error')) {
-            Horde::logMessage($query, __FILE__, __LINE__, PEAR_LOG_ERR);
-            return $query;
+        if (is_a($stmt, 'PEAR_Error')) {
+            Horde::logMessage($stmt, __FILE__, __LINE__, PEAR_LOG_ERR);
+            return $stmt;
         }
-        $result = $query->execute(array($share));
+        $result = $stmt->execute(array($share));
         if (is_a($result, 'PEAR_Error')) {
             Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
             return $result;
         }
-        return (bool)$result->fetchOne();
+
+        $exists = (bool)$result->fetchOne();
+
+        $stmt->free();
+        $result->free();
+
+        return $exists;
     }
 
     /**
@@ -939,28 +956,32 @@
             $query = 'UPDATE ' . $table . ' SET ' . implode(' = ?, ', $fields) . ' = ? WHERE share_id = ?';
             $params[] = $this->data['share_id'];
         }
-        $query = $db->prepare($query, null, MDB2_PREPARE_MANIP);
-        if (is_a($query, 'PEAR_Error')) {
-            Horde::logMessage($query, __FILE__, __LINE__, PEAR_LOG_ERR);
-            return $query;
+        $stmt = $db->prepare($query, null, MDB2_PREPARE_MANIP);
+        if (is_a($stmt, 'PEAR_Error')) {
+            Horde::logMessage($stmt, __FILE__, __LINE__, PEAR_LOG_ERR);
+            return $stmt;
         }
-        $result = $query->execute($params);
+        $result = $stmt->execute($params);
         if (is_a($result, 'PEAR_Error')) {
             Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
             return $result;
         }
+        $stmt->free();
+        $result->free();
 
         // Update the share's user permissions
-        $query = $db->prepare('DELETE FROM ' . $table . '_users WHERE share_id = ?', null, MDB2_PREPARE_MANIP);
-        if (is_a($query, 'PEAR_Error')) {
-            Horde::logMessage($query, __FILE__, __LINE__, PEAR_LOG_ERR);
-            return $query;
+        $stmt = $db->prepare('DELETE FROM ' . $table . '_users WHERE share_id = ?', null, MDB2_PREPARE_MANIP);
+        if (is_a($stmt, 'PEAR_Error')) {
+            Horde::logMessage($stmt, __FILE__, __LINE__, PEAR_LOG_ERR);
+            return $stmt;
         }
-        $result = $query->execute(array($this->data['share_id']));
+        $result = $stmt->execute(array($this->data['share_id']));
         if (is_a($result, 'PEAR_Error')) {
             Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
             return $result;
         }
+        $stmt->free();
+        $result->free();
 
         if (!empty($this->data['perm']['users']) ||
             !empty($this->data['perm']['groups'])) {
@@ -983,19 +1004,23 @@
                 Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
                 return $result;
             }
+            $stmt->free();
+            $result->free();
         }
 
         // Update the share's group permissions
-        $query = $db->prepare('DELETE FROM ' . $table . '_groups WHERE share_id = ?', null, MDB2_PREPARE_MANIP);
-        if (is_a($query, 'PEAR_Error')) {
-            Horde::logMessage($query, __FILE__, __LINE__, PEAR_LOG_ERR);
-            return $query;
+        $stmt = $db->prepare('DELETE FROM ' . $table . '_groups WHERE share_id = ?', null, MDB2_PREPARE_MANIP);
+        if (is_a($stmt, 'PEAR_Error')) {
+            Horde::logMessage($stmt, __FILE__, __LINE__, PEAR_LOG_ERR);
+            return $stmt;
         }
-        $result = $query->execute(array($this->data['share_id']));
+        $result = $stmt->execute(array($this->data['share_id']));
         if (is_a($result, 'PEAR_Error')) {
             Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
             return $result;
         }
+        $stmt->free();
+        $result->free();
 
         if (!empty($this->data['perm']['groups'])) {
             $data = array();
@@ -1012,6 +1037,8 @@
                 Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
                 return $result;
             }
+            $stmt->free();
+            $result->free();
         }
 
         return true;


More information about the dev mailing list