cvs: php4 /pear/DB oci8.php

From: Date: Thu, 01 Nov 2001 13:06:26 +0000
Subject: cvs: php4 /pear/DB oci8.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-1226@lists.php.net to get a copy of this message
cox Thu Nov 1 08:06:26 2001 EDT Modified files: /php4/pear/DB oci8.php Log: Added row limit support for Oracle (untested) Index: php4/pear/DB/oci8.php diff -u php4/pear/DB/oci8.php:1.34 php4/pear/DB/oci8.php:1.35 --- php4/pear/DB/oci8.php:1.34 Thu Nov 1 03:54:25 2001 +++ php4/pear/DB/oci8.php Thu Nov 1 08:06:26 2001 @@ -17,7 +17,7 @@ // | | // +----------------------------------------------------------------------+ // -// $Id: oci8.php,v 1.34 2001/11/01 08:54:25 cox Exp $ +// $Id: oci8.php,v 1.35 2001/11/01 13:06:26 cox Exp $ // // Database independent query interface definition for PHP's Oracle 8 // call-interface extension. @@ -55,7 +55,7 @@ 'prepare' => false, 'pconnect' => true, 'transactions' => true, - 'limit' => false + 'limit' => 'alter' ); $this->errorcode_map = array( 900 => DB_ERROR_SYNTAX, @@ -505,6 +505,69 @@ return $query; } + // }}} + // {{{ modifyLimitQuery() + + /** + * Emulate the row limit support altering the query + * + * @param string $query The query to treat + * @param int $from The row to start to fetch from + * @param int $count The offset + * @return string The modified query + * + * @author Tomas V.V.Cox <cox@idecnet.com> + */ + function modifyQuery($query, $from, $count) + { + // Find fields (supports UNIONs also) + $t = preg_split('/\s+FROM\s+/is', $query); + $f = preg_replace('/^\s*SELECT\s+/is', '', $t[0]); + + // Put the "Order by" statement at the end of the final query + if (preg_match('/\s+ORDER\s+BY\s+.*/is', $query, $match)) { + $orderby = $match[0]; + $query = substr($query, 0, -1 * strlen($orderby)); + } else { + $orderby = ''; + } + + // Field parsing: Try to find final column names + $fa = array(); + $grab = true; + $tmpbuff = ''; + for ($i = 0; $i < strlen($f); $i++) { + // Probably doesn't work if the query contains a funcion without + // alias ("AS"), for ex: to_char(...) as date + if ($f{$i} == '(') { //don't parse commas acting as func params + $grab = false; + } elseif ($f{$i} == ')') { + $grab = true; + } + if (preg_match('/\sAS\s/i', substr($tmpbuff, -4))) { + $tmpbuff = ''; + } + if ($f{$i} == ',' && $grab) { + $fa[] = $tmpbuff; + $tmpbuff = ''; + continue; + } + $tmpbuff .= $f{$i}; + } + $fa[] = $tmpbuff; + $fields = implode(', ', $fa); + + // Construct the query + // more at: http://marc.theaimsgroup.com/?l=php-db&m=99831958101212&w=2 + $query = "SELECT $fields FROM". + " (SELECT rownum as linenum, $fields FROM". + " ($query)". + " ) ". + "WHERE linenum BETWEEN $from AND ". ($from + $count) . + "$orderby"; + + return $query; + } // }}} // {{{ nextId()

« previous php.pear.cvs (#1226) next »