Namespaces

  • Latte
    • Loaders
    • Macros
    • Runtime
  • Nette
    • Application
      • Responses
      • Routers
      • UI
    • Bridges
      • ApplicationDI
      • ApplicationLatte
      • ApplicationTracy
      • CacheDI
      • CacheLatte
      • DatabaseDI
      • DatabaseTracy
      • DITracy
      • FormsDI
      • FormsLatte
      • Framework
      • HttpDI
      • HttpTracy
      • MailDI
      • ReflectionDI
      • SecurityDI
      • SecurityTracy
    • Caching
      • Storages
    • ComponentModel
    • Database
      • Conventions
      • Drivers
      • Reflection
      • Table
    • DI
      • Config
        • Adapters
      • Extensions
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
    • Reflection
    • Security
    • Utils
  • none
  • Tracy
    • Bridges
      • Nette

Classes

  • MsSqlDriver
  • MySqlDriver
  • OciDriver
  • OdbcDriver
  • PgSqlDriver
  • Sqlite2Driver
  • SqliteDriver
  • SqlsrvDriver
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Other releases
  • Nette homepage
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (https://nette.org)
  5:  * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
  6:  */
  7: 
  8: namespace Nette\Database\Drivers;
  9: 
 10: use Nette;
 11: 
 12: 
 13: /**
 14:  * Supplemental Oracle database driver.
 15:  */
 16: class OciDriver extends Nette\Object implements Nette\Database\ISupplementalDriver
 17: {
 18:     /** @var Nette\Database\Connection */
 19:     private $connection;
 20: 
 21:     /** @var string  Datetime format */
 22:     private $fmtDateTime;
 23: 
 24: 
 25:     public function __construct(Nette\Database\Connection $connection, array $options)
 26:     {
 27:         $this->connection = $connection;
 28:         $this->fmtDateTime = isset($options['formatDateTime']) ? $options['formatDateTime'] : 'U';
 29:     }
 30: 
 31: 
 32:     public function convertException(\PDOException $e)
 33:     {
 34:         $code = isset($e->errorInfo[1]) ? $e->errorInfo[1] : NULL;
 35:         if (in_array($code, array(1, 2299, 38911), TRUE)) {
 36:             return Nette\Database\UniqueConstraintViolationException::from($e);
 37: 
 38:         } elseif (in_array($code, array(1400), TRUE)) {
 39:             return Nette\Database\NotNullConstraintViolationException::from($e);
 40: 
 41:         } elseif (in_array($code, array(2266, 2291, 2292), TRUE)) {
 42:             return Nette\Database\ForeignKeyConstraintViolationException::from($e);
 43: 
 44:         } else {
 45:             return Nette\Database\DriverException::from($e);
 46:         }
 47:     }
 48: 
 49: 
 50:     /********************* SQL ****************d*g**/
 51: 
 52: 
 53:     /**
 54:      * Delimites identifier for use in a SQL statement.
 55:      */
 56:     public function delimite($name)
 57:     {
 58:         // @see http://download.oracle.com/docs/cd/B10500_01/server.920/a96540/sql_elements9a.htm
 59:         return '"' . str_replace('"', '""', $name) . '"';
 60:     }
 61: 
 62: 
 63:     /**
 64:      * Formats boolean for use in a SQL statement.
 65:      */
 66:     public function formatBool($value)
 67:     {
 68:         return $value ? '1' : '0';
 69:     }
 70: 
 71: 
 72:     /**
 73:      * Formats date-time for use in a SQL statement.
 74:      */
 75:     public function formatDateTime(/*\DateTimeInterface*/ $value)
 76:     {
 77:         return $value->format($this->fmtDateTime);
 78:     }
 79: 
 80: 
 81:     /**
 82:      * Formats date-time interval for use in a SQL statement.
 83:      */
 84:     public function formatDateInterval(\DateInterval $value)
 85:     {
 86:         throw new Nette\NotSupportedException;
 87:     }
 88: 
 89: 
 90:     /**
 91:      * Encodes string for use in a LIKE statement.
 92:      */
 93:     public function formatLike($value, $pos)
 94:     {
 95:         throw new Nette\NotImplementedException;
 96:     }
 97: 
 98: 
 99:     /**
100:      * Injects LIMIT/OFFSET to the SQL query.
101:      */
102:     public function applyLimit(& $sql, $limit, $offset)
103:     {
104:         if ($limit < 0 || $offset < 0) {
105:             throw new Nette\InvalidArgumentException('Negative offset or limit.');
106: 
107:         } elseif ($offset) {
108:             // see http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html
109:             $sql = 'SELECT * FROM (SELECT t.*, ROWNUM AS "__rnum" FROM (' . $sql . ') t '
110:                 . ($limit !== NULL ? 'WHERE ROWNUM <= ' . ((int) $offset + (int) $limit) : '')
111:                 . ') WHERE "__rnum" > '. (int) $offset;
112: 
113:         } elseif ($limit !== NULL) {
114:             $sql = 'SELECT * FROM (' . $sql . ') WHERE ROWNUM <= ' . (int) $limit;
115:         }
116:     }
117: 
118: 
119:     /**
120:      * Normalizes result row.
121:      */
122:     public function normalizeRow($row)
123:     {
124:         return $row;
125:     }
126: 
127: 
128:     /********************* reflection ****************d*g**/
129: 
130: 
131:     /**
132:      * Returns list of tables.
133:      */
134:     public function getTables()
135:     {
136:         $tables = array();
137:         foreach ($this->connection->query('SELECT * FROM cat') as $row) {
138:             if ($row[1] === 'TABLE' || $row[1] === 'VIEW') {
139:                 $tables[] = array(
140:                     'name' => $row[0],
141:                     'view' => $row[1] === 'VIEW',
142:                 );
143:             }
144:         }
145:         return $tables;
146:     }
147: 
148: 
149:     /**
150:      * Returns metadata for all columns in a table.
151:      */
152:     public function getColumns($table)
153:     {
154:         throw new Nette\NotImplementedException;
155:     }
156: 
157: 
158:     /**
159:      * Returns metadata for all indexes in a table.
160:      */
161:     public function getIndexes($table)
162:     {
163:         throw new Nette\NotImplementedException;
164:     }
165: 
166: 
167:     /**
168:      * Returns metadata for all foreign keys in a table.
169:      */
170:     public function getForeignKeys($table)
171:     {
172:         throw new Nette\NotImplementedException;
173:     }
174: 
175: 
176:     /**
177:      * Returns associative array of detected types (IReflection::FIELD_*) in result set.
178:      */
179:     public function getColumnTypes(\PDOStatement $statement)
180:     {
181:         return Nette\Database\Helpers::detectTypes($statement);
182:     }
183: 
184: 
185:     /**
186:      * @param  string
187:      * @return bool
188:      */
189:     public function isSupported($item)
190:     {
191:         return $item === self::SUPPORT_SEQUENCE || $item === self::SUPPORT_SUBSELECT;
192:     }
193: 
194: }
195: 
Nette 2.3-20161221 API API documentation generated by ApiGen 2.8.0