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