DQL (Doctrine Query Language) - Functional Expressions - String functions.php 2.76 KB
Newer Older
zYne's avatar
zYne committed
1
<?php ?>
zYne's avatar
zYne committed
2
<ul>
zYne's avatar
zYne committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
<li \>The <i>CONCAT</i> function returns a string that is a concatenation of its arguments. In the example above we 
map the concatenation of users firstname and lastname to a value called name
<br \><br \><?php
renderCode("<?php
\$q = new Doctrine_Query();

\$users = \$q->select('CONCAT(u.firstname, u.lastname) name')->from('User u')->execute();

foreach(\$users as \$user) {
    // here 'name' is not a property of \$user,
    // its a mapped function value
    print \$user->name;
}
?>");
?>

zYne's avatar
zYne committed
19 20 21
<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. 
zYne's avatar
zYne committed
22 23 24 25 26 27 28 29 30 31 32 33 34
The <i>SUBSTRING</i> function returns a string.
<br \><br \><?php
renderCode("<?php
\$q = new Doctrine_Query();

\$users = \$q->select('u.name')->from('User u')->where(\"SUBSTRING(u.name, 0, 1) = 'z'\")->execute();

foreach(\$users as \$user) {
    print \$user->name;
}
?>");
?>
 <br \><br \>
zYne's avatar
zYne committed
35 36 37 38 39

<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.
zYne's avatar
zYne committed
40 41 42 43 44 45 46 47 48 49 50
<br \><br \><?php
renderCode("<?php
\$q = new Doctrine_Query();

\$users = \$q->select('u.name')->from('User u')->where(\"TRIM(u.name) = 'Someone'\")->execute();

foreach(\$users as \$user) {
    print \$user->name;
}
?>");
?>    <br \><br \>
zYne's avatar
zYne committed
51 52
<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 \>
zYne's avatar
zYne committed
53 54 55 56 57 58 59 60 61 62 63 64

<?php
renderCode("<?php
\$q = new Doctrine_Query();

\$users = \$q->select('u.name')->from('User u')->where(\"LOWER(u.name) = 'someone'\")->execute();

foreach(\$users as \$user) {
    print \$user->name;
}
?>");
?>  <br \><br \>
zYne's avatar
zYne committed
65 66 67 68 69 70
<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
zYne's avatar
zYne committed
71 72
returned.

zYne's avatar
zYne committed
73 74 75 76
<br \><br \>
<li \>The <i>LENGTH</i> function returns the length of the string in characters as an integer.

</ul>