1
0
mirror of synced 2025-02-01 04:51:45 +03:00

New DQL docs

This commit is contained in:
zYne 2006-10-20 19:26:39 +00:00
parent 599dc759fb
commit 96bf070900
13 changed files with 249 additions and 0 deletions

View File

@ -0,0 +1,24 @@
Syntax:<br \>
string_expression [NOT] LIKE pattern_value [ESCAPE escape_character]
<br \>
<br \>
The string_expression must have a string value. The pattern_value is a string literal or a string-valued
input parameter in which an underscore (_) stands for any single character, a percent (%) character
stands for any sequence of characters (including the empty sequence), and all other characters stand for
themselves. The optional escape_character is a single-character string literal or a character-valued
input parameter (i.e., char or Character) and is used to escape the special meaning of the underscore
and percent characters in pattern_value.
<br \><br \>
Examples:
<br \>
<ul>
<li \>address.phone LIKE 12%3 is true for '123' '12993' and false for '1234'
<li \>asentence.word LIKE l_se is true for lose and false for 'loose'
<li \>aword.underscored LIKE \_% ESCAPE '\' is true for '_foo' and false for 'bar'
<li \>address.phone NOT LIKE 12%3 is false for '123' and '12993' and true for '1234'
</ul>
<br \>
If the value of the string_expression or pattern_value is NULL or unknown, the value of the LIKE
expression is unknown. If the escape_characteris specified and is NULL, the value of the LIKE expression
is unknown.

View File

@ -0,0 +1,14 @@
The operators are listed below in order of decreasing precedence.
<ul>
<li \> Navigation operator (.)
<li \> Arithmetic operators: <br \>
+, - unary <br \>
*, / multiplication and division <br \>
+, - addition and subtraction <br \>
<li \> Comparison operators : =, >, >=, <, <=, <> (not equal), [NOT] LIKE, <br \>
[NOT] IN, IS [NOT] NULL, IS [NOT] EMPTY <br \>
<li \> Logical operators:<br \>
NOT <br \>
AND <br \>
OR <br \>
</ul>

View File

@ -0,0 +1,31 @@
Syntax: <br \>
<div class='sql'>
<pre>
FROM <i>component_reference</i> [[LEFT | INNER] JOIN <i>component_reference</i>] ...
</pre>
</div>
The FROM clause indicates the component or components from which to retrieve records.
If you name more than one component, you are performing a join.
For each table specified, you can optionally specify an alias.
<br \><br \>
<li \> The default join type is <i>LEFT JOIN</i>. This join can be indicated by the use of either 'LEFT JOIN' clause or simply ',', hence the following queries are equal:
<div class='sql'>
<pre>
SELECT u.*, p.* FROM User u LEFT JOIN u.Phonenumber
SELECT u.*, p.* FROM User u, u.Phonenumber p
</pre>
</div>
<li \><i>INNER JOIN</i> produces a Cartesian product between two specified components (that is, each and every record in the first component is joined to each and every record in the second component).
So basically <i>INNER JOIN</i> can be used when you want to efficiently fetch for example all users which have one or more phonenumbers.
<div class='sql'>
<pre>
SELECT u.*, p.* FROM User u INNER JOIN u.Phonenumber p
</pre>
</div>

View File

@ -0,0 +1,26 @@
<ul>
<li \>The <i>CONCAT</i> function returns a string that is a concatenation of its arguments.
<br \><br \>
<li \>The second and third arguments of the <i>SUBSTRING</i> function denote the starting position and length of
the substring to be returned. These arguments are integers. The first position of a string is denoted by 1.
The <i>SUBSTRING</i> function returns a string.
<br \><br \>
<li \>The <i>TRIM</i> function trims the specified character from a string. If the character to be trimmed is not
specified, it is assumed to be space (or blank). The optional trim_character is a single-character string
literal or a character-valued input parameter (i.e., char or Character)[30]. If a trim specification is
not provided, BOTH is assumed. The <i>TRIM</i> function returns the trimmed string.
<br \><br \>
<li \>The <i>LOWER</i> and <i>UPPER</i> functions convert a string to lower and upper case, respectively. They return a
string. <br \><br \>
<li \>
The <i>LOCATE</i> function returns the position of a given string within a string, starting the search at a specified
position. It returns the first position at which the string was found as an integer. The first argument
is the string to be located; the second argument is the string to be searched; the optional third argument
is an integer that represents the string position at which the search is started (by default, the beginning of
the string to be searched). The first position in a string is denoted by 1. If the string is not found, 0 is
returned.[31]
<br \><br \>
<li \>The <i>LENGTH</i> function returns the length of the string in characters as an integer.
</ul>

View File

@ -0,0 +1,40 @@
<ul>
<li> GROUP BY and HAVING clauses can be used for dealing with aggregate functions
<br \>
<li> Following aggregate functions are availible on DQL: COUNT, MAX, MIN, AVG, SUM
<br \>
Selecting alphabetically first user by name.
<div class='sql'>
<pre>
SELECT MIN(u.name) FROM User u
</pre>
</div>
Selecting the sum of all Account amounts.
<div class='sql'>
<pre>
SELECT SUM(a.amount) FROM Account a
</pre>
</div>
<br \>
<li> Using an aggregate function in a statement containing no GROUP BY clause, results in grouping on all rows. In the example above
we fetch all users and the number of phonenumbers they have.
<div class='sql'>
<pre>
SELECT u.*, COUNT(p.id) FROM User u, u.Phonenumber p GROUP BY u.id
</pre>
</div>
<br \>
<li> The HAVING clause can be used for narrowing the results using aggregate values. In the following example we fetch
all users which have atleast 2 phonenumbers
<div class='sql'>
<pre>
SELECT u.* FROM User u, u.Phonenumber p HAVING COUNT(p.id) >= 2
</pre>
</div>
</ul>

View File

@ -0,0 +1,29 @@
Record collections can be sorted efficiently at the database level using the ORDER BY clause.
Syntax:
<div class='sql'>
<pre>
[ORDER BY {ComponentAlias.columnName}
[ASC | DESC], ...]
</pre>
</div>
Examples:
<br \>
<div class='sql'>
<pre>
FROM User.Phonenumber
ORDER BY User.name, Phonenumber.phonenumber
FROM User u, u.Email e
ORDER BY e.address, u.id
</pre>
</div>
In order to sort in reverse order you can add the DESC (descending) keyword to the name of the column in the ORDER BY clause that you are sorting by. The default is ascending order; this can be specified explicitly using the ASC keyword.
<br \>
<div class='sql'>
<pre>
FROM User u, u.Email e
ORDER BY e.address DESC, u.id ASC;
</pre>
</div>

View File

@ -0,0 +1,69 @@
SELECT statement syntax:
<div class='sql'>
<pre>
SELECT
[ALL | DISTINCT]
<i>select_expr</i>, ...
[FROM <i>components</i>
[WHERE <i>where_condition</i>]
[GROUP BY <i>groupby_expr</i>
[ASC | DESC], ... ]
[HAVING <i>where_condition</i>]
[ORDER BY <i>orderby_expr</i>
[ASC | DESC], ...]
[LIMIT <i>row_count</i> OFFSET <i>offset</i>}]
</pre>
</div>
<br \>
The SELECT statement is used for the retrieval of data from one or more components.
<ul>
<li \>Each <i>select_expr</i> indicates a column or an aggregate function value that you want to retrieve. There must be at least one <i>select_expr</i> in every SELECT statement.
<div class='sql'>
<pre>
SELECT a.name, a.amount FROM Account a
</pre>
</div>
<li \>An asterisk can be used for selecting all columns from given component. Even when using an asterisk the executed sql queries never actually use it
(Doctrine converts asterisk to appropriate column names, hence leading to better performance on some databases).
<div class='sql'>
<pre>
SELECT a.* FROM Account a
</pre>
</div>
<li \>FROM clause <i>components</i> indicates the component or components from which to retrieve records.
<div class='sql'>
<pre>
SELECT a.* FROM Account a
SELECT u.*, p.*, g.* FROM User u LEFT JOIN u.Phonenumber p LEFT JOIN u.Group g
</pre>
</div>
<li \>The WHERE clause, if given, indicates the condition or conditions that the records must satisfy to be selected. <i>where_condition</i> is an expression that evaluates to true for each row to be selected. The statement selects all rows if there is no WHERE clause.
<div class='sql'>
<pre>
SELECT a.* FROM Account a WHERE a.amount > 2000
</pre>
</div>
<li \>In the WHERE clause, you can use any of the functions and operators that DQL supports, except for aggregate (summary) functions
<li \>The HAVING clause can be used for narrowing the results with aggregate functions
<div class='sql'>
<pre>
SELECT u.* FROM User u LEFT JOIN u.Phonenumber p HAVING COUNT(p.id) > 3
</pre>
</div>
<li \>The ORDER BY clause can be used for sorting the results
<div class='sql'>
<pre>
SELECT u.* FROM User u ORDER BY u.name
</pre>
</div>
<li \>The LIMIT and OFFSET clauses can be used for efficiently limiting the number of records to a given <i>row_count</i>
<div class='sql'>
<pre>
SELECT u.* FROM User u LIMIT 20
</pre>
</div>
</ul>

View File

@ -0,0 +1,16 @@
Syntax:
<div class='sql'>
<pre>
WHERE <i>where_condition</i>
</pre>
</div>
<ul>
<li \> The WHERE clause, if given, indicates the condition or conditions that the records must satisfy to be selected.
<br \><br \>
<li \> <i>where_condition</i> is an expression that evaluates to true for each row to be selected.
<br \><br \>
<li \> The statement selects all rows if there is no WHERE clause.
<br \><br \>
<li \> When narrowing results with aggregate function values HAVING clause should be used instead of WHERE clause
<br \><br \>
</ul>