1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-23 17:12:41 +00:00
Arsse/lib/Db/Driver.php

92 lines
3.7 KiB
PHP
Raw Normal View History

<?php
/** @license MIT
* Copyright 2017 J. King, Dustin Wilson et al.
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
2017-03-28 04:12:12 +00:00
namespace JKingWeb\Arsse\Db;
interface Driver {
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
/** 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 */
public static function create(): Driver;
/** Returns a human-friendly name for the driver */
2017-08-29 14:50:31 +00:00
public static function driverName(): string;
/** Returns the version of the schema of the opened database; if uninitialized should return 0
2019-05-02 02:52:20 +00: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 14:50:31 +00:00
public function schemaVersion(): int;
/** Returns the schema set to be used for database set-up */
public static function schemaID(): string;
/** Returns a Transaction object */
2017-08-29 14:50:31 +00:00
public function begin(bool $lock = false): Transaction;
/** Manually begins a real or synthetic transactions, with real or synthetic nesting, and returns its numeric ID
2019-05-02 02:52:20 +00:00
*
* 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;
/** 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;
/** 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;
/** Performs an in-place upgrade of the database schema
2019-05-02 02:52:20 +00:00
*
* 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;
/** 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;
/** 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;
/** Readies a prepared statement for later execution */
2017-08-29 14:50:31 +00:00
public function prepare(string $query, ...$paramType): Statement;
/** Readies a prepared statement for later execution */
2017-08-29 14:50:31 +00:00
public function prepareArray(string $query, array $paramTypes): Statement;
/** Reports whether the database character set is correct/acceptable
2019-05-02 02:52:20 +00: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
*/
public function charsetAcceptable(): bool;
/** Returns an implementation-dependent form of a reference SQL function or operator
2019-05-02 02:52:20 +00:00
*
* The tokens the implementation must understand are:
2019-05-02 02:52:20 +00:00
*
* - "greatest": the GREATEST function implemented by PostgreSQL and MySQL
* - "nocase": the name of a general-purpose case-insensitive collation sequence
* - "like": the case-insensitive LIKE operator
*/
public function sqlToken(string $token): string;
/** Returns a string literal which is properly escaped to guard against SQL injections. Delimiters are included in the output string
2019-05-02 02:52:20 +00:00
*
* This functionality should be avoided in favour of using statement parameters whenever possible
*/
public function literalString(string $str): string;
2019-07-26 13:37:51 +00:00
/** Performs implementation-specific database maintenance to ensure good performance
2019-09-05 14:21:36 +00:00
*
2019-07-26 13:37:51 +00: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 14:50:31 +00:00
}