Properties

$_last_cache

$_last_cache :array

cache for the traffic limiter

Type

array

$_cache

$_cache :array

cache for select queries

Type

array

$_db

$_db :\PDO

instance of database connection

Type

\PDO

$_prefix

$_prefix :string

table prefix

Type

string

$_type

$_type :string

database type

Type

string

Methods

getInstance()

getInstance(array  $options): \PrivateBin\Data\Database

get instance of singleton

Parameters

array $options

Throws

\Exception

Returns

\PrivateBin\Data\Database

create()

create(string  $pasteid,array  $paste): boolean

Create a paste.

Parameters

string $pasteid
array $paste

Returns

boolean

read()

read(string  $pasteid): array|false

Read a paste.

Parameters

string $pasteid

Returns

array|false

delete()

delete(string  $pasteid)

Delete a paste and its discussion.

Parameters

string $pasteid

exists()

exists(string  $pasteid): boolean

Test if a paste exists.

Parameters

string $pasteid

Returns

boolean

createComment()

createComment(string  $pasteid,string  $parentid,string  $commentid,array  $comment): boolean

Create a comment in a paste.

Parameters

string $pasteid
string $parentid
string $commentid
array $comment

Returns

boolean

readComments()

readComments(string  $pasteid): array

Read all comments of paste.

Parameters

string $pasteid

Returns

array

existsComment()

existsComment(string  $pasteid,string  $parentid,string  $commentid): boolean

Test if a comment exists.

Parameters

string $pasteid
string $parentid
string $commentid

Returns

boolean

purgeValues()

purgeValues(string  $namespace,integer  $time): void

Purge outdated entries.

Parameters

string $namespace
integer $time

setValue()

setValue(string  $value,string  $namespace,string  $key = ''): boolean

Save a value.

Parameters

string $value
string $namespace
string $key

Returns

boolean

getValue()

getValue(string  $namespace,string  $key = ''): string

Load a value.

Parameters

string $namespace
string $key

Returns

string

purge()

purge(integer  $batchsize)

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

Parameters

integer $batchsize

__construct()

__construct()

Enforce singleton, disable constructor

Instantiate using \getInstance(), this object implements the singleton pattern.

_getExpiredPastes()

_getExpiredPastes(integer  $batchsize): array

Returns up to batch size number of paste ids that have expired

Parameters

integer $batchsize

Returns

array

getOpenSlot()

getOpenSlot(array  $comments,integer|string  $postdate): integer|string

Get next free slot for comment from postdate.

Parameters

array $comments
integer|string $postdate

Returns

integer|string

upgradePreV1Format()

upgradePreV1Format(array  $paste): array

Upgrade pre-version 1 pastes with attachment to version 1 format.

Parameters

array $paste

Returns

array

__clone()

__clone()

Enforce singleton, disable cloning

Instantiate using \getInstance(), this object implements the singleton pattern.

_exec()

_exec(string  $sql,array  $params): boolean

execute a statement

Parameters

string $sql
array $params

Throws

\PDOException

Returns

boolean

_select()

_select(string  $sql,array  $params,boolean  $firstOnly = false): array|false

run a select statement

Parameters

string $sql
array $params
boolean $firstOnly

if only the first row should be returned

Throws

\PDOException

Returns

array|false

_getVersionedKeys()

_getVersionedKeys(integer  $version): array

get version dependent key names

Parameters

integer $version

Returns

array

_getTableQuery()

_getTableQuery(string  $type): string

get table list query, depending on the database type

Parameters

string $type

Throws

\Exception

Returns

string

_getConfig()

_getConfig(string  $key): string

get a value by key from the config table

Parameters

string $key

Returns

string

_getPrimaryKeyClauses()

_getPrimaryKeyClauses(string  $key = 'dataid'): array

get the primary key clauses, depending on the database driver

Parameters

string $key

Returns

array

_getDataType()

_getDataType(): string

get the data type, depending on the database driver

PostgreSQL and OCI uses a different API for BLOBs then SQL, hence we use TEXT and CLOB

Returns

string

_getAttachmentType()

_getAttachmentType(): string

get the attachment type, depending on the database driver

PostgreSQL and OCI use different APIs for BLOBs then SQL, hence we use TEXT and CLOB

Returns

string

_getMetaType()

_getMetaType(): string

get the meta type, depending on the database driver

OCI doesn't accept TEXT so it has to be VARCHAR2(4000)

Returns

string

_createPasteTable()

_createPasteTable()

create the paste table

_createCommentTable()

_createCommentTable()

create the paste table

_createConfigTable()

_createConfigTable()

create the paste table

_sanitizeIdentifier()

_sanitizeIdentifier(string  $identifier): string

sanitizes identifiers

Parameters

string $identifier

Returns

string

_upgradeDatabase()

_upgradeDatabase(string  $oldversion)

upgrade the database schema from an old version

Parameters

string $oldversion