cvs: pear /MDB2 package_pgsql.php /MDB2/MDB2/Driver pgsql.php

From: Date: Sat, 14 Oct 2006 20:00:26 +0000
Subject: cvs: pear /MDB2 package_pgsql.php /MDB2/MDB2/Driver pgsql.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-42575@lists.php.net to get a copy of this message
quipo Sat Oct 14 20:00:26 2006 UTC Modified files: /pear/MDB2/MDB2/Driver pgsql.php /pear/MDB2 package_pgsql.php Log: fixed _modifyQuery() for manipulation queries (please test) http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/pgsql.php?r1=1.159&r2=1.160&diff_format=u Index: pear/MDB2/MDB2/Driver/pgsql.php diff -u pear/MDB2/MDB2/Driver/pgsql.php:1.159 pear/MDB2/MDB2/Driver/pgsql.php:1.160 --- pear/MDB2/MDB2/Driver/pgsql.php:1.159 Sat Oct 14 16:21:15 2006 +++ pear/MDB2/MDB2/Driver/pgsql.php Sat Oct 14 20:00:26 2006 @@ -43,7 +43,7 @@ // | Author: Paul Cooper <pgc@ucecom.com> | // +----------------------------------------------------------------------+ // -// $Id: pgsql.php,v 1.159 2006/10/14 16:21:15 lsmith Exp $ +// $Id: pgsql.php,v 1.160 2006/10/14 20:00:26 quipo Exp $ /** * MDB2 PostGreSQL driver @@ -683,19 +683,44 @@ $query = substr($query, 0, -1); } if ($is_manip) { -/* -todo: add missing preg_match() all to build $match - $manip = preg_replace('/^(DELETE FROM|UPDATE).*$/', '\\1', $query); - $from = $match[2]; - $where = $match[3]; - $query = $manip.' '.$from.' WHERE ctid=(SELECT ctid FROM '.$from.' '.$where.' LIMIT '.$limit.')'; -*/ + $query = $this->_modifyManipQuery($query, $limit); } else { $query.= " LIMIT $limit OFFSET $offset"; } } return $query; } + + // }}} + // {{{ _modifyManipQuery() + + /** + * Changes a manip query string for various DBMS specific reasons + * + * @param string $query query to modify + * @param integer $limit limit the number of rows + * @return string modified query + * @access protected + */ + function _modifyManipQuery($query, $limit) + { + $pos = strpos(strtolower($query), 'where'); + $where = $pos ? substr($query, $pos) : ''; + + $manip_clause = '(\bDELETE\b\s+(?:\*\s+)?\bFROM\b|\bUPDATE\b)'; + $from_clause = '([\w\.]+)'; + $where_clause = '(?:(.*)\bWHERE\b\s+(.*))|(.*)'; + $pattern = '/^'. $manip_clause . '\s+' . $from_clause .'(?:\s)*(?:'. $where_clause .')?$/i'; + $matches = preg_match($pattern, $query, $match); + if ($matches) { + $manip = $match[1]; + $from = $match[2]; + $what = (count($matches) == 6) ? $match[5] : $match[3]; + return $manip.' '.$from.' '.$what.' WHERE ctid=(SELECT ctid FROM '.$from.' '.$where.' LIMIT '.$limit.')'; + } + //return error? + return $query; + } // }}} // {{{ getServerVersion() http://cvs.php.net/viewvc.cgi/pear/MDB2/package_pgsql.php?r1=1.85&r2=1.86&diff_format=u Index: pear/MDB2/package_pgsql.php diff -u pear/MDB2/package_pgsql.php:1.85 pear/MDB2/package_pgsql.php:1.86 --- pear/MDB2/package_pgsql.php:1.85 Tue Sep 5 13:55:13 2006 +++ pear/MDB2/package_pgsql.php Sat Oct 14 20:00:26 2006 @@ -4,6 +4,7 @@ $version = 'YYY'; $notes = <<<EOT +- fixed _modifyQuery() for manipulation queries open todo items: - enable pg_execute() once issues with bytea column are resolved

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