1
0
mirror of synced 2024-12-13 14:56:01 +03:00

DQL UPDATE / DELETE statement docs added

This commit is contained in:
zYne 2006-10-19 11:48:03 +00:00
parent 8b87b3eacd
commit a300634b2a
6 changed files with 86 additions and 40 deletions

View File

@ -0,0 +1,15 @@
<?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
?>

View File

@ -0,0 +1,16 @@
<?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
?>

View File

@ -0,0 +1,20 @@
<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>

View File

@ -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 <li \>DQL understands relations so you don't have to type manually sql joins and join conditions
</ul> </ul>
<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 <li \>DQL has some very complex built-in algorithms like (the record limit algorithm) which can help
developer to efficiently retrieve objects developer to efficiently retrieve objects
</ul> </ul>
<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> </ul>
If the power of DQL isn't enough, you should consider using the rawSql API for object population. 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.

View File

@ -0,0 +1,24 @@
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>

View File

@ -304,9 +304,14 @@ $menu = array("Getting started" =>
"OffsetIterator") "OffsetIterator")
*/ */
), ),
"DQL (Doctrine Query Language)" => "DQL (Doctrine Query Language)" =>
array('Introduction', array(
'Introduction',
'SELECT queries',
'UPDATE queries',
'DELETE queries',
'FROM clause', 'FROM clause',
'WHERE clause', 'WHERE clause',
'Conditional expressions' => 'Conditional expressions' =>
@ -323,7 +328,7 @@ $menu = array("Getting started" =>
'Empty Collection Comparison Expressions', 'Empty Collection Comparison Expressions',
'Collection Member Expressions', 'Collection Member Expressions',
'Exists Expressions', 'Exists Expressions',
'All or Any Expressions', 'All and Any Expressions',
'Subqueries'), 'Subqueries'),
'Functional Expressions' => 'Functional Expressions' =>
array('String functions', array('String functions',
@ -336,16 +341,6 @@ $menu = array("Getting started" =>
'LIMIT and OFFSET clauses', 'LIMIT and OFFSET clauses',
'Examples', 'Examples',
'BNF'), 'BNF'),
/**
'Functions' => array(
'Contains',
'Regexp',
'Like'),
'Operators' => array(
'Logical operators')
*/
"Transactions" => array( "Transactions" => array(
"Introduction", "Introduction",