1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace Nette\Database\Drivers;
13:
14: use Nette;
15:
16:
17:
18: 19: 20: 21: 22:
23: class SqliteDriver extends Nette\Object implements Nette\Database\ISupplementalDriver
24: {
25:
26: public $supports = array('meta' => FALSE);
27:
28:
29: private $connection;
30:
31:
32: private $fmtDateTime;
33:
34:
35:
36: public function __construct(Nette\Database\Connection $connection, array $options)
37: {
38: $this->connection = $connection;
39: $this->fmtDateTime = isset($options['formatDateTime']) ? $options['formatDateTime'] : 'U';
40: }
41:
42:
43:
44:
45:
46:
47:
48: 49: 50:
51: public function delimite($name)
52: {
53: return '[' . strtr($name, '[]', ' ') . ']';
54: }
55:
56:
57:
58: 59: 60:
61: public function formatDateTime(\DateTime $value)
62: {
63: return $value->format($this->fmtDateTime);
64: }
65:
66:
67:
68: 69: 70:
71: public function formatLike($value, $pos)
72: {
73: $value = addcslashes(substr($this->connection->quote($value), 1, -1), '%_\\');
74: return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'") . " ESCAPE '\\'";
75: }
76:
77:
78:
79: 80: 81:
82: public function applyLimit(&$sql, $limit, $offset)
83: {
84: if ($limit >= 0 || $offset > 0) {
85: $sql .= ' LIMIT ' . $limit . ($offset > 0 ? ' OFFSET ' . (int) $offset : '');
86: }
87: }
88:
89:
90:
91: 92: 93:
94: public function normalizeRow($row, $statement)
95: {
96: return $row;
97: }
98:
99: }
100: