Database
extends AbstractData
in package
Database
Model for database access, implemented as a singleton.
Table of Contents
Properties
- $_last_cache : array<string|int, mixed>
- cache for the traffic limiter
- $_db : PDO
- instance of database connection
- $_prefix : string
- table prefix
- $_type : string
- database type
Methods
- __construct() : mixed
- instantiates a new Database data backend
- _sanitizeClob() : int|string
- sanitizes CLOB values used with OCI
- create() : bool
- Create a paste.
- createComment() : bool
- Create a comment in a paste.
- delete() : mixed
- Delete a paste and its discussion.
- exists() : bool
- Test if a paste exists.
- existsComment() : bool
- Test if a comment exists.
- getAllPastes() : array<string|int, mixed>
- Returns all paste ids
- getValue() : string
- Load a value.
- purge() : mixed
- Perform a purge of old pastes, at most the given batchsize is deleted.
- purgeValues() : void
- Purge outdated entries.
- read() : array<string|int, mixed>|false
- Read a paste.
- readComments() : array<string|int, mixed>
- Read all comments of paste.
- setValue() : bool
- Save a value.
- _getExpiredPastes() : array<string|int, mixed>
- Returns up to batch size number of paste ids that have expired
- getOpenSlot() : int|string
- Get next free slot for comment from postdate.
- upgradePreV1Format() : array<string|int, mixed>
- Upgrade pre-version 1 pastes with attachment to version 1 format.
- _createCommentTable() : mixed
- create the paste table
- _createConfigTable() : mixed
- create the paste table
- _createPasteTable() : mixed
- create the paste table
- _exec() : bool
- execute a statement
- _getAttachmentType() : string
- get the attachment type, depending on the database driver
- _getConfig() : string
- get a value by key from the config table
- _getDataType() : string
- get the data type, depending on the database driver
- _getMetaType() : string
- get the meta type, depending on the database driver
- _getPrimaryKeyClauses() : array<string|int, mixed>
- get the primary key clauses, depending on the database driver
- _getTableQuery() : string
- get table list query, depending on the database type
- _getVersionedKeys() : array<string|int, mixed>
- get version dependent key names
- _sanitizeIdentifier() : string
- sanitizes identifiers
- _select() : array<string|int, mixed>|false
- run a select statement
- _upgradeDatabase() : mixed
- upgrade the database schema from an old version
Properties
$_last_cache
cache for the traffic limiter
protected
array<string|int, mixed>
$_last_cache
= array()
Tags
$_db
instance of database connection
private
PDO
$_db
Tags
$_prefix
table prefix
private
string
$_prefix
= ''
Tags
$_type
database type
private
string
$_type
= ''
Tags
Methods
__construct()
instantiates a new Database data backend
public
__construct(array<string|int, mixed> $options) : mixed
Parameters
- $options : array<string|int, mixed>
Tags
_sanitizeClob()
sanitizes CLOB values used with OCI
public
static _sanitizeClob(int|string|resource $value) : int|string
From: https://stackoverflow.com/questions/36200534/pdo-oci-into-a-clob-field
Parameters
- $value : int|string|resource
Tags
Return values
int|stringcreate()
Create a paste.
public
create(string $pasteid, array<string|int, mixed> $paste) : bool
Parameters
- $pasteid : string
- $paste : array<string|int, mixed>
Tags
Return values
boolcreateComment()
Create a comment in a paste.
public
createComment(string $pasteid, string $parentid, string $commentid, array<string|int, mixed> $comment) : bool
Parameters
- $pasteid : string
- $parentid : string
- $commentid : string
- $comment : array<string|int, mixed>
Tags
Return values
booldelete()
Delete a paste and its discussion.
public
delete(string $pasteid) : mixed
Parameters
- $pasteid : string
Tags
exists()
Test if a paste exists.
public
exists(string $pasteid) : bool
Parameters
- $pasteid : string
Tags
Return values
boolexistsComment()
Test if a comment exists.
public
existsComment(string $pasteid, string $parentid, string $commentid) : bool
Parameters
- $pasteid : string
- $parentid : string
- $commentid : string
Tags
Return values
boolgetAllPastes()
Returns all paste ids
public
getAllPastes() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>getValue()
Load a value.
public
getValue(string $namespace[, string $key = '' ]) : string
Parameters
- $namespace : string
- $key : string = ''
Tags
Return values
stringpurge()
Perform a purge of old pastes, at most the given batchsize is deleted.
public
purge(int $batchsize) : mixed
Parameters
- $batchsize : int
Tags
purgeValues()
Purge outdated entries.
public
purgeValues(string $namespace, int $time) : void
Parameters
- $namespace : string
- $time : int
Tags
read()
Read a paste.
public
read(string $pasteid) : array<string|int, mixed>|false
Parameters
- $pasteid : string
Tags
Return values
array<string|int, mixed>|falsereadComments()
Read all comments of paste.
public
readComments(string $pasteid) : array<string|int, mixed>
Parameters
- $pasteid : string
Tags
Return values
array<string|int, mixed>setValue()
Save a value.
public
setValue(string $value, string $namespace[, string $key = '' ]) : bool
Parameters
- $value : string
- $namespace : string
- $key : string = ''
Tags
Return values
bool_getExpiredPastes()
Returns up to batch size number of paste ids that have expired
protected
_getExpiredPastes(int $batchsize) : array<string|int, mixed>
Parameters
- $batchsize : int
Tags
Return values
array<string|int, mixed>getOpenSlot()
Get next free slot for comment from postdate.
protected
getOpenSlot(array<string|int, mixed> &$comments, int|string $postdate) : int|string
Parameters
- $comments : array<string|int, mixed>
- $postdate : int|string
Tags
Return values
int|stringupgradePreV1Format()
Upgrade pre-version 1 pastes with attachment to version 1 format.
protected
static upgradePreV1Format(array<string|int, mixed> $paste) : array<string|int, mixed>
Parameters
- $paste : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>_createCommentTable()
create the paste table
private
_createCommentTable() : mixed
Tags
_createConfigTable()
create the paste table
private
_createConfigTable() : mixed
Tags
_createPasteTable()
create the paste table
private
_createPasteTable() : mixed
Tags
_exec()
execute a statement
private
_exec(string $sql, array<string|int, mixed> $params) : bool
Parameters
- $sql : string
- $params : array<string|int, mixed>
Tags
Return values
bool_getAttachmentType()
get the attachment type, depending on the database driver
private
_getAttachmentType() : string
PostgreSQL and OCI use different APIs for BLOBs then SQL, hence we use TEXT and CLOB
Tags
Return values
string_getConfig()
get a value by key from the config table
private
_getConfig(string $key) : string
Parameters
- $key : string
Tags
Return values
string_getDataType()
get the data type, depending on the database driver
private
_getDataType() : string
PostgreSQL and OCI uses a different API for BLOBs then SQL, hence we use TEXT and CLOB
Tags
Return values
string_getMetaType()
get the meta type, depending on the database driver
private
_getMetaType() : string
OCI doesn't accept TEXT so it has to be VARCHAR2(4000)
Tags
Return values
string_getPrimaryKeyClauses()
get the primary key clauses, depending on the database driver
private
_getPrimaryKeyClauses([string $key = 'dataid' ]) : array<string|int, mixed>
Parameters
- $key : string = 'dataid'
Tags
Return values
array<string|int, mixed>_getTableQuery()
get table list query, depending on the database type
private
_getTableQuery(string $type) : string
Parameters
- $type : string
Tags
Return values
string_getVersionedKeys()
get version dependent key names
private
_getVersionedKeys(int $version) : array<string|int, mixed>
Parameters
- $version : int
Tags
Return values
array<string|int, mixed>_sanitizeIdentifier()
sanitizes identifiers
private
_sanitizeIdentifier(string $identifier) : string
Parameters
- $identifier : string
Tags
Return values
string_select()
run a select statement
private
_select(string $sql, array<string|int, mixed> $params[, bool $firstOnly = false ]) : array<string|int, mixed>|false
Parameters
- $sql : string
- $params : array<string|int, mixed>
- $firstOnly : bool = false
-
if only the first row should be returned
Tags
Return values
array<string|int, mixed>|false_upgradeDatabase()
upgrade the database schema from an old version
private
_upgradeDatabase(string $oldversion) : mixed
Parameters
- $oldversion : string