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 MySqlDriver extends Nette\Object implements Nette\Database\ISupplementalDriver
24: {
25:
26: public $supports = array('meta' => TRUE);
27:
28:
29: private $connection;
30:
31:
32:
33: 34: 35: 36: 37:
38: public function __construct(Nette\Database\Connection $connection, array $options)
39: {
40: $this->connection = $connection;
41: $charset = isset($options['charset']) ? $options['charset'] : 'utf8';
42: if ($charset) {
43: $connection->exec("SET NAMES '$charset'");
44: }
45: if (isset($options['sqlmode'])) {
46: $connection->exec("SET sql_mode='$options[sqlmode]'");
47: }
48: $connection->exec("SET time_zone='" . date('P') . "'");
49: }
50:
51:
52:
53:
54:
55:
56:
57: 58: 59:
60: public function delimite($name)
61: {
62:
63: return '`' . str_replace('`', '``', $name) . '`';
64: }
65:
66:
67:
68: 69: 70:
71: public function formatDateTime(\DateTime $value)
72: {
73: return $value->format("'Y-m-d H:i:s'");
74: }
75:
76:
77:
78: 79: 80:
81: public function formatLike($value, $pos)
82: {
83: $value = addcslashes(str_replace('\\', '\\\\', $value), "\x00\n\r\\'%_");
84: return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'");
85: }
86:
87:
88:
89: 90: 91:
92: public function applyLimit(&$sql, $limit, $offset)
93: {
94: if ($limit >= 0 || $offset > 0) {
95:
96: $sql .= ' LIMIT ' . ($limit < 0 ? '18446744073709551615' : (int) $limit)
97: . ($offset > 0 ? ' OFFSET ' . (int) $offset : '');
98: }
99: }
100:
101:
102:
103: 104: 105:
106: public function normalizeRow($row, $statement)
107: {
108: return $row;
109: }
110:
111: }
112: