Query/src/Drivers/DriverInterface.php

230 lines
4.5 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
*
2018-01-19 13:43:19 -05:00
* PHP version 7.1
2016-09-07 13:17:17 -04:00
*
* @package Query
* @author Timothy J. Warren <tim@timshomepage.net>
2018-01-19 13:43:19 -05:00
* @copyright 2012 - 2018 Timothy J. Warren
2016-09-07 13:17:17 -04:00
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link https://git.timshomepage.net/aviat4ion/Query
2014-04-22 14:02:54 -04:00
*/
2016-09-07 17:39:19 -04:00
namespace Query\Drivers;
2014-04-22 14:02:54 -04:00
/**
* PDO Interface to implement for database drivers
*/
2016-09-07 17:39:19 -04:00
interface DriverInterface extends PDOInterface {
2014-04-22 14:02:54 -04:00
/**
* Constructor/Connection method
*
* @param string $dsn
* @param string $username
* @param string $password
2016-10-13 21:55:23 -04:00
* @param array $driverOptions
2014-04-22 14:02:54 -04:00
*/
2016-10-13 21:55:23 -04:00
public function __construct($dsn, $username=NULL, $password=NULL, array $driverOptions = []);
2014-04-22 14:02:54 -04:00
/**
* Simplifies prepared statements for database queries
*
* @param string $sql
* @param array $data
* @return \PDOStatement | FALSE
* @throws \InvalidArgumentException
*/
2016-10-13 21:55:23 -04:00
public function prepareQuery($sql, $data);
2014-04-22 14:02:54 -04:00
/**
* Retrieve column information for the current database table
*
* @param string $table
* @return array
*/
2016-10-13 21:55:23 -04:00
public function getColumns($table);
2014-04-22 14:02:54 -04:00
/**
* Retrieve list of data types for the database
*
* @return array
*/
2016-10-13 21:55:23 -04:00
public function getTypes();
/**
* Retrieve indexes for the table
*
* @param string $table
* @return array
*/
2016-10-13 21:55:23 -04:00
public function getIndexes($table);
2014-04-22 14:02:54 -04:00
/**
* Retrieve foreign keys for the table
*
* @param string $table
* @return array
*/
2016-10-13 21:55:23 -04:00
public function getFks($table);
2014-04-22 14:02:54 -04:00
/**
* Return list of tables for the current database
*
* @return array
*/
2016-10-13 21:55:23 -04:00
public function getTables();
2014-04-22 14:02:54 -04:00
/**
* Retrieves an array of non-user-created tables for
* the connection/database
*
* @return array
*/
2016-10-13 21:55:23 -04:00
public function getSystemTables();
2014-04-24 13:42:01 -04:00
/**
* Return list of dbs for the current connection, if possible
*
* @return array
*/
2016-10-13 21:55:23 -04:00
public function getDbs();
2014-04-24 13:42:01 -04:00
/**
* Return list of views for the current database
*
* @return array
*/
2016-10-13 21:55:23 -04:00
public function getViews();
/**
* Return list of sequences for the current database, if they exist
*
* @return array
*/
2016-10-13 21:55:23 -04:00
public function getSequences();
/**
* Return list of functions for the current database
*
* @return array
*/
2016-10-13 21:55:23 -04:00
public function getFunctions();
/**
* Return list of stored procedures for the current database
*
* @return array
*/
2016-10-13 21:55:23 -04:00
public function getProcedures();
/**
* Return list of triggers for the current database
*
* @return array
*/
2016-10-13 21:55:23 -04:00
public function getTriggers();
2014-04-22 14:02:54 -04:00
/**
* Surrounds the string with the databases identifier escape characters
*
2015-07-30 13:13:12 -04:00
* @param string|array $ident
* @return string|array
2014-04-22 14:02:54 -04:00
*/
2016-10-13 21:55:23 -04:00
public function quoteIdent($ident);
2014-04-22 14:02:54 -04:00
/**
* Quote database table name, and set prefix
*
2015-07-30 13:13:12 -04:00
* @param string|array $table
* @return string|array
2014-04-22 14:02:54 -04:00
*/
2016-10-13 21:55:23 -04:00
public function quoteTable($table);
2014-04-22 14:02:54 -04:00
/**
* Create and execute a prepared statement with the provided parameters
*
* @param string $sql
* @param array $params
* @return \PDOStatement
*/
2016-10-13 21:55:23 -04:00
public function prepareExecute($sql, $params);
2014-04-24 13:42:01 -04:00
/**
* Method to simplify retrieving db results for meta-data queries
*
* @param string|array|null $query
2016-10-13 21:55:23 -04:00
* @param bool $filteredIndex
2014-04-24 13:42:01 -04:00
* @return array
*/
2016-10-13 21:55:23 -04:00
public function driverQuery($query, $filteredIndex=TRUE);
/**
* Returns number of rows affected by an INSERT, UPDATE, DELETE type query
*
* @return int
*/
2016-10-13 21:55:23 -04:00
public function affectedRows();
/**
* Return the number of rows returned for a SELECT query
* @see http://us3.php.net/manual/en/pdostatement.rowcount.php#87110
*
* @return int
*/
2016-10-13 21:55:23 -04:00
public function numRows();
/**
* Prefixes a table if it is not already prefixed
*
* @param string $table
* @return string
*/
2016-10-13 21:55:23 -04:00
public function prefixTable($table);
/**
* Create sql for batch insert
*
* @param string $table
* @param array $data
* @return array
*/
2016-10-13 21:55:23 -04:00
public function insertBatch($table, $data=[]);
2016-09-07 17:39:19 -04:00
/**
* Creates a batch update, and executes it.
* Returns the number of affected rows
*
* @param string $table
* @param array|object $data
* @param string $where
* @return int|null
*/
2016-10-13 21:55:23 -04:00
public function updateBatch($table, $data, $where);
2016-09-07 17:39:19 -04:00
/**
* Get the SQL class for the current driver
*
2016-10-13 21:55:23 -04:00
* @return SQLInterface
2016-09-07 17:39:19 -04:00
*/
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-12 22:12:25 -04:00
* @return AbstractUtil
2016-09-07 17:39:19 -04:00
*/
2016-10-13 21:55:23 -04:00
public function getUtil(): AbstractUtil;
2016-09-07 17:39:19 -04:00
/**
* Set the last query sql
*
2016-10-13 21:55:23 -04:00
* @param string $queryString
2016-09-07 17:39:19 -04:00
* @return void
*/
2016-10-13 21:55:23 -04:00
public function setLastQuery(string $queryString);
}