Query/src/Drivers/DriverInterface.php

206 lines
4.9 KiB
PHP
Raw Normal View History

2016-10-12 22:12:25 -04:00
<?php declare(strict_types=1);
2014-04-22 14:02:54 -04:00
/**
* Query
*
2016-09-07 13:17:17 -04:00
* SQL Query Builder / Database Abstraction Layer
2014-04-22 14:02:54 -04:00
*
2022-09-29 11:33:08 -04:00
* PHP version 8.1
2016-09-07 13:17:17 -04:00
*
* @package Query
2023-01-20 11:30:51 -05:00
* @author Timothy J. Warren <tim@timshome.page>
* @copyright 2012 - 2023 Timothy J. Warren
2016-09-07 13:17:17 -04:00
* @license http://www.opensource.org/licenses/mit-license.html MIT License
2019-12-11 16:49:42 -05:00
* @link https://git.timshomepage.net/aviat/Query
2023-03-17 16:34:21 -04:00
* @version 4.1.0
2014-04-22 14:02:54 -04:00
*/
2023-03-17 15:18:33 -04:00
2016-09-07 17:39:19 -04:00
namespace Query\Drivers;
2014-04-22 14:02:54 -04:00
2019-12-11 16:49:06 -05:00
use PDO;
2018-01-24 13:14:03 -05:00
use PDOStatement;
2014-04-22 14:02:54 -04:00
/**
* PDO Interface to implement for database drivers
2019-12-11 16:49:06 -05:00
*
* @method beginTransaction(): bool
* @method commit(): bool
* @method errorCode(): string
* @method errorInfo(): array
* @method exec(string $statement): int
* @method getAttribute(int $attribute)
* @method inTransaction(): bool
* @method lastInsertId(string $name = NULL): string
* @method prepare(string $statement, array $driver_options = []): PDOStatement
* @method query(string $statement): PDOStatement
* @method quote(string $string, int $parameter_type = PDO::PARAM_STR): string
* @method rollback(): bool
* @method setAttribute(int $attribute, $value): bool
2014-04-22 14:02:54 -04:00
*/
2023-03-17 15:18:33 -04:00
interface DriverInterface // extends the interface of PDO
{
2014-04-22 14:02:54 -04:00
/**
* Constructor/Connection method
*/
2023-03-17 15:18:33 -04:00
public function __construct(string $dsn, ?string $username=NULL, ?string $password=NULL, array $driverOptions = []);
2014-04-22 14:02:54 -04:00
/**
* Simplifies prepared statements for database queries
*/
public function prepareQuery(string $sql, array $data): PDOStatement;
2014-04-22 14:02:54 -04:00
/**
* Retrieve column information for the current database table
*/
2019-12-11 16:49:06 -05:00
public function getColumns(string $table): ?array;
2014-04-22 14:02:54 -04:00
/**
* Retrieve list of data types for the database
*/
2018-01-24 13:14:03 -05:00
public function getTypes(): ?array;
/**
* Retrieve indexes for the table
*/
2019-12-11 16:49:06 -05:00
public function getIndexes(string $table): ?array;
2014-04-22 14:02:54 -04:00
/**
* Retrieve foreign keys for the table
*/
2019-12-11 16:49:06 -05:00
public function getFks(string $table): ?array;
2014-04-22 14:02:54 -04:00
/**
* Return list of tables for the current database
*/
2018-01-24 13:14:03 -05:00
public function getTables(): ?array;
2014-04-22 14:02:54 -04:00
/**
* Retrieves an array of non-user-created tables for
* the connection/database
*/
2018-01-24 13:14:03 -05:00
public function getSystemTables(): ?array;
2019-12-11 16:49:06 -05:00
/**
* Return schemas for databases that list them. Returns
* database list if schemas are databases for the current driver.
*/
public function getSchemas(): ?array;
2014-04-24 13:42:01 -04:00
/**
* Return list of dbs for the current connection, if possible
*/
2018-01-24 13:14:03 -05:00
public function getDbs(): ?array;
2014-04-24 13:42:01 -04:00
/**
* Return list of views for the current database
*/
2018-01-24 13:14:03 -05:00
public function getViews(): ?array;
/**
* Return list of sequences for the current database, if they exist
*/
2018-01-24 13:14:03 -05:00
public function getSequences(): ?array;
/**
* Return list of functions for the current database
2023-01-20 10:33:43 -05:00
*
* @deprecated Will be removed in next version
*/
2018-01-24 13:14:03 -05:00
public function getFunctions(): ?array;
/**
* Return list of stored procedures for the current database
2023-01-20 10:33:43 -05:00
*
* @deprecated Will be removed in next version
*/
2018-01-24 13:14:03 -05:00
public function getProcedures(): ?array;
/**
* Return list of triggers for the current database
2023-01-20 10:33:43 -05:00
*
* @deprecated Will be removed in next version
*/
2018-01-24 13:14:03 -05:00
public function getTriggers(): ?array;
2014-04-22 14:02:54 -04:00
/**
* Surrounds the string with the databases identifier escape characters
*/
2023-01-20 11:30:51 -05:00
public function quoteIdent(string|array $identifier): string|array;
2014-04-22 14:02:54 -04:00
/**
* Quote database table name, and set prefix
*/
2020-04-23 18:16:32 -04:00
public function quoteTable(string $table): string;
2014-04-22 14:02:54 -04:00
/**
* Create and execute a prepared statement with the provided parameters
*/
public function prepareExecute(string $sql, array $params): PDOStatement;
2014-04-24 13:42:01 -04:00
/**
* Method to simplify retrieving db results for meta-data queries
*/
2023-01-13 13:14:28 -05:00
public function driverQuery(string|array $query, bool $filteredIndex=TRUE): ?array;
/**
* Returns number of rows affected by an INSERT, UPDATE, DELETE type query
*/
2018-01-24 13:14:03 -05:00
public function affectedRows(): int;
/**
* Return the number of rows returned for a SELECT query
* @see http://us3.php.net/manual/en/pdostatement.rowcount.php#87110
*/
2018-01-24 13:14:03 -05:00
public function numRows(): ?int;
/**
* Prefixes a table if it is not already prefixed
*/
2018-01-24 13:14:03 -05:00
public function prefixTable(string $table): string;
/**
* Create sql for batch insert
*/
2018-01-24 13:14:03 -05:00
public function insertBatch(string $table, array $data=[]): array;
2016-09-07 17:39:19 -04:00
/**
* Creates a batch update, and executes it.
* Returns the number of affected rows
*/
2018-01-26 08:39:30 -05:00
public function updateBatch(string $table, array $data, string $where): array;
2016-09-07 17:39:19 -04:00
2019-12-11 16:49:06 -05:00
/**
* Empty the passed table
*/
public function truncate(string $table): PDOStatement;
2016-09-07 17:39:19 -04:00
/**
* Get the SQL class for the current driver
*/
2016-10-13 21:55:23 -04:00
public function getSql(): SQLInterface;
2016-09-07 17:39:19 -04:00
/**
* Get the Util class for the current driver
*/
2016-10-13 21:55:23 -04:00
public function getUtil(): AbstractUtil;
2016-09-07 17:39:19 -04:00
/**
* Get the version of the database engine
*/
public function getVersion(): string;
2019-12-11 16:49:06 -05:00
/**
* Get the last sql query executed
*/
public function getLastQuery(): string;
2016-09-07 17:39:19 -04:00
/**
* Set the last query sql
*/
2018-01-24 13:14:03 -05:00
public function setLastQuery(string $queryString): void;
2019-12-11 16:49:06 -05:00
/**
* Set the common table name prefix
*/
public function setTablePrefix(string $prefix): void;
2019-12-10 12:17:40 -05:00
}