Methods

prepare()

prepare(string  $sql, integer  $limit = null, integer  $offset = null) : \Doctrine\DBAL\Driver\Statement

Used to abstract the ownCloud database access away

Parameters

string $sql

the sql query with ? placeholder for params

integer $limit

the maximum number of rows

integer $offset

from which row we want to start

Returns

\Doctrine\DBAL\Driver\Statement —

The prepared statement.

executeQuery()

executeQuery(string  $query, array<mixed,string>  $params = array(), array  $types = array()) : \Doctrine\DBAL\Driver\Statement

Executes an, optionally parameterized, SQL query.

If the query is parameterized, a prepared statement is used. If an SQLLogger is configured, the execution is logged.

Parameters

string $query

The SQL query to execute.

array<mixed,string> $params

The parameters to bind to the query, if any.

array $types

The types the previous parameters are in.

Returns

\Doctrine\DBAL\Driver\Statement —

The executed statement.

executeUpdate()

executeUpdate(string  $query, array  $params = array(), array  $types = array()) : integer

Executes an SQL INSERT/UPDATE/DELETE query with the given parameters and returns the number of affected rows.

This method supports PDO binding types as well as DBAL mapping types.

Parameters

string $query

The SQL query.

array $params

The query parameters.

array $types

The parameter types.

Returns

integer —

The number of affected rows.

lastInsertId()

lastInsertId(string  $table = null) : integer

Used to get the id of the just inserted element

Parameters

string $table

the name of the table where we inserted the item

Returns

integer —

the id of the inserted element

insertIfNotExist()

insertIfNotExist(string  $table, array  $input, array|null  $compare = null) : integer

Insert a row if the matching row does not exists.

Parameters

string $table

The table name (will replace PREFIX with the actual prefix)

array $input

data that should be inserted into the table (column name => value)

array|null $compare

List of values that should be checked for "if not exists" If this is null or an empty array, all keys of $input will be compared Please note: text fields (clob) must not be used in the compare array

Throws

\Doctrine\DBAL\DBALException

Returns

integer —

number of inserted rows

setValues()

setValues(string  $table, array  $keys, array  $values, array  $updatePreconditionValues = array()) : integer

Insert or update a row value

Parameters

string $table
array $keys

(column name => value)

array $values

(column name => value)

array $updatePreconditionValues

ensure values match preconditions (column name => value)

Throws

\Doctrine\DBAL\DBALException
\OCP\PreconditionNotMetException

Returns

integer —

number of new rows

lockTable()

lockTable(string  $tableName) 

Create an exclusive read+write lock on a table

Important Note: Due to the nature how locks work on different DBs, it is only possible to lock one table at a time. You should also NOT start a transaction while holding a lock.

Parameters

string $tableName

unlockTable()

unlockTable() 

Release a previous acquired lock again

beginTransaction()

beginTransaction() 

Start a transaction

inTransaction()

inTransaction() : boolean

Check if a transaction is active

Returns

boolean

commit()

commit() 

Commit the database changes done during a transaction that is in progress

rollBack()

rollBack() 

Rollback the database changes done during a transaction that is in progress

getError()

getError() : string

Gets the error code and message as a string for logging

Returns

string

errorCode()

errorCode() : integer

Fetch the SQLSTATE associated with the last database operation.

Returns

integer —

The last error code.

errorInfo()

errorInfo() : array

Fetch extended error information associated with the last database operation.

Returns

array —

The last error information.

connect()

connect() : boolean

Establishes the connection with the database.

Returns

boolean

close()

close() 

Close the database connection

quote()

quote(mixed  $input, integer  $type = \OCP\DB\QueryBuilder\IQueryBuilder::PARAM_STR) : string

Quotes a given input parameter.

Parameters

mixed $input

Parameter to be quoted.

integer $type

Type of the parameter.

Returns

string —

The quoted parameter.

getDatabasePlatform()

getDatabasePlatform() : \Doctrine\DBAL\Platforms\AbstractPlatform

Gets the DatabasePlatform instance that provides all the metadata about the platform this driver connects to.

Returns

\Doctrine\DBAL\Platforms\AbstractPlatform —

The database platform.

dropTable()

dropTable(string  $table) 

Drop a table from the database if it exists

Parameters

string $table

table name without the prefix

tableExists()

tableExists(string  $table) : boolean

Check if a table exists

Parameters

string $table

table name without the prefix

Returns

boolean

escapeLikeParameter()

escapeLikeParameter(string  $param) : string

Escape a parameter to be used in a LIKE query

Parameters

string $param

Returns

string

createSchema()

createSchema() : \Doctrine\DBAL\Schema\Schema

Create the schema of the connected database

Returns

\Doctrine\DBAL\Schema\Schema

migrateToSchema()

migrateToSchema(\Doctrine\DBAL\Schema\Schema  $toSchema) 

Migrate the database to the given schema

Parameters

\Doctrine\DBAL\Schema\Schema $toSchema

getTransactionIsolation()

getTransactionIsolation() : integer

Gets the currently active transaction isolation level.

Returns

integer —

The current transaction isolation level.

allows4ByteCharacters()

allows4ByteCharacters() : boolean

Are 4-byte characters allowed or only 3-byte

Returns

boolean

prepareQuery()

prepareQuery(string  $sql, integer  $limit = null, integer  $offset = null) : \OC_DB_StatementWrapper

Used to abstract the owncloud database access away

Parameters

string $sql

the sql query with ? placeholder for params

integer $limit

the maximum number of rows

integer $offset

from which row we want to start

Returns

\OC_DB_StatementWrapper —

prepared SQL query

getInsertId()

getInsertId(string  $tableName) : integer

Used to get the id of the just inserted element

Parameters

string $tableName

the name of the table where we inserted the item

Returns

integer —

the id of the inserted element