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