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