2016-10-05 22:08:43 -04:00
< ? php
2017-11-16 20:23:18 -05:00
/** @ license MIT
* Copyright 2017 J . King , Dustin Wilson et al .
* See LICENSE and AUTHORS files for details */
2016-10-05 22:08:43 -04:00
declare ( strict_types = 1 );
2021-04-14 11:17:01 -04:00
2017-03-28 00:12:12 -04:00
namespace JKingWeb\Arsse\Db ;
2016-10-05 22:08:43 -04:00
2017-03-02 09:04:04 -05:00
interface Driver {
2020-03-01 18:32:01 -05:00
public const TR_PEND = 0 ;
public const TR_COMMIT = 1 ;
public const TR_ROLLBACK = 2 ;
public const TR_PEND_COMMIT = - 1 ;
public const TR_PEND_ROLLBACK = - 2 ;
2018-10-26 14:58:04 -04:00
2019-02-21 15:10:32 -05:00
/** Creates and returns an instance of the class; this is so that either a native or PDO driver may be returned depending on what is available on the server */
2017-12-18 18:29:32 -05:00
public static function create () : Driver ;
2019-02-21 15:10:32 -05:00
/** Returns a human-friendly name for the driver */
2017-08-29 10:50:31 -04:00
public static function driverName () : string ;
2019-02-21 15:10:32 -05:00
/** Returns the version of the schema of the opened database ; if uninitialized should return 0
2019-05-01 22:52:20 -04:00
*
2019-02-21 15:10:32 -05:00
* Normally the version is stored under the 'schema_version' key in the arsse_meta table , but another method may be used if appropriate
*/
2017-08-29 10:50:31 -04:00
public function schemaVersion () : int ;
2019-02-21 15:10:32 -05:00
/** Returns the schema set to be used for database set-up */
2017-12-18 18:29:32 -05:00
public static function schemaID () : string ;
2019-02-21 15:10:32 -05:00
/** Returns a Transaction object */
2017-08-29 10:50:31 -04:00
public function begin ( bool $lock = false ) : Transaction ;
2019-02-21 15:10:32 -05:00
/** Manually begins a real or synthetic transactions , with real or synthetic nesting , and returns its numeric ID
2019-05-01 22:52:20 -04:00
*
2019-02-21 15:10:32 -05:00
* If the database backend does not implement savepoints , IDs must still be tracked as if it does
*/
2017-08-29 10:50:31 -04:00
public function savepointCreate () : int ;
2019-02-21 15:10:32 -05:00
/** Manually commits either the latest or a specified nested transaction */
2017-08-29 10:50:31 -04:00
public function savepointRelease ( int $index = null ) : bool ;
2019-02-21 15:10:32 -05:00
/** Manually rolls back either the latest or a specified nested transaction */
2017-08-29 10:50:31 -04:00
public function savepointUndo ( int $index = null ) : bool ;
2019-02-21 15:10:32 -05:00
/** Performs an in - place upgrade of the database schema
2019-05-01 22:52:20 -04:00
*
2019-02-21 15:10:32 -05:00
* The driver may choose not to implement in - place upgrading , in which case an exception should be thrown
*/
2017-08-29 10:50:31 -04:00
public function schemaUpdate ( int $to ) : bool ;
2019-02-21 15:10:32 -05:00
/** Executes one or more queries without parameters, returning only an indication of success */
2017-08-29 10:50:31 -04:00
public function exec ( string $query ) : bool ;
2019-02-21 15:10:32 -05:00
/** Executes a single query without parameters, and returns a result set */
2017-08-29 10:50:31 -04:00
public function query ( string $query ) : Result ;
2019-02-21 15:10:32 -05:00
/** Readies a prepared statement for later execution */
2017-08-29 10:50:31 -04:00
public function prepare ( string $query , ... $paramType ) : Statement ;
2019-02-21 15:10:32 -05:00
/** Readies a prepared statement for later execution */
2017-08-29 10:50:31 -04:00
public function prepareArray ( string $query , array $paramTypes ) : Statement ;
2019-02-21 15:10:32 -05:00
/** Reports whether the database character set is correct / acceptable
2019-05-01 22:52:20 -04:00
*
2019-02-21 15:10:32 -05:00
* The backend must be able to accept and provide UTF - 8 text ; information may be stored in any encoding capable of representing the entire range of Unicode
*/
2017-11-29 18:14:59 -05:00
public function charsetAcceptable () : bool ;
2019-02-21 15:10:32 -05:00
/** Returns an implementation - dependent form of a reference SQL function or operator
2019-05-01 22:52:20 -04:00
*
2019-02-21 15:10:32 -05:00
* The tokens the implementation must understand are :
2019-05-01 22:52:20 -04:00
*
2019-02-21 15:10:32 -05:00
* - " greatest " : the GREATEST function implemented by PostgreSQL and MySQL
* - " nocase " : the name of a general - purpose case - insensitive collation sequence
2019-02-22 11:13:13 -05:00
* - " like " : the case - insensitive LIKE operator
2021-01-07 10:12:38 -05:00
* - " integer " : the integer type to use for explicit casts
2021-02-03 14:20:34 -05:00
* - " asc " : ascending sort order when dealing with nulls
* - " desc " : descending sort order when dealing with nulls
2019-02-21 15:10:32 -05:00
*/
2018-12-04 20:41:21 -05:00
public function sqlToken ( string $token ) : string ;
2019-03-01 22:36:25 -05:00
/** Returns a string literal which is properly escaped to guard against SQL injections . Delimiters are included in the output string
2019-05-01 22:52:20 -04:00
*
2019-03-01 22:36:25 -05:00
* This functionality should be avoided in favour of using statement parameters whenever possible
*/
public function literalString ( string $str ) : string ;
2019-07-26 09:37:51 -04:00
/** Performs implementation - specific database maintenance to ensure good performance
2019-09-05 10:21:36 -04:00
*
2019-07-26 09:37:51 -04:00
* This should be restricted to quick maintenance ; in SQLite terms it might include ANALYZE , but not VACUUM
*/
public function maintenance () : bool ;
2017-08-29 10:50:31 -04:00
}