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
      • Table
    • DI
      • Config
        • Adapters
      • Extensions
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
    • Reflection
    • Security
    • Tokenizer
    • Utils
  • Tracy
    • Bridges
      • Nette
  • none

Classes

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