IQueryBuilder

interface OCP\DB\QueryBuilder\IQueryBuilder
This class provides a wrapper around Doctrine’s QueryBuilder
Implemented by:OC\DB\QueryBuilder\QueryBuilder
Source:lib/public/DB/QueryBuilder/IQueryBuilder.php#41

Constants

PARAM_NULL = \PDO::PARAM_NULL
Source:lib/public/DB/QueryBuilder/IQueryBuilder.php#46
Since:9.0.0
PARAM_BOOL = \PDO::PARAM_BOOL
Source:lib/public/DB/QueryBuilder/IQueryBuilder.php#50
Since:9.0.0
PARAM_INT = \PDO::PARAM_INT
Source:lib/public/DB/QueryBuilder/IQueryBuilder.php#54
Since:9.0.0
PARAM_STR = \PDO::PARAM_STR
Source:lib/public/DB/QueryBuilder/IQueryBuilder.php#58
Since:9.0.0
PARAM_LOB = \PDO::PARAM_LOB
Source:lib/public/DB/QueryBuilder/IQueryBuilder.php#62
Since:9.0.0
PARAM_DATE = datetime
Source:lib/public/DB/QueryBuilder/IQueryBuilder.php#66
Since:9.0.0
PARAM_INT_ARRAY = \Doctrine\DBAL\Connection::PARAM_INT_ARRAY
Source:lib/public/DB/QueryBuilder/IQueryBuilder.php#71
Since:9.0.0
PARAM_STR_ARRAY = \Doctrine\DBAL\Connection::PARAM_STR_ARRAY
Source:lib/public/DB/QueryBuilder/IQueryBuilder.php#75
Since:9.0.0

Methods

public OCP\DB\QueryBuilder\IQueryBuilder::automaticTablePrefix($enabled)
Enable/disable automatic prefixing of table names with the oc_ prefix
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#85

Parameters:
  • $enabled (bool) If set to true table names will be prefixed with the

owncloud database prefix automatically.

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::expr()
Gets an ExpressionBuilder used for object-oriented construction of query expressions.
This producer method is intended for convenient inline usage. Example:

<code>
$qb = $conn->getQueryBuilder()
->select(‘u’)
->from(‘users’, ‘u’)
->where($qb->expr()->eq(‘u.id’, 1));
</code>

For more complex expression construction, consider storing the expression
builder object in a local variable.
Source:lib/public/DB/QueryBuilder/IQueryBuilder.php#104
Returns:\OCP\DB\QueryBuilder\IExpressionBuilder
Since:8.2.0
public OCP\DB\QueryBuilder\IQueryBuilder::func()
Gets an FunctionBuilder used for object-oriented construction of query functions.
This producer method is intended for convenient inline usage. Example:

<code>
$qb = $conn->getQueryBuilder()
->select(‘u’)
->from(‘users’, ‘u’)
->where($qb->fun()->md5(‘u.id’));
</code>

For more complex function construction, consider storing the function
builder object in a local variable.
Source:lib/public/DB/QueryBuilder/IQueryBuilder.php#123
Returns:\OCP\DB\QueryBuilder\IFunctionBuilder
Since:12.0.0
public OCP\DB\QueryBuilder\IQueryBuilder::getType()
Gets the type of the currently built query.
Source:lib/public/DB/QueryBuilder/IQueryBuilder.php#131
Returns:int
Since:8.2.0
public OCP\DB\QueryBuilder\IQueryBuilder::getConnection()
Gets the associated DBAL Connection for this query builder.
Source:lib/public/DB/QueryBuilder/IQueryBuilder.php#139
Returns:\OCP\IDBConnection
Since:8.2.0
public OCP\DB\QueryBuilder\IQueryBuilder::getState()
Gets the state of this query builder instance.
Source:lib/public/DB/QueryBuilder/IQueryBuilder.php#147
Returns:int Either QueryBuilder::STATE_DIRTY or QueryBuilder::STATE_CLEAN.
Since:8.2.0
public OCP\DB\QueryBuilder\IQueryBuilder::execute()
Executes this query using the bound parameters and their types.
Uses {@see \OCP\DB\QueryBuilder\Connection::executeQuery} for select statements and {@see \OCP\DB\QueryBuilder\Connection::executeStatement}
for insert, update and delete statements.

