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
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
    • Reflection
    • Security
    • Templating
    • Utils
  • NetteModule
  • none
  • Tracy
    • Bridges
      • Nette

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 (http://nette.org)
  5:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
  6:  */
  7: 
  8: namespace Nette\Database\Drivers;
  9: 
 10: use Nette;
 11: 
 12: 
 13: /**
 14:  * Supplemental Oracle database driver.
 15:  *
 16:  * @author     David Grudl
 17:  */
 18: class OciDriver extends Nette\Object implements Nette\Database\ISupplementalDriver
 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, array(1, 2299, 38911), TRUE)) {
 38:             return Nette\Database\UniqueConstraintViolationException::from($e);
 39: 
 40:         } elseif (in_array($code, array(1400), TRUE)) {
 41:             return Nette\Database\NotNullConstraintViolationException::from($e);
 42: 
 43:         } elseif (in_array($code, array(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 ($offset > 0) {
107:             // see http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html
108:             $sql = 'SELECT * FROM (SELECT t.*, ROWNUM AS "__rnum" FROM (' . $sql . ') t '
109:                 . ($limit >= 0 ? 'WHERE ROWNUM <= ' . ((int) $offset + (int) $limit) : '')
110:                 . ') WHERE "__rnum" > '. (int) $offset;
111: 
112:         } elseif ($limit >= 0) {
113:             $sql = 'SELECT * FROM (' . $sql . ') WHERE ROWNUM <= ' . (int) $limit;
114:         }
115:     }
116: 
117: 
118:     /**
119:      * Normalizes result row.
120:      */
121:     public function normalizeRow($row)
122:     {
123:         return $row;
124:     }
125: 
126: 
127:     /********************* reflection ****************d*g**/
128: 
129: 
130:     /**
131:      * Returns list of tables.
132:      */
133:     public function getTables()
134:     {
135:         $tables = array();
136:         foreach ($this->connection->query('SELECT * FROM cat') as $row) {
137:             if ($row[1] === 'TABLE' || $row[1] === 'VIEW') {
138:                 $tables[] = array(
139:                     'name' => $row[0],
140:                     'view' => $row[1] === 'VIEW',
141:                 );
142:             }
143:         }
144:         return $tables;
145:     }
146: 
147: 
148:     /**
149:      * Returns metadata for all columns in a table.
150:      */
151:     public function getColumns($table)
152:     {
153:         throw new Nette\NotImplementedException;
154:     }
155: 
156: 
157:     /**
158:      * Returns metadata for all indexes in a table.
159:      */
160:     public function getIndexes($table)
161:     {
162:         throw new Nette\NotImplementedException;
163:     }
164: 
165: 
166:     /**
167:      * Returns metadata for all foreign keys in a table.
168:      */
169:     public function getForeignKeys($table)
170:     {
171:         throw new Nette\NotImplementedException;
172:     }
173: 
174: 
175:     /**
176:      * Returns associative array of detected types (IReflection::FIELD_*) in result set.
177:      */
178:     public function getColumnTypes(\PDOStatement $statement)
179:     {
180:         return Nette\Database\Helpers::detectTypes($statement);
181:     }
182: 
183: 
184:     /**
185:      * @param  string
186:      * @return bool
187:      */
188:     public function isSupported($item)
189:     {
190:         return $item === self::SUPPORT_SEQUENCE || $item === self::SUPPORT_SUBSELECT;
191:     }
192: 
193: }
194: 
Nette 2.3.1 API API documentation generated by ApiGen 2.8.0