QueryBuilder

class OC\DB\QueryBuilder\QueryBuilder
Source:lib/private/DB/QueryBuilder/QueryBuilder.php#58
Implements:OCP\DB\QueryBuilder\IQueryBuilder

Properties

protected static property OC\DB\QueryBuilder\QueryBuilder::$lastInsertedTable
Source:lib/private/DB/QueryBuilder/QueryBuilder.php#79
Type:string

Methods

public OC\DB\QueryBuilder\QueryBuilder::__construct($connection, $systemConfig, $logger)
Initializes a new QueryBuilder.
Source:

lib/private/DB/QueryBuilder/QueryBuilder.php#88

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

lib/private/DB/QueryBuilder/QueryBuilder.php#103

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

owncloud database prefix automatically.

Since:

8.2.0

public OC\DB\QueryBuilder\QueryBuilder::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/private/DB/QueryBuilder/QueryBuilder.php#123
Returns:\OCP\DB\QueryBuilder\IExpressionBuilder
public OC\DB\QueryBuilder\QueryBuilder::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/private/DB/QueryBuilder/QueryBuilder.php#156
Returns:\OCP\DB\QueryBuilder\IFunctionBuilder
public OC\DB\QueryBuilder\QueryBuilder::getType()
Gets the type of the currently built query.
Source:lib/private/DB/QueryBuilder/QueryBuilder.php#175
Returns:int
public OC\DB\QueryBuilder\QueryBuilder::getConnection()
Gets the associated DBAL Connection for this query builder.
Source:lib/private/DB/QueryBuilder/QueryBuilder.php#184
Returns:\OCP\IDBConnection
public OC\DB\QueryBuilder\QueryBuilder::getState()
Gets the state of this query builder instance.
Source:lib/private/DB/QueryBuilder/QueryBuilder.php#193
Returns:int Either QueryBuilder::STATE_DIRTY or QueryBuilder::STATE_CLEAN.
public OC\DB\QueryBuilder\QueryBuilder::execute()
Executes this query using the bound parameters and their types.
Uses {@see \OC\DB\QueryBuilder\Connection::executeQuery} for select statements and {@see \OC\DB\QueryBuilder\Connection::executeUpdate}
for insert, update and delete statements.
Source:lib/private/DB/QueryBuilder/QueryBuilder.php#205
Returns:\OCP\DB\IResult | int
public OC\DB\QueryBuilder\QueryBuilder::executeQuery()
Source:lib/private/DB/QueryBuilder/QueryBuilder.php#294
public OC\DB\QueryBuilder\QueryBuilder::executeUpdate()
Monkey-patched compatibility layer for apps that were adapted for Nextcloud 22 before
the first beta, where executeStatement was named executeUpdate.
Static analysis should catch those misuses, but until then let’s try to keep things
running.
Source:lib/private/DB/QueryBuilder/QueryBuilder.php#323
Deprecated:
public OC\DB\QueryBuilder\QueryBuilder::executeStatement()
Source:lib/private/DB/QueryBuilder/QueryBuilder.php#327
public OC\DB\QueryBuilder\QueryBuilder::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/private/DB/QueryBuilder/QueryBuilder.php#358
Returns:string The SQL query string.
public OC\DB\QueryBuilder\QueryBuilder::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/private/DB/QueryBuilder/QueryBuilder.php#379

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.

public OC\DB\QueryBuilder\QueryBuilder::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/private/DB/QueryBuilder/QueryBuilder.php#404

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

$this This QueryBuilder instance.

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

lib/private/DB/QueryBuilder/QueryBuilder.php#426

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

mixed The value of the bound parameter.

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

lib/private/DB/QueryBuilder/QueryBuilder.php#446

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

mixed The value of the bound parameter type.

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

lib/private/DB/QueryBuilder/QueryBuilder.php#457

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

$this This QueryBuilder instance.

public OC\DB\QueryBuilder\QueryBuilder::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/private/DB/QueryBuilder/QueryBuilder.php#469
Returns:int The position of the first result.
public OC\DB\QueryBuilder\QueryBuilder::setMaxResults($maxResults)
Sets the maximum number of results to retrieve (the “limit”).
NOTE: Setting max results to “0” will cause mixed behaviour. While most
of the databases will just return an empty result set, Oracle will return
all entries.
Source:

lib/private/DB/QueryBuilder/QueryBuilder.php#484

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

$this This QueryBuilder instance.

public OC\DB\QueryBuilder\QueryBuilder::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/private/DB/QueryBuilder/QueryBuilder.php#496
Returns:int | null The maximum number of results.
public OC\DB\QueryBuilder\QueryBuilder::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/private/DB/QueryBuilder/QueryBuilder.php#515

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

'@return $this This QueryBuilder instance.

public OC\DB\QueryBuilder\QueryBuilder::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/private/DB/QueryBuilder/QueryBuilder.php#542

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

$this This QueryBuilder instance.

public OC\DB\QueryBuilder\QueryBuilder::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/private/DB/QueryBuilder/QueryBuilder.php#563

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

$this This QueryBuilder instance.

public OC\DB\QueryBuilder\QueryBuilder::addSelect(...$selects)
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/private/DB/QueryBuilder/QueryBuilder.php#592

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

$this This QueryBuilder instance.

public OC\DB\QueryBuilder\QueryBuilder::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/private/DB/QueryBuilder/QueryBuilder.php#620

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.

public OC\DB\QueryBuilder\QueryBuilder::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/private/DB/QueryBuilder/QueryBuilder.php#645

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.

public OC\DB\QueryBuilder\QueryBuilder::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/private/DB/QueryBuilder/QueryBuilder.php#673

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

$this This QueryBuilder instance.

public OC\DB\QueryBuilder\QueryBuilder::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/private/DB/QueryBuilder/QueryBuilder.php#698

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

$this This QueryBuilder instance.

public OC\DB\QueryBuilder\QueryBuilder::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/private/DB/QueryBuilder/QueryBuilder.php#724

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.

public OC\DB\QueryBuilder\QueryBuilder::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/private/DB/QueryBuilder/QueryBuilder.php#752

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.

public OC\DB\QueryBuilder\QueryBuilder::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/private/DB/QueryBuilder/QueryBuilder.php#780

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.

public OC\DB\QueryBuilder\QueryBuilder::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/private/DB/QueryBuilder/QueryBuilder.php#808

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.

public OC\DB\QueryBuilder\QueryBuilder::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/private/DB/QueryBuilder/QueryBuilder.php#834

Parameters:
Returns:

$this This QueryBuilder instance.

public OC\DB\QueryBuilder\QueryBuilder::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/private/DB/QueryBuilder/QueryBuilder.php#869

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

$this This QueryBuilder instance.

public OC\DB\QueryBuilder\QueryBuilder::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/private/DB/QueryBuilder/QueryBuilder.php#896

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

$this This QueryBuilder instance.

See:

\OC\DB\QueryBuilder\where()

public OC\DB\QueryBuilder\QueryBuilder::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/private/DB/QueryBuilder/QueryBuilder.php#923

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

$this This QueryBuilder instance.

See:

\OC\DB\QueryBuilder\where()

public OC\DB\QueryBuilder\QueryBuilder::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/private/DB/QueryBuilder/QueryBuilder.php#947

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

$this This QueryBuilder instance.

public OC\DB\QueryBuilder\QueryBuilder::addGroupBy(...$groupBys)
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/private/DB/QueryBuilder/QueryBuilder.php#975
Parameters:
Returns:$this This QueryBuilder instance.
public OC\DB\QueryBuilder\QueryBuilder::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/private/DB/QueryBuilder/QueryBuilder.php#1007

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.

public OC\DB\QueryBuilder\QueryBuilder::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/private/DB/QueryBuilder/QueryBuilder.php#1035

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

$this This QueryBuilder instance.

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

lib/private/DB/QueryBuilder/QueryBuilder.php#1054

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

$this This QueryBuilder instance.

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

lib/private/DB/QueryBuilder/QueryBuilder.php#1071

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

$this This QueryBuilder instance.

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

lib/private/DB/QueryBuilder/QueryBuilder.php#1088

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

$this This QueryBuilder instance.

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

lib/private/DB/QueryBuilder/QueryBuilder.php#1106

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

$this This QueryBuilder instance.

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

lib/private/DB/QueryBuilder/QueryBuilder.php#1123

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

$this This QueryBuilder instance.

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

lib/private/DB/QueryBuilder/QueryBuilder.php#1139

Parameters:
  • $queryPartName (string)
Returns:

mixed

public OC\DB\QueryBuilder\QueryBuilder::getQueryParts()
Gets all query parts.
Source:lib/private/DB/QueryBuilder/QueryBuilder.php#1148
Returns:array
public OC\DB\QueryBuilder\QueryBuilder::resetQueryParts($queryPartNames=null)
Resets SQL parts.
Source:

lib/private/DB/QueryBuilder/QueryBuilder.php#1159

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

$this This QueryBuilder instance.

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

lib/private/DB/QueryBuilder/QueryBuilder.php#1172

Parameters:
  • $queryPartName (string)
Returns:

$this This QueryBuilder instance.

public OC\DB\QueryBuilder\QueryBuilder::createNamedParameter($value, $type=\OCP\DB\QueryBuilder\IQueryBuilder::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/private/DB/QueryBuilder/QueryBuilder.php#1207

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 the placeholder name used.

public OC\DB\QueryBuilder\QueryBuilder::createPositionalParameter($value, $type=\OCP\DB\QueryBuilder\IQueryBuilder::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/private/DB/QueryBuilder/QueryBuilder.php#1233

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

\OCP\DB\QueryBuilder\IParameter

public OC\DB\QueryBuilder\QueryBuilder::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/private/DB/QueryBuilder/QueryBuilder.php#1253

Parameters:
  • $name (string)
Returns:

\OCP\DB\QueryBuilder\IParameter

public OC\DB\QueryBuilder\QueryBuilder::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/private/DB/QueryBuilder/QueryBuilder.php#1280

Parameters:
  • $call (string)
Returns:

\OCP\DB\QueryBuilder\IQueryFunction

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

lib/private/DB/QueryBuilder/QueryBuilder.php#1305

Parameters:
  • $table (string)
Returns:

string

protected OC\DB\QueryBuilder\QueryBuilder::prefixTableName($table)
Returns the table name with database prefix as needed by the implementation
Source:

lib/private/DB/QueryBuilder/QueryBuilder.php#1320

Parameters:
  • $table (string)
Returns:

string

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

lib/private/DB/QueryBuilder/QueryBuilder.php#1335

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

string

public OC\DB\QueryBuilder\QueryBuilder::quoteAlias($alias)
Returns the column name quoted and with table alias prefix as needed by the implementation
Source:

lib/private/DB/QueryBuilder/QueryBuilder.php#1349

Parameters:
  • $alias (string)
Returns:

string