IDBConnection
in
Interface IDBConnection
Tags
Table of Contents
Constants
- PLATFORM_MYSQL = 'mysql'
- PLATFORM_ORACLE = 'oracle'
- PLATFORM_POSTGRES = 'postgres'
- PLATFORM_SQLITE = 'sqlite'
Methods
- beginTransaction() : void
- Start a transaction
- close() : void
- Close the database connection
- commit() : void
- Commit the database changes done during a transaction that is in progress
- connect() : bool
- Establishes the connection with the database.
- createSchema() : Schema
- Create the schema of the connected database
- dropTable() : void
- Drop a table from the database if it exists
- errorCode() : int
- Fetch the SQLSTATE associated with the last database operation.
- errorInfo() : array<string|int, mixed>
- Fetch extended error information associated with the last database operation.
- escapeLikeParameter() : string
- Escape a parameter to be used in a LIKE query
- executeQuery() : IResult
- Executes an, optionally parameterized, SQL query.
- executeStatement() : int
- Executes an SQL INSERT/UPDATE/DELETE query with the given parameters and returns the number of affected rows.
- executeUpdate() : int
- Executes an SQL INSERT/UPDATE/DELETE query with the given parameters and returns the number of affected rows.
- getDatabasePlatform() : AbstractPlatform
- Gets the DatabasePlatform instance that provides all the metadata about the platform this driver connects to.
- getDatabaseProvider() : IDBConnection::PLATFORM_*
- Returns the database provider name
- getError() : string
- Gets the error code and message as a string for logging
- getQueryBuilder() : IQueryBuilder
- Gets the QueryBuilder for the connection.
- insertIfNotExist() : int
- 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.
- insertIgnoreConflict() : int
- Insert a row if the row does not exist. Eventual conflicts during insert will be ignored.
- inTransaction() : bool
- Check if a transaction is active
- lastInsertId() : int
- Used to get the id of the just inserted element
- lockTable() : void
- Create an exclusive read+write lock on a table
- migrateToSchema() : void
- Migrate the database to the given schema
- prepare() : IPreparedStatement
- Used to abstract the Nextcloud database access away
- quote() : mixed
- Quotes a given input parameter.
- rollBack() : void
- Rollback the database changes done during a transaction that is in progress
- setValues() : int
- Insert or update a row value
- supports4ByteText() : bool
- Check whether or not the current database support 4byte wide unicode
- tableExists() : bool
- Check if a table exists
- unlockTable() : void
- Release a previous acquired lock again
Constants
PLATFORM_MYSQL
public
mixed
PLATFORM_MYSQL
= 'mysql'
Tags
PLATFORM_ORACLE
public
mixed
PLATFORM_ORACLE
= 'oracle'
Tags
PLATFORM_POSTGRES
public
mixed
PLATFORM_POSTGRES
= 'postgres'
Tags
PLATFORM_SQLITE
public
mixed
PLATFORM_SQLITE
= 'sqlite'
Tags
Methods
beginTransaction()
Start a transaction
public
beginTransaction() : void
Tags
close()
Close the database connection
public
close() : void
Tags
commit()
Commit the database changes done during a transaction that is in progress
public
commit() : void
Tags
connect()
Establishes the connection with the database.
public
connect() : bool
Tags
Return values
boolcreateSchema()
Create the schema of the connected database
public
createSchema() : Schema
Tags
Return values
SchemadropTable()
Drop a table from the database if it exists
public
dropTable(string $table) : void
Parameters
- $table : string
-
table name without the prefix
Tags
errorCode()
Fetch the SQLSTATE associated with the last database operation.
public
errorCode() : int
Tags
Return values
int —The last error code.
errorInfo()
Fetch extended error information associated with the last database operation.
public
errorInfo() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —The last error information.
escapeLikeParameter()
Escape a parameter to be used in a LIKE query
public
escapeLikeParameter(string $param) : string
Parameters
- $param : string
Tags
Return values
stringexecuteQuery()
Executes an, optionally parameterized, SQL query.
public
executeQuery(string $sql[, array<string|int, string> $params = [] ][, array<string|int, mixed> $types = [] ]) : IResult
If the query is parameterized, a prepared statement is used. If an SQLLogger is configured, the execution is logged.
Parameters
- $sql : string
-
The SQL query to execute.
- $params : array<string|int, string> = []
-
The parameters to bind to the query, if any.
- $types : array<string|int, mixed> = []
-
The types the previous parameters are in.
Tags
Return values
IResult —The executed statement.
executeStatement()
Executes an SQL INSERT/UPDATE/DELETE query with the given parameters and returns the number of affected rows.
public
executeStatement(string $sql[, array<string|int, mixed> $params = [] ][, array<string|int, mixed> $types = [] ]) : int
This method supports PDO binding types as well as DBAL mapping types.
Parameters
- $sql : string
-
The SQL query.
- $params : array<string|int, mixed> = []
-
The query parameters.
- $types : array<string|int, mixed> = []
-
The parameter types.
Tags
Return values
int —The number of affected rows.
executeUpdate()
Executes an SQL INSERT/UPDATE/DELETE query with the given parameters and returns the number of affected rows.
public
executeUpdate(string $sql[, array<string|int, mixed> $params = [] ][, array<string|int, mixed> $types = [] ]) : int
This method supports PDO binding types as well as DBAL mapping types.
Parameters
- $sql : string
-
The SQL query.
- $params : array<string|int, mixed> = []
-
The query parameters.
- $types : array<string|int, mixed> = []
-
The parameter types.
Tags
Return values
int —The number of affected rows.
getDatabasePlatform()
Gets the DatabasePlatform instance that provides all the metadata about the platform this driver connects to.
public
getDatabasePlatform() : AbstractPlatform
Tags
Return values
AbstractPlatform —The database platform.
getDatabaseProvider()
Returns the database provider name
public
getDatabaseProvider() : IDBConnection::PLATFORM_*
Tags
Return values
IDBConnection::PLATFORM_*getError()
Gets the error code and message as a string for logging
public
getError() : string
Tags
Return values
stringgetQueryBuilder()
Gets the QueryBuilder for the connection.
public
getQueryBuilder() : IQueryBuilder
Tags
Return values
IQueryBuilderinsertIfNotExist()
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.
public
insertIfNotExist(string $table, array<string|int, mixed> $input[, array<string|int, mixed>|null $compare = null ]) : int
Parameters
- $table : string
-
The table name (will replace PREFIX with the actual prefix)
- $input : array<string|int, mixed>
-
data that should be inserted into the table (column name => value)
- $compare : array<string|int, mixed>|null = 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
Tags
Return values
int —number of inserted rows
insertIgnoreConflict()
Insert a row if the row does not exist. Eventual conflicts during insert will be ignored.
public
insertIgnoreConflict(string $table, array<string|int, mixed> $values) : int
Implementation is not fully finished and should not be used!
Parameters
- $table : string
-
The table name (will replace PREFIX with the actual prefix)
- $values : array<string|int, mixed>
-
data that should be inserted into the table (column name => value)
Tags
Return values
int —number of inserted rows
inTransaction()
Check if a transaction is active
public
inTransaction() : bool
Tags
Return values
boollastInsertId()
Used to get the id of the just inserted element
public
lastInsertId(string $table) : int
Parameters
- $table : string
-
the name of the table where we inserted the item
Tags
Return values
int —the id of the inserted element
lockTable()
Create an exclusive read+write lock on a table
public
lockTable(string $tableName) : void
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
- $tableName : string
Tags
migrateToSchema()
Migrate the database to the given schema
public
migrateToSchema(Schema $toSchema) : void
Parameters
- $toSchema : Schema
Tags
prepare()
Used to abstract the Nextcloud database access away
public
prepare(string $sql[, int|null $limit = null ][, int|null $offset = null ]) : IPreparedStatement
Parameters
- $sql : string
-
the sql query with ? placeholder for params
- $limit : int|null = null
-
the maximum number of rows
- $offset : int|null = null
-
from which row we want to start
Tags
Return values
IPreparedStatement —The prepared statement.
quote()
Quotes a given input parameter.
public
quote(mixed $input[, int $type = IQueryBuilder::PARAM_STR ]) : mixed
Parameters
- $input : mixed
-
Parameter to be quoted.
- $type : int = IQueryBuilder::PARAM_STR
-
Type of the parameter.
Tags
Return values
mixed —The quoted parameter.
rollBack()
Rollback the database changes done during a transaction that is in progress
public
rollBack() : void
Tags
setValues()
Insert or update a row value
public
setValues(string $table, array<string|int, mixed> $keys, array<string|int, mixed> $values[, array<string|int, mixed> $updatePreconditionValues = [] ]) : int
Parameters
- $table : string
- $keys : array<string|int, mixed>
-
(column name => value)
- $values : array<string|int, mixed>
-
(column name => value)
- $updatePreconditionValues : array<string|int, mixed> = []
-
ensure values match preconditions (column name => value)
Tags
Return values
int —number of new rows
supports4ByteText()
Check whether or not the current database support 4byte wide unicode
public
supports4ByteText() : bool
Tags
Return values
booltableExists()
Check if a table exists
public
tableExists(string $table) : bool
Parameters
- $table : string
-
table name without the prefix
Tags
Return values
boolunlockTable()
Release a previous acquired lock again
public
unlockTable() : void