2016-10-06 02:08:43 +00:00
< ? php
2017-11-17 01:23:18 +00:00
/** @ license MIT
* Copyright 2017 J . King , Dustin Wilson et al .
* See LICENSE and AUTHORS files for details */
2016-10-06 02:08:43 +00:00
declare ( strict_types = 1 );
2017-03-28 04:12:12 +00:00
namespace JKingWeb\Arsse\Db ;
2016-10-06 02:08:43 +00:00
2017-03-02 14:04:04 +00:00
interface Driver {
2017-05-07 22:27:16 +00:00
const TR_PEND = 0 ;
const TR_COMMIT = 1 ;
const TR_ROLLBACK = 2 ;
const TR_PEND_COMMIT = - 1 ;
const TR_PEND_ROLLBACK = - 2 ;
2018-10-26 18:58:04 +00:00
2019-02-21 20:10:32 +00: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 23:29:32 +00:00
public static function create () : Driver ;
2019-02-21 20:10:32 +00:00
/** Returns a human-friendly name for the driver */
2017-08-29 14:50:31 +00:00
public static function driverName () : string ;
2019-02-21 20:10:32 +00:00
/** Returns the version of the schema of the opened database ; if uninitialized should return 0
*
* 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 14:50:31 +00:00
public function schemaVersion () : int ;
2019-02-21 20:10:32 +00:00
/** Returns the schema set to be used for database set-up */
2017-12-18 23:29:32 +00:00
public static function schemaID () : string ;
2019-02-21 20:10:32 +00:00
/** Returns a Transaction object */
2017-08-29 14:50:31 +00:00
public function begin ( bool $lock = false ) : Transaction ;
2019-02-21 20:10:32 +00:00
/** Manually begins a real or synthetic transactions , with real or synthetic nesting , and returns its numeric ID
*
* If the database backend does not implement savepoints , IDs must still be tracked as if it does
*/
2017-08-29 14:50:31 +00:00
public function savepointCreate () : int ;
2019-02-21 20:10:32 +00:00
/** Manually commits either the latest or a specified nested transaction */
2017-08-29 14:50:31 +00:00
public function savepointRelease ( int $index = null ) : bool ;
2019-02-21 20:10:32 +00:00
/** Manually rolls back either the latest or a specified nested transaction */
2017-08-29 14:50:31 +00:00
public function savepointUndo ( int $index = null ) : bool ;
2019-02-21 20:10:32 +00:00
/** Performs an in - place upgrade of the database schema
*
* The driver may choose not to implement in - place upgrading , in which case an exception should be thrown
*/
2017-08-29 14:50:31 +00:00
public function schemaUpdate ( int $to ) : bool ;
2019-02-21 20:10:32 +00:00
/** Executes one or more queries without parameters, returning only an indication of success */
2017-08-29 14:50:31 +00:00
public function exec ( string $query ) : bool ;
2019-02-21 20:10:32 +00:00
/** Executes a single query without parameters, and returns a result set */
2017-08-29 14:50:31 +00:00
public function query ( string $query ) : Result ;
2019-02-21 20:10:32 +00:00
/** Readies a prepared statement for later execution */
2017-08-29 14:50:31 +00:00
public function prepare ( string $query , ... $paramType ) : Statement ;
2019-02-21 20:10:32 +00:00
/** Readies a prepared statement for later execution */
2017-08-29 14:50:31 +00:00
public function prepareArray ( string $query , array $paramTypes ) : Statement ;
2019-02-21 20:10:32 +00:00
/** Reports whether the database character set is correct / acceptable
*
* 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 23:14:59 +00:00
public function charsetAcceptable () : bool ;
2019-02-21 20:10:32 +00:00
/** Returns an implementation - dependent form of a reference SQL function or operator
*
* The tokens the implementation must understand are :
*
* - " greatest " : the GREATEST function implemented by PostgreSQL and MySQL
* - " nocase " : the name of a general - purpose case - insensitive collation sequence
2019-02-22 16:13:13 +00:00
* - " like " : the case - insensitive LIKE operator
2019-02-21 20:10:32 +00:00
*/
2018-12-05 01:41:21 +00:00
public function sqlToken ( string $token ) : string ;
2017-08-29 14:50:31 +00:00
}