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 PostgreSQL database driver.
20: *
21: * @author David Grudl
22: */
23: class PdoPgSqlDriver extends Nette\Object implements Nette\Database\ISupplementalDriver
24: {
25: /** @var Nette\Database\Connection */
26: private $connection;
27:
28:
29:
30: public function __construct(Nette\Database\Connection $connection, array $options)
31: {
32: $this->connection = $connection;
33: }
34:
35:
36:
37: /********************* SQL ****************d*g**/
38:
39:
40:
41: /**
42: * Delimites identifier for use in a SQL statement.
43: */
44: public function delimite($name)
45: {
46: // @see http://www.postgresql.org/docs/8.2/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
47: return '"' . str_replace('"', '""', $name) . '"';
48: }
49:
50:
51:
52: /**
53: * Formats date-time for use in a SQL statement.
54: */
55: public function formatDateTime(\DateTime $value)
56: {
57: return $value->format("'Y-m-d H:i:s'");
58: }
59:
60:
61:
62: /**
63: * Encodes string for use in a LIKE statement.
64: */
65: public function formatLike($value, $pos)
66: {
67: throw new \NotImplementedException;
68: }
69:
70:
71:
72: /**
73: * Injects LIMIT/OFFSET to the SQL query.
74: */
75: public function applyLimit(&$sql, $limit, $offset)
76: {
77: if ($limit >= 0)
78: $sql .= ' LIMIT ' . (int) $limit;
79:
80: if ($offset > 0)
81: $sql .= ' OFFSET ' . (int) $offset;
82: }
83:
84:
85:
86: /**
87: * Normalizes result row.
88: */
89: public function normalizeRow($row, $statement)
90: {
91: return $row;
92: }
93:
94: }
95: