cvs: php4 /pear/DB oci8.php

From: Date: Fri, 30 Nov 2001 01:29:06 +0000
Subject: cvs: php4 /pear/DB oci8.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-1435@lists.php.net to get a copy of this message
cox Thu Nov 29 20:29:06 2001 EDT Modified files: /php4/pear/DB oci8.php Log: Why try to guess the resultant column names when Oracle could return it with this littles trick? Now the limit support for Oracle should be fast and complete Index: php4/pear/DB/oci8.php diff -u php4/pear/DB/oci8.php:1.37 php4/pear/DB/oci8.php:1.38 --- php4/pear/DB/oci8.php:1.37 Thu Nov 29 13:46:34 2001 +++ php4/pear/DB/oci8.php Thu Nov 29 20:29:06 2001 @@ -17,7 +17,7 @@ // | | // +----------------------------------------------------------------------+ // -// $Id: oci8.php,v 1.37 2001/11/29 18:46:34 cox Exp $ +// $Id: oci8.php,v 1.38 2001/11/30 01:29:06 cox Exp $ // // Database independent query interface definition for PHP's Oracle 8 // call-interface extension. @@ -520,10 +520,6 @@ */ function modifyLimitQuery($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]; @@ -531,43 +527,24 @@ } else { $orderby = ''; } - - // Field parsing: Try to find final column names - $fa = array(); - $grab = true; - $is_function = false; - $tmpbuff = ''; - for ($i = 0; $i < strlen($f); $i++) { - if ($f{$i} == '(') { //don't parse commas acting as func params - $grab = false; - $is_function = true; - } elseif ($f{$i} == ')') { - $grab = true; - } - if (preg_match('/\sAS\s/i', substr($tmpbuff, -4))) { - $tmpbuff = ''; - } - if ($f{$i} == ',' && $grab) { - if ($is_function) { - // Oracle names function cols without alias as they are: - // count(foo) will be converted to column "COUNT(FOO)" - $tmpbuff = '"' . strtoupper($tmpbuff) . '"'; - $is_function = false; - } - $fa[] = $tmpbuff; - $tmpbuff = ''; - continue; - } - $tmpbuff .= $f{$i}; + // Let Oracle return the name of the columns instead of + // being coding a "home" SQL parser + $q_fields = "SELECT * FROM ($query) WHERE NULL = NULL"; + if (!$result = OCIParse($this->connection, $q_fields)) { + return $this->oci8RaiseError(); } - if ($is_function) { - $tmpbuff = '"' . strtoupper($tmpbuff) . '"'; + if (!$success = OCIExecute($result, OCI_DEFAULT)) { + return $this->oci8RaiseError($result); } - $fa[] = $tmpbuff; - $fields = implode(', ', $fa); - + $ncols = OCINumCols($result); + for ( $i = 1; $i <= $ncols; $i++ ) { + $cols[] = OCIColumnName($result, $i); + } + $fields = implode(',', $cols); // Construct the query // more at: http://marc.theaimsgroup.com/?l=php-db&m=99831958101212&w=2 + // Perhaps this could be optimized with the use of Unions + $from += 1; // in Oracle rownum starts at 1 $query = "SELECT $fields FROM". " (SELECT rownum as linenum, $fields FROM". " ($query)".

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