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 PdoSqliteDriver extends Nette\Object implements Nette\Database\ISupplementalDriver
24: {
25:
26: private $connection;
27:
28:
29: private $fmtDateTime;
30:
31:
32:
33: public function __construct(Nette\Database\Connection $connection, array $options)
34: {
35: $this->connection = $connection;
36: $this->fmtDateTime = isset($options['formatDateTime']) ? $options['formatDateTime'] : 'U';
37: }
38:
39:
40:
41:
42:
43:
44:
45: 46: 47:
48: public function delimite($name)
49: {
50: return '[' . strtr($name, '[]', ' ') . ']';
51: }
52:
53:
54:
55: 56: 57:
58: public function formatDateTime(\DateTime $value)
59: {
60: return $value->format($this->fmtDateTime);
61: }
62:
63:
64:
65: 66: 67:
68: public function formatLike($value, $pos)
69: {
70: $value = addcslashes(substr($this->connection->quote($value), 1, -1), '%_\\');
71: return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'") . " ESCAPE '\\'";
72: }
73:
74:
75:
76: 77: 78:
79: public function applyLimit(&$sql, $limit, $offset)
80: {
81: if ($limit < 0 && $offset < 1) return;
82: $sql .= ' LIMIT ' . $limit . ($offset > 0 ? ' OFFSET ' . (int) $offset : '');
83: }
84:
85:
86:
87: 88: 89:
90: public function normalizeRow($row, $statement)
91: {
92: return $row;
93: }
94:
95: }
96: