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: * @package Nette\Database\Drivers
20: */
21: class PgSqlDriver extends Object implements ISupplementalDriver
22: {
23: /** @var array */
24: public $supports = array('meta' => TRUE);
25:
26: /** @var Connection */
27: private $connection;
28:
29:
30:
31: public function __construct(Connection $connection, array $options)
32: {
33: $this->connection = $connection;
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://www.postgresql.org/docs/8.2/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
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("'Y-m-d H:i:s'");
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 ($limit >= 0)
79: $sql .= ' LIMIT ' . (int) $limit;
80:
81: if ($offset > 0)
82: $sql .= ' OFFSET ' . (int) $offset;
83: }
84:
85:
86:
87: /**
88: * Normalizes result row.
89: */
90: public function normalizeRow($row, $statement)
91: {
92: return $row;
93: }
94:
95: }
96: