~ubuntu-branches/ubuntu/precise/libtangram-perl/precise

« back to all changes in this revision

Viewing changes to Tangram/Expr.pod

  • Committer: Bazaar Package Importer
  • Author(s): Stephen Zander
  • Date: 2001-09-21 10:20:34 UTC
  • Revision ID: james.westby@ubuntu.com-20010921102034-tohkprbnz4n1aua0
Tags: upstream-2.04
ImportĀ upstreamĀ versionĀ 2.04

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
=head1 NAME
 
2
 
 
3
Tangram::Expr - manipulate expressions on database server side
 
4
 
 
5
=head1 SYNOPSIS
 
6
   
 
7
   my ($r1, $r2) = $storage->remote(qw( ... ));
 
8
 
 
9
   $r1->{field} operator $value
 
10
      $r1->{field} operator $r2->{field2}
 
11
   
 
12
      $r1->{collection}->includes( $obj )
 
13
      $r1->{collection}->exists( $obj, $filter )
 
14
 
 
15
=head1 DESCRIPTION
 
16
 
 
17
Tangram::Expr objects represent expressions that will be evaluated on
 
18
the database server side.
 
19
 
 
20
Expression objects fall into one of the following categories: numeric,
 
21
string, reference or collection.
 
22
 
 
23
The methods in Expr are needed only by people extending Tangram. See
 
24
L<Tangram::Dialect>.
 
25
 
 
26
=head1 NUMERIC EXPRESSIONS
 
27
 
 
28
Numeric expression objects can be compared using the operators ==, !=,
 
29
<, >, <= and >=.  The other operand must be either another numeric
 
30
expression object, or a normal Perl numeric value.  The result of the
 
31
comparison is a Filter.
 
32
 
 
33
=head1 STRING EXPRESSIONS
 
34
 
 
35
String expression objects can be compared using the operators eq, ne,
 
36
lt, gt, le, and ge.  The other operand must be either a string
 
37
expression object or any Perl scalar value. Tangram will automatically
 
38
quote the operand as required by the SQL syntax.  The result of the
 
39
comparison is a Tangram::Filter.
 
40
 
 
41
String expression objects also support the method like($str), where
 
42
$str is a string that may contain SQL wildcards. The result is a
 
43
Tangram::Filter that translates to a SQL C<LIKE $str> predicate.
 
44
 
 
45
=head1 REFERENCE EXPRESSIONS
 
46
 
 
47
Reference expression objects can be compared for equality using
 
48
operators == and !=. The other operand must be another reference
 
49
expression, a persistent object or undef(). The result of the
 
50
comparison is a Filter.
 
51
 
 
52
=head1 COLLECTION EXPRESSIONS
 
53
 
 
54
Collection expression objects represents a collection inside an
 
55
object. It supports the includes() and exists() methods, which returns
 
56
a Tangram::Filter stating that the collection must contain the
 
57
operand. exists() uses a subselect.
 
58
 
 
59
The operand may be a Tangram::Remote, a persistent object,
 
60
or an object ID.
 
61
 
 
62
operator < is provided as a synonym for includes().
 
63
 
 
64
=head1 PREDICATES
 
65
 
 
66
Predicate objects represent logical expressions, or
 
67
conditions. Predicates support logical operators &, | and !. Note that
 
68
a I<single> ampersand or vertical bar must be used.  The result is
 
69
another predicate.
 
70
 
 
71
=head1 CLASS METHODS
 
72
 
 
73
=head2 new($type, $expr, @remotes)
 
74
 
 
75
Returns a new instance.
 
76
 
 
77
$type is a Type object corresponding to this expression (see
 
78
L<Tangram::Type>).
 
79
 
 
80
$expr is a SQL expression. It will eventually become part of a
 
81
WHERE-CLAUSE.
 
82
 
 
83
@remotes contains the Remote objects (see L<Tangram::Remote>) that
 
84
participate in the expression. Tangram uses this list to insert the
 
85
corresponding tables in the FROM clause and conditions in the
 
86
WHERE-CLAUSE.
 
87
 
 
88
=head1 INSTANCE METHODS
 
89
 
 
90
=head2 expr()
 
91
 
 
92
Returns the SQL equivalent for this expression.
 
93
 
 
94
=head2 type()
 
95
 
 
96
Returns the Type (see L<Tangram::Type>) corresponding  to this
 
97
expression.
 
98
 
 
99
=head2 objects()
 
100
 
 
101
Returns the list of the objects that participate in this
 
102
expression. 
 
103
 
 
104
=head2 storage()
 
105
 
 
106
Returns the Storage associated with this expression.
 
107
 
 
108
=head1 EXAMPLES
 
109
 
 
110
$person is called 'Homer'
 
111
 
 
112
      $person->{name} eq 'Homer'
 
113
 
 
114
$person's name ends with 'mer'
 
115
 
 
116
      $person->{name}->like('%mer');
 
117
 
 
118
$person is older than 35
 
119
 
 
120
      $person->{age} > 35
 
121
 
 
122
$person is married to $homer
 
123
 
 
124
      $person->{partner} == $homer
 
125
 
 
126
$person is not $homer
 
127
 
 
128
      $person != $homer
 
129
 
 
130
$person is not $homer and is older than 65
 
131
 
 
132
      $person != $homer & $person->{age} > 65
 
133
 
 
134
$person is $bart's parent
 
135
 
 
136
      $person->{children}->includes( $bart )
 
137
      $person->{children} < $bart
 
138
 
 
139
$person is not $bart's parent
 
140
 
 
141
      !$person->{children}->includes( $bart )
 
142
      !($person->{children} < $bart)
 
143
 
 
144
=head1 SEE ALSO
 
145
 
 
146
L<Tangram::Remote>, L<Tangram::Expr>, L<Tangram::Storage>
 
 
b'\\ No newline at end of file'