Warning: until Nextcloud 20, this method could return a \Doctrine\DBAL\Driver\Statement but since
that interface changed in a breaking way the adapter \OCP\DB\QueryBuilder\IStatement is returned
to bridge old code to the new API
Source:lib/public/DB/QueryBuilder/IQueryBuilder.php#164
Returns:\OCP\DB\IResult | int
Throws:\OCP\DB\Exception since 21.0.0
Since:8.2.0
Deprecated:22.0.0 Use executeQuery or executeUpdate
public OCP\DB\QueryBuilder\IQueryBuilder::executeQuery()
Execute for select statements
Source:lib/public/DB/QueryBuilder/IQueryBuilder.php#175
Returns:\OCP\DB\IResult
Since:22.0.0
Throws:\OCP\DB\Exception
Throws:\RuntimeException in case of usage with non select query
Throws:\OCP\DB\Exception
Throws:\RuntimeException in case of usage with non select query
public OCP\DB\QueryBuilder\IQueryBuilder::executeStatement()
Execute insert, update and delete statements
Source:lib/public/DB/QueryBuilder/IQueryBuilder.php#186
Returns:int the number of affected rows
Since:22.0.0
Throws:\OCP\DB\Exception
Throws:\RuntimeException in case of usage with select query
Throws:\OCP\DB\Exception
Throws:\RuntimeException in case of usage with select query
public OCP\DB\QueryBuilder\IQueryBuilder::getSQL()
Gets the complete SQL string formed by the current specifications of this QueryBuilder.
<code>
$qb = $conn->getQueryBuilder()
->select(‘u’)
->from(‘User’, ‘u’)
echo $qb->getSQL(); // SELECT u FROM User u
</code>
Source:lib/public/DB/QueryBuilder/IQueryBuilder.php#201
Returns:string The SQL query string.
Since:8.2.0
public OCP\DB\QueryBuilder\IQueryBuilder::setParameter($key, $value, $type=null)
Sets a query parameter for the query being constructed.
<code>
$qb = $conn->getQueryBuilder()
->select(‘u’)
->from(‘users’, ‘u’)
->where(‘u.id = :user_id’)
->setParameter(‘:user_id’, 1);
</code>
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#221

Parameters:
  • $key (string | int) The parameter position or name.
  • $value (mixed) The parameter value.
  • $type (string | null | int) One of the IQueryBuilder::PARAM_* constants.
Returns:

$this This QueryBuilder instance.

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::setParameters($params, $types=[])
Sets a collection of query parameters for the query being constructed.
<code>
$qb = $conn->getQueryBuilder()
->select(‘u’)
->from(‘users’, ‘u’)
->where(‘u.id = :user_id1 OR u.id = :user_id2’)
->setParameters(array(
‘:user_id1’ => 1,
‘:user_id2’ => 2
));
</code>
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#243

Parameters:
  • $params (array) The query parameters to set.
  • $types (array) The query parameters types to set.
Returns:

$this This QueryBuilder instance.

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::getParameters()
Gets all defined query parameters for the query being constructed indexed by parameter index or name.
Source:lib/public/DB/QueryBuilder/IQueryBuilder.php#251
Returns:array The currently defined query parameters indexed by parameter index or name.
Since:8.2.0
public OCP\DB\QueryBuilder\IQueryBuilder::getParameter($key)
Gets a (previously set) query parameter of the query being constructed.
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#261

Parameters:
  • $key (mixed) The key (index or name) of the bound parameter.
Returns:

mixed The value of the bound parameter.

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::getParameterTypes()
Gets all defined query parameter types for the query being constructed indexed by parameter index or name.
Source:lib/public/DB/QueryBuilder/IQueryBuilder.php#269
Returns:array The currently defined query parameter types indexed by parameter index or name.
Since:8.2.0
public OCP\DB\QueryBuilder\IQueryBuilder::getParameterType($key)
Gets a (previously set) query parameter type of the query being constructed.
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#279

Parameters:
  • $key (mixed) The key (index or name) of the bound parameter type.
Returns:

mixed The value of the bound parameter type.

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::setFirstResult($firstResult)
Sets the position of the first result to retrieve (the “offset”).
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#289

Parameters:
  • $firstResult (int) The first result to return.
Returns:

$this This QueryBuilder instance.

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::getFirstResult()
Gets the position of the first result the query object was set to retrieve (the “offset”).
Returns NULL if {@link setFirstResult} was not applied to this QueryBuilder.
Source:lib/public/DB/QueryBuilder/IQueryBuilder.php#298
Returns:int The position of the first result.
Since:8.2.0
public OCP\DB\QueryBuilder\IQueryBuilder::setMaxResults($maxResults)
Sets the maximum number of results to retrieve (the “limit”).
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#308

Parameters:
  • $maxResults (int) The maximum number of results to retrieve.
Returns:

$this This QueryBuilder instance.

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::getMaxResults()
Gets the maximum number of results the query object was set to retrieve (the “limit”).
Returns NULL if {@link setMaxResults} was not applied to this query builder.
Source:lib/public/DB/QueryBuilder/IQueryBuilder.php#317
Returns:int | null The maximum number of results.
Since:8.2.0
public OCP\DB\QueryBuilder\IQueryBuilder::select(...$selects)
Specifies an item that is to be returned in the query result.
Replaces any previously specified selections, if any.

<code>
$qb = $conn->getQueryBuilder()
->select(‘u.id’, ‘p.id’)
->from(‘users’, ‘u’)
->leftJoin(‘u’, ‘phonenumbers’, ‘p’, ‘u.id = p.user_id’);
</code>
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#337

Parameters:
  • $selects (mixed) The selection expressions.
Returns:

$this This QueryBuilder instance.

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::selectAlias($select, $alias)
Specifies an item that is to be returned with a different name in the query result.
<code>
$qb = $conn->getQueryBuilder()
->selectAlias(‘u.id’, ‘user_id’)
->from(‘users’, ‘u’)
->leftJoin(‘u’, ‘phonenumbers’, ‘p’, ‘u.id = p.user_id’);
</code>
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#358

Parameters:
  • $select (mixed) The selection expressions.
  • $alias (string) The column alias used in the constructed query.
Returns:

$this This QueryBuilder instance.

Since:

8.2.1

public OCP\DB\QueryBuilder\IQueryBuilder::selectDistinct($select)
Specifies an item that is to be returned uniquely in the query result.
<code>
$qb = $conn->getQueryBuilder()
->selectDistinct(‘type’)
->from(‘users’);
</code>
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#376

Parameters:
  • $select (mixed) The selection expressions.
Returns:

$this This QueryBuilder instance.

Since:

9.0.0

public OCP\DB\QueryBuilder\IQueryBuilder::addSelect(...$select)
Adds an item that is to be returned in the query result.
<code>
$qb = $conn->getQueryBuilder()
->select(‘u.id’)
->addSelect(‘p.id’)
->from(‘users’, ‘u’)
->leftJoin(‘u’, ‘phonenumbers’, ‘u.id = p.user_id’);
</code>
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#396

Parameters:
  • $select (mixed) The selection expression.
Returns:

$this This QueryBuilder instance.

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::delete($delete=null, $alias=null)
Turns the query being built into a bulk delete query that ranges over
a certain table.
<code>
$qb = $conn->getQueryBuilder()
->delete(‘users’, ‘u’)
->where(‘u.id = :user_id’);
->setParameter(‘:user_id’, 1);
</code>
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#417

Parameters:
  • $delete (string) The table whose rows are subject to the deletion.
  • $alias (string) The table alias used in the constructed query.
Returns:

$this This QueryBuilder instance.

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::update($update=null, $alias=null)
Turns the query being built into a bulk update query that ranges over
a certain table
<code>
$qb = $conn->getQueryBuilder()
->update(‘users’, ‘u’)
->set(‘u.password’, md5(‘password’))
->where(‘u.id = ?’);
</code>
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#438

Parameters:
  • $update (string) The table whose rows are subject to the update.
  • $alias (string) The table alias used in the constructed query.
Returns:

$this This QueryBuilder instance.

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::insert($insert=null)
Turns the query being built into an insert query that inserts into
a certain table
<code>
$qb = $conn->getQueryBuilder()
->insert(‘users’)
->values(
array(
‘name’ => ‘?’,
‘password’ => ‘?’
)
);
</code>
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#462

Parameters:
  • $insert (string) The table into which the rows should be inserted.
Returns:

$this This QueryBuilder instance.

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::from($from, $alias=null)
Creates and adds a query root corresponding to the table identified by the
given alias, forming a cartesian product with any existing query roots.
<code>
$qb = $conn->getQueryBuilder()
->select(‘u.id’)
->from(‘users’, ‘u’)
</code>
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#482

Parameters:
  • $from (string) The table.
  • $alias (string | null) The alias of the table.
Returns:

$this This QueryBuilder instance.

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::join($fromAlias, $join, $alias, $condition=null)
Creates and adds a join to the query.
<code>
$qb = $conn->getQueryBuilder()
->select(‘u.name’)
->from(‘users’, ‘u’)
->join(‘u’, ‘phonenumbers’, ‘p’, ‘p.is_primary = 1’);
</code>
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#507

Parameters:
  • $fromAlias (string) The alias that points to a from clause.
  • $join (string) The table name to join.
  • $alias (string) The alias of the join table.
  • $condition (string | \OCP\DB\QueryBuilder\ICompositeExpression | null) The condition for the join.
Returns:

$this This QueryBuilder instance.

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::innerJoin($fromAlias, $join, $alias, $condition=null)
Creates and adds a join to the query.
<code>
$qb = $conn->getQueryBuilder()
->select(‘u.name’)
->from(‘users’, ‘u’)
->innerJoin(‘u’, ‘phonenumbers’, ‘p’, ‘p.is_primary = 1’);
</code>
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#532

Parameters:
  • $fromAlias (string) The alias that points to a from clause.
  • $join (string) The table name to join.
  • $alias (string) The alias of the join table.
  • $condition (string | \OCP\DB\QueryBuilder\ICompositeExpression | null) The condition for the join.
Returns:

$this This QueryBuilder instance.

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::leftJoin($fromAlias, $join, $alias, $condition=null)
Creates and adds a left join to the query.
<code>
$qb = $conn->getQueryBuilder()
->select(‘u.name’)
->from(‘users’, ‘u’)
->leftJoin(‘u’, ‘phonenumbers’, ‘p’, ‘p.is_primary = 1’);
</code>
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#557

Parameters:
  • $fromAlias (string) The alias that points to a from clause.
  • $join (string) The table name to join.
  • $alias (string) The alias of the join table.
  • $condition (string | \OCP\DB\QueryBuilder\ICompositeExpression | null) The condition for the join.
Returns:

$this This QueryBuilder instance.

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::rightJoin($fromAlias, $join, $alias, $condition=null)
Creates and adds a right join to the query.
<code>
$qb = $conn->getQueryBuilder()
->select(‘u.name’)
->from(‘users’, ‘u’)
->rightJoin(‘u’, ‘phonenumbers’, ‘p’, ‘p.is_primary = 1’);
</code>
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#582

Parameters:
  • $fromAlias (string) The alias that points to a from clause.
  • $join (string) The table name to join.
  • $alias (string) The alias of the join table.
  • $condition (string | \OCP\DB\QueryBuilder\ICompositeExpression | null) The condition for the join.
Returns:

$this This QueryBuilder instance.

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::set($key, $value)
Sets a new value for a column in a bulk update query.
<code>
$qb = $conn->getQueryBuilder()
->update(‘users’, ‘u’)
->set(‘u.password’, md5(‘password’))
->where(‘u.id = ?’);
</code>
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#603

Parameters:
Returns:

$this This QueryBuilder instance.

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::where(...$predicates)
Specifies one or more restrictions to the query result.
Replaces any previously specified restrictions, if any.

<code>
$qb = $conn->getQueryBuilder()
->select(‘u.name’)
->from(‘users’, ‘u’)
->where(‘u.id = ?’);

// You can optionally programatically build and/or expressions
$qb = $conn->getQueryBuilder();

$or = $qb->expr()->orx();
$or->add($qb->expr()->eq(‘u.id’, 1));
$or->add($qb->expr()->eq(‘u.id’, 2));

$qb->update(‘users’, ‘u’)
->set(‘u.password’, md5(‘password’))
->where($or);
</code>
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#634

Parameters:
  • $predicates (mixed) The restriction predicates.
Returns:

$this This QueryBuilder instance.

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::andWhere(...$where)
Adds one or more restrictions to the query results, forming a logical
conjunction with any previously specified restrictions.
<code>
$qb = $conn->getQueryBuilder()
->select(‘u’)
->from(‘users’, ‘u’)
->where(‘u.username LIKE ?’)
->andWhere(‘u.is_active = 1’);
</code>
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#657

Parameters:
  • $where (mixed) The query restrictions.
Returns:

$this This QueryBuilder instance.

See:

\OCP\DB\QueryBuilder\where()

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::orWhere(...$where)
Adds one or more restrictions to the query results, forming a logical
disjunction with any previously specified restrictions.
<code>
$qb = $conn->getQueryBuilder()
->select(‘u.name’)
->from(‘users’, ‘u’)
->where(‘u.id = 1’)
->orWhere(‘u.id = 2’);
</code>
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#680

Parameters:
  • $where (mixed) The WHERE statement.
Returns:

$this This QueryBuilder instance.

See:

\OCP\DB\QueryBuilder\where()

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::groupBy(...$groupBys)
Specifies a grouping over the results of the query.
Replaces any previously specified groupings, if any.

<code>
$qb = $conn->getQueryBuilder()
->select(‘u.name’)
->from(‘users’, ‘u’)
->groupBy(‘u.id’);
</code>
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#700

Parameters:
  • $groupBys (mixed) The grouping expression.
Returns:

$this This QueryBuilder instance.

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::addGroupBy(...$groupBy)
Adds a grouping expression to the query.
<code>
$qb = $conn->getQueryBuilder()
->select(‘u.name’)
->from(‘users’, ‘u’)
->groupBy(‘u.lastLogin’);
->addGroupBy(‘u.createdAt’)
</code>
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#720

Parameters:
  • $groupBy (mixed) The grouping expression.
Returns:

$this This QueryBuilder instance.

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::setValue($column, $value)
Sets a value for a column in an insert query.
<code>
$qb = $conn->getQueryBuilder()
->insert(‘users’)
->values(
array(
‘name’ => ‘?’
)
)
->setValue(‘password’, ‘?’);
</code>
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#745

Parameters:
  • $column (string) The column into which the value should be inserted.
  • $value (OCP\DB\QueryBuilder\IParameter | string) The value that should be inserted into the column.
Returns:

$this This QueryBuilder instance.

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::values($values)
Specifies values for an insert query indexed by column names.
Replaces any previous values, if any.

<code>
$qb = $conn->getQueryBuilder()
->insert(‘users’)
->values(
array(
‘name’ => ‘?’,
‘password’ => ‘?’
)
);
</code>
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#769

Parameters:
  • $values (array) The values to specify for the insert query indexed by column names.
Returns:

$this This QueryBuilder instance.

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::having(...$having)
Specifies a restriction over the groups of the query.
Replaces any previous having restrictions, if any.
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#782

Parameters:
  • $having (mixed) The restriction over the groups.
Returns:

$this This QueryBuilder instance.

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::andHaving(...$having)
Adds a restriction over the groups of the query, forming a logical
conjunction with any existing having restrictions.
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#795

Parameters:
  • $having (mixed) The restriction to append.
Returns:

$this This QueryBuilder instance.

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::orHaving(...$having)
Adds a restriction over the groups of the query, forming a logical
disjunction with any existing having restrictions.
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#808

Parameters:
  • $having (mixed) The restriction to add.
Returns:

$this This QueryBuilder instance.

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::orderBy($sort, $order=null)
Specifies an ordering for the query results.
Replaces any previously specified orderings, if any.
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#823

Parameters:
  • $sort (string) The ordering expression.
  • $order (string) The ordering direction.
Returns:

$this This QueryBuilder instance.

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::addOrderBy($sort, $order=null)
Adds an ordering to the query results.
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#837

Parameters:
  • $sort (string) The ordering expression.
  • $order (string) The ordering direction.
Returns:

$this This QueryBuilder instance.

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::getQueryPart($queryPartName)
Gets a query part by its name.
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#847

Parameters:
  • $queryPartName (string)
Returns:

mixed

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::getQueryParts()
Gets all query parts.
Source:lib/public/DB/QueryBuilder/IQueryBuilder.php#855
Returns:array
Since:8.2.0
public OCP\DB\QueryBuilder\IQueryBuilder::resetQueryParts($queryPartNames=null)
Resets SQL parts.
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#865

Parameters:
  • $queryPartNames (array | null)
Returns:

$this This QueryBuilder instance.

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::resetQueryPart($queryPartName)
Resets a single SQL part.
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#875

Parameters:
  • $queryPartName (string)
Returns:

$this This QueryBuilder instance.

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::createNamedParameter($value, $type=self::PARAM_STR, $placeHolder=null)
Creates a new named parameter and bind the value $value to it.
This method provides a shortcut for PDOStatement::bindValue
when using prepared statements.

The parameter $value specifies the value that you want to bind. If
$placeholder is not provided bindValue() will automatically create a
placeholder for you. An automatic placeholder will be of the name
‘:dcValue1’, ‘:dcValue2’ etc.


Example:
<code>
$value = 2;
$q->eq( ‘id’, $q->bindValue( $value ) );
$stmt = $q->executeQuery(); // executed with ‘id = 2’
</code>
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#909

Parameters:
  • $value (mixed)
  • $type (mixed)
  • $placeHolder (string) The name to bind with. The string must start with a colon ‘:’.
License:

New BSD License

Returns:

\OCP\DB\QueryBuilder\IParameter

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::createPositionalParameter($value, $type=self::PARAM_STR)
Creates a new positional parameter and bind the given value to it.
Attention: If you are using positional parameters with the query builder you have
to be very careful to bind all parameters in the order they appear in the SQL
statement , otherwise they get bound in the wrong order which can lead to serious
bugs in your code.

Example:
<code>
$qb = $conn->getQueryBuilder();
$qb->select(‘u.*’)
->from(‘users’, ‘u’)
->where(‘u.username = ‘ . $qb->createPositionalParameter(‘Foo’, IQueryBuilder::PARAM_STR))
->orWhere(‘u.username = ‘ . $qb->createPositionalParameter(‘Bar’, IQueryBuilder::PARAM_STR))
</code>
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#936

Parameters:
  • $value (mixed)
  • $type (int)
Returns:

\OCP\DB\QueryBuilder\IParameter

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::createParameter($name)
Creates a new parameter
Example:
<code>
$qb = $conn->getQueryBuilder();
$qb->select(‘u.*’)
->from(‘users’, ‘u’)
->where(‘u.username = ‘ . $qb->createParameter(‘name’))
->setParameter(‘name’, ‘Bar’, IQueryBuilder::PARAM_STR))
</code>
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#957

Parameters:
  • $name (string)
Returns:

\OCP\DB\QueryBuilder\IParameter

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::createFunction($call)
Creates a new function
Attention: Column names inside the call have to be quoted before hand

Example:
<code>
$qb = $conn->getQueryBuilder();
$qb->select($qb->createFunction(‘COUNT(*)’))
->from(‘users’, ‘u’)
echo $qb->getSQL(); // SELECT COUNT(*) FROM `users` u
</code>
<code>
$qb = $conn->getQueryBuilder();
$qb->select($qb->createFunction(‘COUNT(`column`)’))
->from(‘users’, ‘u’)
echo $qb->getSQL(); // SELECT COUNT(`column`) FROM `users` u
</code>
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#985

Parameters:
  • $call (string)
Returns:

\OCP\DB\QueryBuilder\IQueryFunction

Since:

8.2.0

public OCP\DB\QueryBuilder\IQueryBuilder::getLastInsertId()
Used to get the id of the last inserted element
Source:lib/public/DB/QueryBuilder/IQueryBuilder.php#993
Returns:int
Throws:\BadMethodCallException When being called before an insert query has been run.
Since:9.0.0
public OCP\DB\QueryBuilder\IQueryBuilder::getTableName($table)
Returns the table name quoted and with database prefix as needed by the implementation
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#1002

Parameters:
  • $table (string)
Returns:

string

Since:

9.0.0

public OCP\DB\QueryBuilder\IQueryBuilder::getColumnName($column, $tableAlias="")
Returns the column name quoted and with table alias prefix as needed by the implementation
Source:

lib/public/DB/QueryBuilder/IQueryBuilder.php#1012

Parameters:
  • $column (string)
  • $tableAlias (string)
Returns:

string

Since:

9.0.0