1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (http://nette.org)
5: *
6: * Copyright (c) 2004, 2011 David Grudl (http://davidgrudl.com)
7: *
8: * For the full copyright and license information, please view
9: * the file license.txt that was distributed with this source code.
10: */
11:
12: namespace Nette\Database\Drivers;
13:
14: use Nette;
15:
16:
17:
18: /**
19: * Supplemental Oracle database driver.
20: *
21: * @author David Grudl
22: */
23: class OciDriver extends Nette\Object implements Nette\Database\ISupplementalDriver
24: {
25: /** @var array */
26: public $supports = array('meta' => TRUE);
27:
28: /** @var Nette\Database\Connection */
29: private $connection;
30:
31: /** @var string Datetime format */
32: private $fmtDateTime;
33:
34:
35:
36: public function __construct(Nette\Database\Connection $connection, array $options)
37: {
38: $this->connection = $connection;
39: $this->fmtDateTime = isset($options['formatDateTime']) ? $options['formatDateTime'] : 'U';
40: }
41:
42:
43:
44: /********************* SQL ****************d*g**/
45:
46:
47:
48: /**
49: * Delimites identifier for use in a SQL statement.
50: */
51: public function delimite($name)
52: {
53: // @see http://download.oracle.com/docs/cd/B10500_01/server.920/a96540/sql_elements9a.htm
54: return '"' . str_replace('"', '""', $name) . '"';
55: }
56:
57:
58:
59: /**
60: * Formats date-time for use in a SQL statement.
61: */
62: public function formatDateTime(\DateTime $value)
63: {
64: return $value->format($this->fmtDateTime);
65: }
66:
67:
68:
69: /**
70: * Encodes string for use in a LIKE statement.
71: */
72: public function formatLike($value, $pos)
73: {
74: throw new Nette\NotImplementedException;
75: }
76:
77:
78:
79: /**
80: * Injects LIMIT/OFFSET to the SQL query.
81: */
82: public function applyLimit(&$sql, $limit, $offset)
83: {
84: if ($offset > 0) {
85: // see http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html
86: $sql = 'SELECT * FROM (SELECT t.*, ROWNUM AS "__rnum" FROM (' . $sql . ') t '
87: . ($limit >= 0 ? 'WHERE ROWNUM <= ' . ((int) $offset + (int) $limit) : '')
88: . ') WHERE "__rnum" > '. (int) $offset;
89:
90: } elseif ($limit >= 0) {
91: $sql = 'SELECT * FROM (' . $sql . ') WHERE ROWNUM <= ' . (int) $limit;
92: }
93: }
94:
95:
96:
97: /**
98: * Normalizes result row.
99: */
100: public function normalizeRow($row, $statement)
101: {
102: return $row;
103: }
104:
105: }
106: