| 1 | <?php |
| 2 | /* |
| 3 | * $Id: Oracle.php 2963 2007-10-21 06:23:59Z Jonathan.Wage $ |
| 4 | * |
| 5 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 6 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 7 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 8 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 9 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 10 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 11 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 12 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 13 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 14 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 15 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 16 | * |
| 17 | * This software consists of voluntary contributions made by many individuals |
| 18 | * and is licensed under the LGPL. For more information, see |
| 19 | * <http://www.phpdoctrine.org>. |
| 20 | */ |
| 21 | Doctrine::autoload('Doctrine_Connection'); |
| 22 | /** |
| 23 | * Doctrine_Connection_Oracle |
| 24 | * |
| 25 | * @package Doctrine |
| 26 | * @subpackage Connection |
| 27 | * @license http://www.opensource.org/licenses/lgpl-license.php LGPL |
| 28 | * @link www.phpdoctrine.org |
| 29 | * @since 1.0 |
| 30 | * @version $Revision: 2963 $ |
| 31 | * @author Konsta Vesterinen <kvesteri@cc.hut.fi> |
| 32 | */ |
| 33 | class Doctrine_Connection_Oracle extends Doctrine_Connection |
| 34 | { |
| 35 | /** |
| 36 | * @var string $driverName the name of this connection driver |
| 37 | */ |
| 38 | protected $driverName = 'Oracle'; |
| 39 | |
| 40 | public function __construct(Doctrine_Manager $manager, $adapter) |
| 41 | { |
| 42 | $this->supported = array( |
| 43 | 'sequences' => true, |
| 44 | 'indexes' => true, |
| 45 | 'summary_functions' => true, |
| 46 | 'order_by_text' => true, |
| 47 | 'current_id' => true, |
| 48 | 'affected_rows' => true, |
| 49 | 'transactions' => true, |
| 50 | 'savepoints' => true, |
| 51 | 'limit_queries' => true, |
| 52 | 'LOBs' => true, |
| 53 | 'replace' => 'emulated', |
| 54 | 'sub_selects' => true, |
| 55 | 'auto_increment' => false, // implementation is broken |
| 56 | 'primary_key' => true, |
| 57 | 'result_introspection' => true, |
| 58 | 'prepared_statements' => true, |
| 59 | 'identifier_quoting' => true, |
| 60 | 'pattern_escaping' => true, |
| 61 | ); |
| 62 | /** |
| 63 | $this->options['DBA_username'] = false; |
| 64 | $this->options['DBA_password'] = false; |
| 65 | $this->options['database_name_prefix'] = false; |
| 66 | $this->options['emulate_database'] = true; |
| 67 | $this->options['default_tablespace'] = false; |
| 68 | $this->options['default_text_field_length'] = 2000; |
| 69 | $this->options['result_prefetching'] = false; |
| 70 | */ |
| 71 | parent::__construct($manager, $adapter); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Sets up the date/time format |
| 76 | * |
| 77 | */ |
| 78 | public function setDateFormat($format = 'YYYY-MM-DD HH24:MI:SS') |
| 79 | { |
| 80 | $this->exec('ALTER SESSION SET NLS_DATE_FORMAT = "' . $format . '"'); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Adds an driver-specific LIMIT clause to the query |
| 85 | * |
| 86 | * @param string $query query to modify |
| 87 | * @param integer $limit limit the number of rows |
| 88 | * @param integer $offset start reading from given offset |
| 89 | * @return string the modified query |
| 90 | */ |
| 91 | public function modifyLimitQuery($query, $limit, $offset) |
| 92 | { |
| 93 | /** |
| 94 | $e = explode("select ",strtolower($query)); |
| 95 | $e2 = explode(" from ",$e[1]); |
| 96 | $fields = $e2[0]; |
| 97 | */ |
| 98 | $limit = (int) $limit; |
| 99 | $offset = (int) $offset; |
| 100 | if (preg_match('/^\s*SELECT/i', $query)) { |
| 101 | if ( ! preg_match('/\sFROM\s/i', $query)) { |
| 102 | $query .= " FROM dual"; |
| 103 | } |
| 104 | if ($limit > 0) { |
| 105 | // taken from http://svn.ez.no/svn/ezcomponents/packages/Database |
| 106 | $max = $offset + $limit; |
| 107 | if ($offset > 0) { |
| 108 | $min = $offset + 1; |
| 109 | $query = 'SELECT * FROM (SELECT a.*, ROWNUM dctrn_rownum FROM (' . $query |
| 110 | . ') a WHERE ROWNUM <= ' . $max . ') WHERE dctrn_rownum >= ' . $min; |
| 111 | } else { |
| 112 | $query = 'SELECT a.* FROM (' . $query .') a WHERE ROWNUM <= ' . $max; |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | return $query; |
| 117 | } |
| 118 | } |