Commit a300634b authored by zYne's avatar zYne

DQL UPDATE / DELETE statement docs added

parent 8b87b3ea
<?php
$q = 'DELETE FROM Account WHERE id > ?';
$rows = $this->conn->query($q, array(3));
// the same query using the query interface
$q = new Doctrine_Query();
$rows = $q->update('Account')
->where('id > ?')
->execute(array(3));
print $rows; // the number of affected rows
?>
<?php
$q = 'UPDATE Account SET amount = amount + 200 WHERE id > 200';
$rows = $this->conn->query($q);
// the same query using the query interface
$q = new Doctrine_Query();
$rows = $q->update('Account')
->set('amount', 'amount + 200')
->where('id > 200')
->execute();
print $rows; // the number of affected rows
?>
<div class='sql'>
<pre>
DELETE FROM <i>component_name</i>
[WHERE <i>where_condition</i>]
[ORDER BY ...]
[LIMIT <i>record_count</i>]
</pre>
</div>
<ul>
<li \>The DELETE statement deletes records from <i>component_name</i> and returns the number of records deleted.
<li \>The optional WHERE clause specifies the conditions that identify which records to delete.
Without WHERE clause, all records are deleted.
<li \>If the ORDER BY clause is specified, the records are deleted in the order that is specified.
<li \>The LIMIT clause places a limit on the number of rows that can be deleted.
The statement will stop as soon as it has deleted <i>record_count</i> records.
</ul>
......@@ -9,39 +9,15 @@ When compared to using raw SQL, DQL has several benefits: <br \>
<li \>DQL understands relations so you don't have to type manually sql joins and join conditions
</ul>
<ul>
<li \>DQL is portable on different databases
</ul>
<ul>
<li \>DQL has some very complex built-in algorithms like (the record limit algorithm) which can help
developer to efficiently retrieve objects
</ul>
<ul>
<li \>It supports some many functions that help dealing with one-to-many, many-to-many relational data with conditional fetching.
<li \>It supports some functions that can save time when dealing with one-to-many, many-to-many relational data with conditional fetching.
</ul>
If the power of DQL isn't enough, you should consider using the rawSql API for object population.
Standard DQL query consists of the following parts:
<ul>
<li \> a FROM clause, which provides declarations that designate the domain to which the expressions
specified in the other clauses of the query apply.
</ul>
<ul>
<li \> an optional WHERE clause, which may be used to restrict the results that are returned by the
query.
</ul>
<ul>
<li \> an optional GROUP BY clause, which allows query results to be aggregated in terms of
groups.
</ul>
<ul>
<li \> an optional HAVING clause, which allows filtering over aggregated groups.
</ul>
<ul>
<li \> an optional ORDER BY clause, which may be used to order the results that are returned by the
query.
</ul>
<br \>
In BNF syntax, a select statement is defined as:
select_statement :: = select_clause from_clause [where_clause] [groupby_clause]
[having_clause] [orderby_clause]
<br \>
A select statement must always have a SELECT and a FROM clause. The square brackets [] indicate
that the other clauses are optional.
UPDATE statement syntax:
<div class='sql'>
<pre>
UPDATE <i>component_name</i>
SET <i>col_name1</i>=<i>expr1</i> [, <i>col_name2</i>=<i>expr2</i> ...]
[WHERE <i>where_condition</i>]
[ORDER BY ...]
[LIMIT <i>record_count</i>]
</pre>
</div>
<ul>
<li \>The UPDATE statement updates columns of existing records in <i>component_name</i> with new values and returns the number of affected records.
<li \>The SET clause indicates which columns to modify and the values they should be given.
<li \>The optional WHERE clause specifies the conditions that identify which records to update.
Without WHERE clause, all records are updated.
<li \>The optional ORDER BY clause specifies the order in which the records are being updated.
<li \>The LIMIT clause places a limit on the number of records that can be updated. You can use LIMIT row_count to restrict the scope of the UPDATE.
A LIMIT clause is a <b>rows-matched restriction</b> not a rows-changed restriction.
The statement stops as soon as it has found <i>record_count</i> rows that satisfy the WHERE clause, whether or not they actually were changed.
</ul>
......@@ -304,9 +304,14 @@ $menu = array("Getting started" =>
"OffsetIterator")
*/
),
"DQL (Doctrine Query Language)" =>
array('Introduction',
array(
'Introduction',
'SELECT queries',
'UPDATE queries',
'DELETE queries',
'FROM clause',
'WHERE clause',
'Conditional expressions' =>
......@@ -323,7 +328,7 @@ $menu = array("Getting started" =>
'Empty Collection Comparison Expressions',
'Collection Member Expressions',
'Exists Expressions',
'All or Any Expressions',
'All and Any Expressions',
'Subqueries'),
'Functional Expressions' =>
array('String functions',
......@@ -336,16 +341,6 @@ $menu = array("Getting started" =>
'LIMIT and OFFSET clauses',
'Examples',
'BNF'),
/**
'Functions' => array(
'Contains',
'Regexp',
'Like'),
'Operators' => array(
'Logical operators')
*/
"Transactions" => array(
"Introduction",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment