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 PdoOciDriver extends Nette\Object implements Nette\Database\ISupplementalDriver
24: {
25: /** @var Nette\Database\Connection */
26: private $connection;
27:
28: /** @var string Datetime format */
29: private $fmtDateTime;
30:
31:
32:
33: public function __construct(Nette\Database\Connection $connection, array $options)
34: {
35: $this->connection = $connection;
36: $this->fmtDateTime = isset($options['formatDateTime']) ? $options['formatDateTime'] : 'U';
37: }
38:
39:
40:
41: /********************* SQL ****************d*g**/
42:
43:
44:
45: /**
46: * Delimites identifier for use in a SQL statement.
47: */
48: public function delimite($name)
49: {
50: // @see http://download.oracle.com/docs/cd/B10500_01/server.920/a96540/sql_elements9a.htm
51: return '"' . str_replace('"', '""', $name) . '"';
52: }
53:
54:
55:
56: /**
57: * Formats date-time for use in a SQL statement.
58: */
59: public function formatDateTime(\DateTime $value)
60: {
61: return $value->format($this->fmtDateTime);
62: }
63:
64:
65:
66: /**
67: * Encodes string for use in a LIKE statement.
68: */
69: public function formatLike($value, $pos)
70: {
71: throw new \NotImplementedException;
72: }
73:
74:
75:
76: /**
77: * Injects LIMIT/OFFSET to the SQL query.
78: */
79: public function applyLimit(&$sql, $limit, $offset)
80: {
81: if ($offset > 0) {
82: // see http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html
83: $sql = 'SELECT * FROM (SELECT t.*, ROWNUM AS "__rnum" FROM (' . $sql . ') t '
84: . ($limit >= 0 ? 'WHERE ROWNUM <= ' . ((int) $offset + (int) $limit) : '')
85: . ') WHERE "__rnum" > '. (int) $offset;
86:
87: } elseif ($limit >= 0) {
88: $sql = 'SELECT * FROM (' . $sql . ') WHERE ROWNUM <= ' . (int) $limit;
89: }
90: }
91:
92:
93:
94: /**
95: * Normalizes result row.
96: */
97: public function normalizeRow($row, $statement)
98: {
99: return $row;
100: }
101:
102: }
103: