Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | n/a |
0 / 0 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
1 | <?php declare(strict_types=1); |
2 | /** |
3 | * Query |
4 | * |
5 | * SQL Query Builder / Database Abstraction Layer |
6 | * |
7 | * PHP version 8.1 |
8 | * |
9 | * @package Query |
10 | * @author Timothy J. Warren <tim@timshome.page> |
11 | * @copyright 2012 - 2023 Timothy J. Warren |
12 | * @license http://www.opensource.org/licenses/mit-license.html MIT License |
13 | * @link https://git.timshomepage.net/aviat/Query |
14 | * @version 4.0.0 |
15 | */ |
16 | |
17 | namespace Query\Drivers; |
18 | |
19 | use PDO; |
20 | use PDOStatement; |
21 | |
22 | /** |
23 | * PDO Interface to implement for database drivers |
24 | * |
25 | * @method beginTransaction(): bool |
26 | * @method commit(): bool |
27 | * @method errorCode(): string |
28 | * @method errorInfo(): array |
29 | * @method exec(string $statement): int |
30 | * @method getAttribute(int $attribute) |
31 | * @method inTransaction(): bool |
32 | * @method lastInsertId(string $name = NULL): string |
33 | * @method prepare(string $statement, array $driver_options = []): PDOStatement |
34 | * @method query(string $statement): PDOStatement |
35 | * @method quote(string $string, int $parameter_type = PDO::PARAM_STR): string |
36 | * @method rollback(): bool |
37 | * @method setAttribute(int $attribute, $value): bool |
38 | */ |
39 | interface DriverInterface // extends the interface of PDO |
40 | { |
41 | /** |
42 | * Constructor/Connection method |
43 | */ |
44 | public function __construct(string $dsn, ?string $username=NULL, ?string $password=NULL, array $driverOptions = []); |
45 | |
46 | /** |
47 | * Simplifies prepared statements for database queries |
48 | */ |
49 | public function prepareQuery(string $sql, array $data): PDOStatement; |
50 | |
51 | /** |
52 | * Retrieve column information for the current database table |
53 | */ |
54 | public function getColumns(string $table): ?array; |
55 | |
56 | /** |
57 | * Retrieve list of data types for the database |
58 | */ |
59 | public function getTypes(): ?array; |
60 | |
61 | /** |
62 | * Retrieve indexes for the table |
63 | */ |
64 | public function getIndexes(string $table): ?array; |
65 | |
66 | /** |
67 | * Retrieve foreign keys for the table |
68 | */ |
69 | public function getFks(string $table): ?array; |
70 | |
71 | /** |
72 | * Return list of tables for the current database |
73 | */ |
74 | public function getTables(): ?array; |
75 | |
76 | /** |
77 | * Retrieves an array of non-user-created tables for |
78 | * the connection/database |
79 | */ |
80 | public function getSystemTables(): ?array; |
81 | |
82 | /** |
83 | * Return schemas for databases that list them. Returns |
84 | * database list if schemas are databases for the current driver. |
85 | */ |
86 | public function getSchemas(): ?array; |
87 | |
88 | /** |
89 | * Return list of dbs for the current connection, if possible |
90 | */ |
91 | public function getDbs(): ?array; |
92 | |
93 | /** |
94 | * Return list of views for the current database |
95 | */ |
96 | public function getViews(): ?array; |
97 | |
98 | /** |
99 | * Return list of sequences for the current database, if they exist |
100 | */ |
101 | public function getSequences(): ?array; |
102 | |
103 | /** |
104 | * Return list of functions for the current database |
105 | * |
106 | * @deprecated Will be removed in next version |
107 | */ |
108 | public function getFunctions(): ?array; |
109 | |
110 | /** |
111 | * Return list of stored procedures for the current database |
112 | * |
113 | * @deprecated Will be removed in next version |
114 | */ |
115 | public function getProcedures(): ?array; |
116 | |
117 | /** |
118 | * Return list of triggers for the current database |
119 | * |
120 | * @deprecated Will be removed in next version |
121 | */ |
122 | public function getTriggers(): ?array; |
123 | |
124 | /** |
125 | * Surrounds the string with the databases identifier escape characters |
126 | */ |
127 | public function quoteIdent(string|array $identifier): string|array; |
128 | |
129 | /** |
130 | * Quote database table name, and set prefix |
131 | */ |
132 | public function quoteTable(string $table): string; |
133 | |
134 | /** |
135 | * Create and execute a prepared statement with the provided parameters |
136 | */ |
137 | public function prepareExecute(string $sql, array $params): PDOStatement; |
138 | |
139 | /** |
140 | * Method to simplify retrieving db results for meta-data queries |
141 | */ |
142 | public function driverQuery(string|array $query, bool $filteredIndex=TRUE): ?array; |
143 | |
144 | /** |
145 | * Returns number of rows affected by an INSERT, UPDATE, DELETE type query |
146 | */ |
147 | public function affectedRows(): int; |
148 | |
149 | /** |
150 | * Return the number of rows returned for a SELECT query |
151 | * @see http://us3.php.net/manual/en/pdostatement.rowcount.php#87110 |
152 | */ |
153 | public function numRows(): ?int; |
154 | |
155 | /** |
156 | * Prefixes a table if it is not already prefixed |
157 | */ |
158 | public function prefixTable(string $table): string; |
159 | |
160 | /** |
161 | * Create sql for batch insert |
162 | */ |
163 | public function insertBatch(string $table, array $data=[]): array; |
164 | |
165 | /** |
166 | * Creates a batch update, and executes it. |
167 | * Returns the number of affected rows |
168 | */ |
169 | public function updateBatch(string $table, array $data, string $where): array; |
170 | |
171 | /** |
172 | * Empty the passed table |
173 | */ |
174 | public function truncate(string $table): PDOStatement; |
175 | |
176 | /** |
177 | * Get the SQL class for the current driver |
178 | */ |
179 | public function getSql(): SQLInterface; |
180 | |
181 | /** |
182 | * Get the Util class for the current driver |
183 | */ |
184 | public function getUtil(): AbstractUtil; |
185 | |
186 | /** |
187 | * Get the version of the database engine |
188 | */ |
189 | public function getVersion(): string; |
190 | |
191 | /** |
192 | * Get the last sql query executed |
193 | */ |
194 | public function getLastQuery(): string; |
195 | |
196 | /** |
197 | * Set the last query sql |
198 | */ |
199 | public function setLastQuery(string $queryString): void; |
200 | |
201 | /** |
202 | * Set the common table name prefix |
203 | */ |
204 | public function setTablePrefix(string $prefix): void; |
205 | } |