IDBConnection

interface OCP\IDBConnection
Interface IDBConnection
Implemented by:OC\DB\Connection
Source:lib/public/IDBConnection.php#47

Constants

ADD_MISSING_INDEXES_EVENT = self::class . ::ADD_MISSING_INDEXES
Source:lib/public/IDBConnection.php#49
CHECK_MISSING_INDEXES_EVENT = self::class . ::CHECK_MISSING_INDEXES
Source:lib/public/IDBConnection.php#50

Methods

public OCP\IDBConnection::getQueryBuilder()
Gets the QueryBuilder for the connection.
Source:lib/public/IDBConnection.php#58
Returns:\OCP\DB\QueryBuilder\IQueryBuilder
Since:8.2.0
public OCP\IDBConnection::prepare($sql, $limit=null, $offset=null)
Used to abstract the ownCloud database access away
Source:

lib/public/IDBConnection.php#68

Parameters:
  • $sql (string) the sql query with ? placeholder for params
  • $limit (int) the maximum number of rows
  • $offset (int) from which row we want to start
Returns:

\Doctrine\DBAL\Driver\Statement The prepared statement.

Since:

6.0.0

public OCP\IDBConnection::executeQuery($query, $params=array(), $types=array())
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.
Source:

lib/public/IDBConnection.php#82

Parameters:
  • $query (string) The SQL query to execute.
  • $params (string[]) The parameters to bind to the query, if any.
  • $types (array) The types the previous parameters are in.
Returns:

\Doctrine\DBAL\Driver\Statement The executed statement.

Since:

8.0.0

public OCP\IDBConnection::executeUpdate($query, $params=array(), $types=array())
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/public/IDBConnection.php#96

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

int The number of affected rows.

Since:

8.0.0

public OCP\IDBConnection::lastInsertId($table=null)
Used to get the id of the just inserted element
Source:

lib/public/IDBConnection.php#104

Parameters:
  • $table (string) the name of the table where we inserted the item
Returns:

int the id of the inserted element

Since:

6.0.0

public OCP\IDBConnection::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/public/IDBConnection.php#121

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\DBALException

Since:

6.0.0 - parameter $compare was added in 8.1.0, return type changed from boolean in 8.1.0

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 OCP\IDBConnection::insertIgnoreConflict($table, $values)
Insert a row if the row does not exist. Eventual conflicts during insert will be ignored.
Implementation is not fully finished and should not be used!
Source:

lib/public/IDBConnection.php#135

Parameters:
  • $table (string) The table name (will replace PREFIX with the actual prefix)
  • $values (array) data that should be inserted into the table (column name => value)
Returns:

int number of inserted rows

Since:

16.0.0

public OCP\IDBConnection::setValues($table, $keys, $values, $updatePreconditionValues=[])
Insert or update a row value
Source:

lib/public/IDBConnection.php#149

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\DBALException

Throws:

\OCP\PreconditionNotMetException

Throws:

\Doctrine\DBAL\DBALException

Throws:

\OCP\PreconditionNotMetException

Since:

9.0.0

public OCP\IDBConnection::lockTable($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.
Source:

lib/public/IDBConnection.php#161

Parameters:
  • $tableName (string)
Since:

9.1.0

public OCP\IDBConnection::unlockTable()
Release a previous acquired lock again
Source:lib/public/IDBConnection.php#168
Since:9.1.0
public OCP\IDBConnection::beginTransaction()
Start a transaction
Source:lib/public/IDBConnection.php#174
Since:6.0.0
public OCP\IDBConnection::inTransaction()
Check if a transaction is active
Source:lib/public/IDBConnection.php#182
Returns:bool
Since:8.2.0
public OCP\IDBConnection::commit()
Commit the database changes done during a transaction that is in progress
Source:lib/public/IDBConnection.php#188
Since:6.0.0
public OCP\IDBConnection::rollBack()
Rollback the database changes done during a transaction that is in progress
Source:lib/public/IDBConnection.php#194
Since:6.0.0
public OCP\IDBConnection::getError()
Gets the error code and message as a string for logging
Source:lib/public/IDBConnection.php#201
Returns:string
Since:6.0.0
public OCP\IDBConnection::errorCode()
Fetch the SQLSTATE associated with the last database operation.
Source:lib/public/IDBConnection.php#209
Returns:int The last error code.
Since:8.0.0
public OCP\IDBConnection::errorInfo()
Fetch extended error information associated with the last database operation.
Source:lib/public/IDBConnection.php#217
Returns:array The last error information.
Since:8.0.0
public OCP\IDBConnection::connect()
Establishes the connection with the database.
Source:lib/public/IDBConnection.php#225
Returns:bool
Since:8.0.0
public OCP\IDBConnection::close()
Close the database connection
Source:lib/public/IDBConnection.php#231
Since:8.0.0
public OCP\IDBConnection::quote($input, $type=\OCP\DB\QueryBuilder\IQueryBuilder::PARAM_STR)
Quotes a given input parameter.
Source:

lib/public/IDBConnection.php#241

Parameters:
  • $input (mixed) Parameter to be quoted.
  • $type (int) Type of the parameter.
Returns:

string The quoted parameter.

Since:

8.0.0

public OCP\IDBConnection::getDatabasePlatform()
Gets the DatabasePlatform instance that provides all the metadata about
the platform this driver connects to.
Source:lib/public/IDBConnection.php#250
Returns:\Doctrine\DBAL\Platforms\AbstractPlatform The database platform.
Since:8.0.0
public OCP\IDBConnection::dropTable($table)
Drop a table from the database if it exists
Source:

lib/public/IDBConnection.php#258

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

8.0.0

public OCP\IDBConnection::tableExists($table)
Check if a table exists
Source:

lib/public/IDBConnection.php#267

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

bool

Since:

8.0.0

public OCP\IDBConnection::escapeLikeParameter($param)
Escape a parameter to be used in a LIKE query
Source:

lib/public/IDBConnection.php#276

Parameters:
  • $param (string)
Returns:

string

Since:

9.0.0

public OCP\IDBConnection::supports4ByteText()
Check whether or not the current database support 4byte wide unicode
Source:lib/public/IDBConnection.php#284
Returns:bool
Since:11.0.0
public OCP\IDBConnection::createSchema()
Create the schema of the connected database
Source:lib/public/IDBConnection.php#292
Returns:\Doctrine\DBAL\Schema\Schema
Since:13.0.0
public OCP\IDBConnection::migrateToSchema($toSchema)
Migrate the database to the given schema
Source:

lib/public/IDBConnection.php#300

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

13.0.0