Documentation

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
access

protected

$_db

instance of database connection

private PDO $_db
Tags
access

private

$_prefix

table prefix

private string $_prefix = ''
Tags
access

private

$_type

database type

private string $_type = ''
Tags
access

private

Methods

__construct()

instantiates a new Database data backend

public __construct(array<string|int, mixed> $options) : mixed
Parameters
$options : array<string|int, mixed>
Tags
access

public

throws
Exception

_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
access

public

static
Return values
int|string

create()

Create a paste.

public create(string $pasteid, array<string|int, mixed> $paste) : bool
Parameters
$pasteid : string
$paste : array<string|int, mixed>
Tags
access

public

Return values
bool

createComment()

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
access

public

Return values
bool

delete()

Delete a paste and its discussion.

public delete(string $pasteid) : mixed
Parameters
$pasteid : string
Tags
access

public

exists()

Test if a paste exists.

public exists(string $pasteid) : bool
Parameters
$pasteid : string
Tags
access

public

Return values
bool

existsComment()

Test if a comment exists.

public existsComment(string $pasteid, string $parentid, string $commentid) : bool
Parameters
$pasteid : string
$parentid : string
$commentid : string
Tags
access

public

Return values
bool

getAllPastes()

Returns all paste ids

public getAllPastes() : array<string|int, mixed>
Tags
inheritDoc
Return values
array<string|int, mixed>

getValue()

Load a value.

public getValue(string $namespace[, string $key = '' ]) : string
Parameters
$namespace : string
$key : string = ''
Tags
access

public

Return values
string

purge()

Perform a purge of old pastes, at most the given batchsize is deleted.

public purge(int $batchsize) : mixed
Parameters
$batchsize : int
Tags
access

public

purgeValues()

Purge outdated entries.

public purgeValues(string $namespace, int $time) : void
Parameters
$namespace : string
$time : int
Tags
access

public

read()

Read a paste.

public read(string $pasteid) : array<string|int, mixed>|false
Parameters
$pasteid : string
Tags
access

public

Return values
array<string|int, mixed>|false

readComments()

Read all comments of paste.

public readComments(string $pasteid) : array<string|int, mixed>
Parameters
$pasteid : string
Tags
access

public

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
access

public

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
access

private

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
access

protected

Return values
int|string

upgradePreV1Format()

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
access

protected

static
Return values
array<string|int, mixed>

_createCommentTable()

create the paste table

private _createCommentTable() : mixed
Tags
access

private

_createConfigTable()

create the paste table

private _createConfigTable() : mixed
Tags
access

private

_createPasteTable()

create the paste table

private _createPasteTable() : mixed
Tags
access

private

_exec()

execute a statement

private _exec(string $sql, array<string|int, mixed> $params) : bool
Parameters
$sql : string
$params : array<string|int, mixed>
Tags
access

private

throws
PDOException
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
access

private

Return values
string

_getConfig()

get a value by key from the config table

private _getConfig(string $key) : string
Parameters
$key : string
Tags
access

private

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
access

private

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
access

private

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
access

private

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
access

private

throws
Exception
Return values
string

_getVersionedKeys()

get version dependent key names

private _getVersionedKeys(int $version) : array<string|int, mixed>
Parameters
$version : int
Tags
access

private

Return values
array<string|int, mixed>

_sanitizeIdentifier()

sanitizes identifiers

private _sanitizeIdentifier(string $identifier) : string
Parameters
$identifier : string
Tags
access

private

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
access

private

throws
PDOException
Return values
array<string|int, mixed>|false

_upgradeDatabase()

upgrade the database schema from an old version

private _upgradeDatabase(string $oldversion) : mixed
Parameters
$oldversion : string
Tags
access

private


        
On this page

Search results