1 | <?php |
||
9 | abstract class Query |
||
10 | { |
||
11 | protected $bindings; |
||
12 | |||
13 | protected $connection; |
||
14 | |||
15 | protected $flags; |
||
16 | |||
17 | protected $quoter; |
||
18 | |||
19 | protected $indent = ''; |
||
20 | |||
21 | 20 | public function __construct(Connection $connection, Bindings $bindings = null, $indent = '') |
|
38 | |||
39 | /** |
||
40 | * Perform the query at it's current state (conditions and bind values) |
||
41 | * |
||
42 | * @return \PDOStatement |
||
43 | */ |
||
44 | public function perform() |
||
51 | |||
52 | /** |
||
53 | * Creates a numbered binding placeholder to be added to the statement |
||
54 | * like :__102__, :__3__ and adds the value to the list of bind values |
||
55 | * |
||
56 | * @param $value |
||
57 | * @param int $type |
||
58 | * |
||
59 | * @return string |
||
60 | */ |
||
61 | 1 | public function bindInline($value, int $type = -1) |
|
65 | |||
66 | /** |
||
67 | * Creates a string where %s is replaced by numbered binding placeholders |
||
68 | * and adds the values to the list of bind values |
||
69 | * |
||
70 | * @param string $format |
||
71 | * @param mixed ...$values |
||
72 | * |
||
73 | * @return string |
||
74 | * @example $format = "date between %s and %s", returns "date between :__4__ and :__5__" |
||
75 | * |
||
76 | */ |
||
77 | 1 | public function bindSprintf(string $format, ...$values): string |
|
81 | |||
82 | /** |
||
83 | * Creates a named binding placedholder and adds the value to the bind values |
||
84 | * |
||
85 | * @param string $key |
||
86 | * @param $value |
||
87 | * @param int $type |
||
88 | * |
||
89 | * @return $this |
||
90 | * @example $key = 'title', returns ':title' |
||
91 | * |
||
92 | */ |
||
93 | 2 | public function bindValue(string $key, $value, int $type = -1) |
|
99 | |||
100 | /** |
||
101 | * Binds a set of key-value pairs to the statement |
||
102 | * |
||
103 | * @param array $values |
||
104 | * |
||
105 | * @return $this |
||
106 | */ |
||
107 | 1 | public function bindValues(array $values) |
|
113 | |||
114 | /** |
||
115 | * Returns a RAW value that will be used as-is in the statement |
||
116 | * |
||
117 | * @param $value |
||
118 | * |
||
119 | * @return Raw |
||
120 | */ |
||
121 | 3 | public function raw($value): Raw |
|
125 | |||
126 | 11 | public function getBindValues(): array |
|
130 | |||
131 | /** |
||
132 | * Sets a statement flag like IGNORE for INSERT or DISTINCT for SELECT |
||
133 | * |
||
134 | * @param string $flag |
||
135 | * @param bool $enable |
||
136 | */ |
||
137 | 2 | public function setFlag(string $flag, bool $enable = true): void |
|
141 | |||
142 | /** |
||
143 | * Resets the query (conditions, columns etc) |
||
144 | * @return $this |
||
145 | */ |
||
146 | 20 | public function reset() |
|
156 | |||
157 | 20 | public function resetFlags() |
|
163 | |||
164 | public function quoteIdentifier(string $name): string |
||
168 | |||
169 | /** |
||
170 | * Returns the statement to be executed on the connection |
||
171 | * @return string |
||
172 | */ |
||
173 | abstract public function getStatement(): string; |
||
174 | |||
175 | /** |
||
176 | * Returns a compiled version of the query. |
||
177 | * To be used only for debugging purposes. |
||
178 | * All lines are prepended with # so you don't accidentally run it |
||
179 | * |
||
180 | * @return string |
||
181 | */ |
||
182 | 1 | public function __toString() |
|
197 | } |
||
198 |