fmsystem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fmsystem-commits] [14598] generalize


From: Sigurd Nes
Subject: [Fmsystem-commits] [14598] generalize
Date: Mon, 14 Dec 2015 16:04:43 +0000

Revision: 14598
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=14598
Author:   sigurdne
Date:     2015-12-14 16:04:42 +0000 (Mon, 14 Dec 2015)
Log Message:
-----------
generalize

Modified Paths:
--------------
    branches/dev-syncromind/phpgwapi/inc/class.db.inc.php
    branches/dev-syncromind/phpgwapi/inc/class.db_pdo.inc.php

Modified: branches/dev-syncromind/phpgwapi/inc/class.db.inc.php
===================================================================
--- branches/dev-syncromind/phpgwapi/inc/class.db.inc.php       2015-12-14 
12:57:08 UTC (rev 14597)
+++ branches/dev-syncromind/phpgwapi/inc/class.db.inc.php       2015-12-14 
16:04:42 UTC (rev 14598)
@@ -280,6 +280,54 @@
                abstract public function query($sql, $line = '', $file = '', 
$exec = false, $fetch_single = false);
 
                /**
+               * Get the limit statement for a query with limited result set
+               *
+               * @param string $sql the query to be executed
+               * @param integer $offset row to start from
+               * @param integer $num_rows number of rows to return (optional), 
if unset will use 
$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']
+               * @return string offset and limit
+               */
+               function get_offset($sql = '', $offset, $num_rows = 0)
+               {
+                       $offset         = (int)$offset;
+                       $num_rows       = (int)$num_rows;
+
+                       if ($num_rows == 0)
+                       {
+                               $maxmatches = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
+                               $num_rows = isset($maxmatches) && $maxmatches ? 
(int)$maxmatches : 15;
+                       }
+
+                       switch ( $this->Type )
+                       {
+                               case 'mssql':
+                                       $sql = str_replace('SELECT ', 'SELECT 
TOP ', $sql);
+                                       $sql = str_replace('SELECT TOP 
DISTINCT', 'SELECT DISTINCT TOP ', $sql);
+                                       $sql = str_replace('TOP ', 'TOP ' . 
($offset + $num_rows) . ' ', $sql);
+                                       break;
+                               case 'oci8':
+                               case 'oracle':
+                                       
//http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html
+                                       //http://dibiphp.com
+                                       if ($offset > 0)
+                                       {
+                                               $sql = 'SELECT * FROM (SELECT 
t.*, ROWNUM AS "__rownum" FROM (' . $sql . ') t ' . ($num_rows >= 0 ? 'WHERE 
ROWNUM <= '
+                                                . ( $offset + $num_rows) : '') 
. ') WHERE "__rownum" > '.  $offset;
+                                       }
+                                       elseif ($num_rows >= 0)
+                                       {
+                                               $sql = "SELECT * FROM ({$sql}) 
WHERE ROWNUM <= {$num_rows}";
+                                       }
+
+                                       break;
+                               default:
+                                       $sql .= " LIMIT {$num_rows}";
+                                       $sql .=  $offset ? " OFFSET {$offset}" 
: '';
+                       }
+                       return $sql;
+               }
+
+               /**
                * Execute a query with limited result set
                *
                * @param string $Query_String the query to be executed

Modified: branches/dev-syncromind/phpgwapi/inc/class.db_pdo.inc.php
===================================================================
--- branches/dev-syncromind/phpgwapi/inc/class.db_pdo.inc.php   2015-12-14 
12:57:08 UTC (rev 14597)
+++ branches/dev-syncromind/phpgwapi/inc/class.db_pdo.inc.php   2015-12-14 
16:04:42 UTC (rev 14598)
@@ -437,54 +437,6 @@
                }
 
                /**
-               * Get the limit statement for a query with limited result set
-               *
-               * @param string $sql the query to be executed
-               * @param integer $offset row to start from
-               * @param integer $num_rows number of rows to return (optional), 
if unset will use 
$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']
-               * @return string offset and limit
-               */
-               function get_offset($sql = '', $offset, $num_rows = 0)
-               {
-                       $offset         = (int)$offset;
-                       $num_rows       = (int)$num_rows;
-
-                       if ($num_rows == 0)
-                       {
-                               $maxmatches = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
-                               $num_rows = isset($maxmatches) && $maxmatches ? 
(int)$maxmatches : 15;
-                       }
-
-                       switch ( $this->Type )
-                       {
-                               case 'mssql':
-                                       $sql = str_replace('SELECT ', 'SELECT 
TOP ', $sql);
-                                       $sql = str_replace('SELECT TOP 
DISTINCT', 'SELECT DISTINCT TOP ', $sql);
-                                       $sql = str_replace('TOP ', 'TOP ' . 
($offset + $num_rows) . ' ', $sql);
-                                       break;
-                               case 'oci8':
-                               case 'oracle':
-                                       
//http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html
-                                       //http://dibiphp.com
-                                       if ($offset > 0)
-                                       {
-                                               $sql = 'SELECT * FROM (SELECT 
t.*, ROWNUM AS "__rownum" FROM (' . $sql . ') t ' . ($num_rows >= 0 ? 'WHERE 
ROWNUM <= '
-                                                . ( $offset + $num_rows) : '') 
. ') WHERE "__rownum" > '.  $offset;
-                                       }
-                                       elseif ($num_rows >= 0)
-                                       {
-                                               $sql = "SELECT * FROM ({$sql}) 
WHERE ROWNUM <= {$num_rows}";
-                                       }
-
-                                       break;
-                               default:
-                                       $sql .= " LIMIT {$num_rows}";
-                                       $sql .=  $offset ? " OFFSET {$offset}" 
: '';
-                       }
-                       return $sql;
-               }
-
-               /**
                * Execute a query with limited result set
                *
                * @param string $sql the query to be executed
@@ -499,7 +451,7 @@
                {
                        $this->_get_fetchmode();
 
-                       $sql = $this->get_offset($sql, $offset, $num_rows);
+                       $sql = parent::get_offset($sql, $offset, $num_rows);
 
                        if ($this->debug)
                        {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]