[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pear-cvs
Subject:    [PEAR-CVS] =?utf-8?q?svn:_/pear/packages/DB=5FDataObject/trunk/DB/_DataObject.php?=
From:       Alan_Knowles <alan_k () php ! net>
Date:       2014-12-18 11:15:25
Message-ID: svn-alan_k-1418901325-335309-1640409531 () svn ! php ! net
[Download RAW message or body]

alan_k                                   Thu, 18 Dec 2014 11:15:25 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=335309

Log:
suuport for useindex (mysql only) and fix static infront of depricated staticget() method

Changed paths:
    U   pear/packages/DB_DataObject/trunk/DB/DataObject.php

Modified: pear/packages/DB_DataObject/trunk/DB/DataObject.php
===================================================================
--- pear/packages/DB_DataObject/trunk/DB/DataObject.php	2014-12-18 06:57:48 UTC (rev 335308)
+++ pear/packages/DB_DataObject/trunk/DB/DataObject.php	2014-12-18 11:15:25 UTC (rev 335309)
@@ -346,7 +346,7 @@
                $this->_query['derive_select']
                .' FROM ( SELECT'.
                     $this->_query['data_select'] . " \n" .
-                    " FROM   $tn \n" .
+                    " FROM   $tn  " . $this->_query['useindex'] . " \n" .
                     $this->_join . " \n" .
                     $this->_query['condition'] . " \n" .
                     $this->_query['group_by'] . " \n" .
@@ -362,7 +362,7 @@

         $sql = 'SELECT ' .
             $this->_query['data_select'] . " \n" .
-            " FROM   $tn \n" .
+            " FROM   $tn  " . $this->_query['useindex'] . " \n" .
             $this->_join . " \n" .
             $this->_query['condition'] . " \n" .
             $this->_query['group_by'] . " \n" .
@@ -863,6 +863,43 @@
     }

     /**
+     * Adds a using Index
+     *
+     * $object->useIndex(); //reset the use Index
+     * $object->useIndex("some_index");
+     *
+     * Note do not put unfiltered user input into theis method.
+     * This is mysql specific at present? - might need altering to support other databases.
+     *
+     * @param  string|array  $index  index or indexes to use.
+     * @access public
+     * @return none|PEAR::Error - invalid args only
+     */
+    function useIndex($index = false)
+    {
+        if ($this->_query === false) {
+            $this->raiseError(
+                "You cannot do two queries on the same object (copy it before finding)",
+                DB_DATAOBJECT_ERROR_INVALIDARGS);
+            return false;
+        }
+        if ($index=== false) {
+            $this->_query['useindex'] = '';
+            return;
+        }
+        // check input...= 0 or '    ' == error!
+        if ((is_string($index) && !trim($index)) || (is_array($index) && !count($index)) ) {
+            return $this->raiseError("Having: No Valid Arguments", DB_DATAOBJECT_ERROR_INVALIDARGS);
+        }
+        $index = is_array($index) ? implode(', ', $index) : $index;
+
+        if (!$this->_query['useindex']) {
+            $this->_query['useindex'] = " USE INDEX ({$index}) ";
+            return;
+        }
+        $this->_query['useindex'] =  substr($this->_query['useindex'],0, -2) . ", {$index}) ";
+    }
+    /**
      * Sets the Limit
      *
      * $boject->limit(); // clear limit
@@ -1808,6 +1845,7 @@
         'group_by'    => '', // the GROUP BY condition
         'order_by'    => '', // the ORDER BY condition
         'having'      => '', // the HAVING condition
+        'useindex'   => '', // the USE INDEX condition
         'limit_start' => '', // the LIMIT condition
         'limit_count' => '', // the LIMIT condition
         'data_select' => '*', // the columns to be SELECTed
@@ -4779,7 +4817,7 @@
     /**
      * (deprecated - use ::get / and your own caching method)
      */
-    function staticGet($class, $k, $v = null)
+    static function staticGet($class, $k, $v = null)
     {
         $lclass = strtolower($class);
         global $_DB_DATAOBJECT;



-- 
PEAR CVS Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic