Connection

class OC\DB\Connection
Source:lib/private/DB/Connection.php#59
Parent:Doctrine\DBAL\Connection

Properties

protected static property OC\DB\Connection::$tablePrefix
Source:lib/private/DB/Connection.php#61
Type:string
protected static property OC\DB\Connection::$adapter
Source:lib/private/DB/Connection.php#64
Type:\OC\DB\Adapter
protected static property OC\DB\Connection::$lockedTable
Source:lib/private/DB/Connection.php#72
protected static property OC\DB\Connection::$queriesBuilt
Source:lib/private/DB/Connection.php#75
Type:int
protected static property OC\DB\Connection::$queriesExecuted
Source:lib/private/DB/Connection.php#78
Type:int

Methods

public OC\DB\Connection::connect()
Source:lib/private/DB/Connection.php#83
Throws:\Doctrine\DBAL\Exception
public OC\DB\Connection::getStats()
Source:lib/private/DB/Connection.php#92
public OC\DB\Connection::getQueryBuilder()
Returns a QueryBuilder for the connection.
Source:lib/private/DB/Connection.php#102
public OC\DB\Connection::createQueryBuilder()
Gets the QueryBuilder for the connection.
Source:lib/private/DB/Connection.php#117
Returns:\Doctrine\DBAL\Query\QueryBuilder
Deprecated:please use $this->getQueryBuilder() instead
public OC\DB\Connection::getExpressionBuilder()
Gets the ExpressionBuilder for the connection.
Source:lib/private/DB/Connection.php#130
Returns:\Doctrine\DBAL\Query\Expression\ExpressionBuilder
Deprecated:please use $this->getQueryBuilder()->expr() instead
protected OC\DB\Connection::getCallerBacktrace()
Get the file and line that called the method where `getCallerBacktrace()` was used
Source:lib/private/DB/Connection.php#142
Returns:string
public OC\DB\Connection::getPrefix()
Source:lib/private/DB/Connection.php#157
Returns:string
public OC\DB\Connection::__construct($params, $driver, $config=null, $eventManager=null)
Initializes a new instance of the Connection class.
Source:

lib/private/DB/Connection.php#170

Parameters:
  • $params (array) The connection parameters.
  • $driver (Doctrine\DBAL\Driver)
  • $config (Doctrine\DBAL\Configuration)
  • $eventManager (Doctrine\Common\EventManager)
Throws:

\Exception

public OC\DB\Connection::prepare($statement, $limit=null, $offset=null)
Prepares an SQL statement.
Source:

lib/private/DB/Connection.php#199

Parameters:
  • $statement (string) The SQL statement to prepare.
  • $limit (int)
  • $offset (int)
Returns:

\Doctrine\DBAL\Statement The prepared statement.

Throws:

\Doctrine\DBAL\Exception

public OC\DB\Connection::executeQuery($sql, $params=[], $types=[], $qcp=null)
Executes an, optionally parametrized, SQL query.
If the query is parametrized, a prepared statement is used.
If an SQLLogger is configured, the execution is logged.
Source:

lib/private/DB/Connection.php#228

Parameters:
  • $sql (string) The SQL query to execute.
  • $params (array) The parameters to bind to the query, if any.
  • $types (array) The types the previous parameters are in.
  • $qcp (Doctrine\DBAL\Cache\QueryCacheProfile | null) The query cache profile, optional.
Returns:

\Doctrine\DBAL\Result The executed statement.

Throws:

\Doctrine\DBAL\Exception

public OC\DB\Connection::executeUpdate($sql, $params=[], $types=[])
Source:lib/private/DB/Connection.php#238
Throws:\Doctrine\DBAL\Exception
public OC\DB\Connection::executeStatement($sql, $params=[], $types=[])
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.
Source:

lib/private/DB/Connection.php#259

Parameters:
  • $sql (string) The SQL query.
  • $params (array) The query parameters.
  • $types (array) The parameter types.
Returns:

int The number of affected rows.

Throws:

\Doctrine\DBAL\Exception

public OC\DB\Connection::lastInsertId($seqName=null)
Returns the ID of the last inserted row, or the last value from a sequence object,
depending on the underlying driver.
Note: This method may not return a meaningful or consistent result across different drivers,
because the underlying database may not even support the notion of AUTO_INCREMENT/IDENTITY
columns or sequences.
Source:

lib/private/DB/Connection.php#279

Parameters:
  • $seqName (string) Name of the sequence object from which the ID should be returned.
Returns:

string the last inserted ID.

Throws:

\Doctrine\DBAL\Exception

public OC\DB\Connection::realLastInsertId($seqName=null)
Source:lib/private/DB/Connection.php#290
Throws:\Doctrine\DBAL\Exception
public OC\DB\Connection::insertIfNotExist($table, $input, $compare=null)
Insert a row if the matching row does not exists. To accomplish proper race condition avoidance
it is needed that there is also a unique constraint on the values. Then this method will
catch the exception and return 0.
Source:

lib/private/DB/Connection.php#308

Parameters:
  • $table (string) The table name (will replace PREFIX with the actual prefix)
  • $input (array) data that should be inserted into the table (column name => value)
  • $compare (array | null) 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

Returns:

int number of inserted rows

Throws:

\Doctrine\DBAL\Exception

Deprecated:

15.0.0 - use unique index and “try { $db->insert() } catch (UniqueConstraintViolationException $e) }” instead, because it is more reliable and does not have the risk for deadlocks - see https://github.com/nextcloud/server/pull/12371

public OC\DB\Connection::insertIgnoreConflict($table, $values)
Source:lib/private/DB/Connection.php#312
public OC\DB\Connection::setValues($table, $keys, $values, $updatePreconditionValues=[])
Insert or update a row value
Source:

lib/private/DB/Connection.php#337

Parameters:
  • $table (string)
  • $keys (array) (column name => value)
  • $values (array) (column name => value)
  • $updatePreconditionValues (array) ensure values match preconditions (column name => value)
Returns:

int number of new rows

Throws:

\Doctrine\DBAL\Exception

Throws:

\OCP\PreConditionNotMetException

Throws:

\Doctrine\DBAL\Exception

Throws:

\OCP\PreConditionNotMetException

public OC\DB\Connection::lockTable($tableName)
Create an exclusive read+write lock on a table
Source:

lib/private/DB/Connection.php#391

Parameters:
  • $tableName (string)
Throws:

\BadMethodCallException When trying to acquire a second lock

Throws:

\Doctrine\DBAL\Exception

Throws:

\BadMethodCallException When trying to acquire a second lock

Throws:

\Doctrine\DBAL\Exception

Since:

9.1.0

public OC\DB\Connection::unlockTable()
Release a previous acquired lock again
Source:lib/private/DB/Connection.php#407
Throws:\Doctrine\DBAL\Exception
Since:9.1.0
public OC\DB\Connection::getError()
returns the error code and message as a string for logging
works with DoctrineException
Source:lib/private/DB/Connection.php#417
Returns:string
public OC\DB\Connection::errorCode()
Source:lib/private/DB/Connection.php#428
public OC\DB\Connection::errorInfo()
Source:lib/private/DB/Connection.php#432
public OC\DB\Connection::dropTable($table)
Drop a table from the database if it exists
Source:

lib/private/DB/Connection.php#443

Parameters:
  • $table (string) table name without the prefix
Throws:

\Doctrine\DBAL\Exception

public OC\DB\Connection::tableExists($table)
Check if a table exists
Source:

lib/private/DB/Connection.php#459

Parameters:
  • $table (string) table name without the prefix
Returns:

bool

Throws:

\Doctrine\DBAL\Exception

protected OC\DB\Connection::replaceTablePrefix($statement)
Source:

lib/private/DB/Connection.php#470

Parameters:
  • $statement (string)
Returns:

string

public OC\DB\Connection::inTransaction()
Check if a transaction is active
Source:lib/private/DB/Connection.php#480
Returns:bool
Since:8.2.0
public OC\DB\Connection::escapeLikeParameter($param)
Escape a parameter to be used in a LIKE query
Source:

lib/private/DB/Connection.php#490

Parameters:
  • $param (string)
Returns:

string

public OC\DB\Connection::supports4ByteText()
Check whether or not the current database support 4byte wide unicode
Source:lib/private/DB/Connection.php#500
Returns:bool
Since:11.0.0
public OC\DB\Connection::createSchema()
Create the schema of the connected database
Source:lib/private/DB/Connection.php#514
Returns:\Doctrine\DBAL\Schema\Schema
Throws:\Doctrine\DBAL\Exception
public OC\DB\Connection::migrateToSchema($toSchema)
Migrate the database to the given schema
Source:

lib/private/DB/Connection.php#526

Parameters:
  • $toSchema (Doctrine\DBAL\Schema\Schema)
Throws:

\Doctrine\DBAL\Exception