| 1 |
lars |
1 |
<com:TContent ID="body">
|
|
|
2 |
|
|
|
3 |
<h1>Mapped Statements</h1>
|
|
|
4 |
<p>Mapped Statements can hold any SQL statement and can use Parameter Maps and
|
|
|
5 |
Result Maps for input and output. (A stored procedure is a specialized form of
|
|
|
6 |
a statement. </p>
|
|
|
7 |
|
|
|
8 |
<p>If the case is simple, the Mapped Statement can reference the parameter and
|
|
|
9 |
result classes directly. Mapped Statements support caching through reference
|
|
|
10 |
to a Cache Model element. The following example shows the syntax for a
|
|
|
11 |
statement element.</p>
|
|
|
12 |
|
|
|
13 |
<com:TTextHighlighter Language="xml" CssClass="source">
|
|
|
14 |
<statement id="statement.name"
|
|
|
15 |
[parameterMap="parameterMap.name"]
|
|
|
16 |
[parameterClass="class.name"]
|
|
|
17 |
[resultMap="resultMap.name"]
|
|
|
18 |
[resultClass="class.name"]
|
|
|
19 |
[listClass="class.name"]
|
|
|
20 |
[cacheModel="cache.name"]
|
|
|
21 |
>
|
|
|
22 |
select * from Products where Product_Id = [?|#propertyName#]
|
|
|
23 |
order by [$simpleDynamic$]
|
|
|
24 |
</statement>
|
|
|
25 |
</com:TTextHighlighter>
|
|
|
26 |
|
|
|
27 |
<p>The <tt>[bracketed]</tt> parts are optional, and some
|
|
|
28 |
options are mutually exclusive. It is perfectly legal to have a Mapped
|
|
|
29 |
Statement as simple as shown by the following example.</p>
|
|
|
30 |
|
|
|
31 |
<com:TTextHighlighter Language="xml" CssClass="source">
|
|
|
32 |
<statement id="InsertTestProduct" >
|
|
|
33 |
insert into Products (Product_Id, Product_Description) values (1, "Shih Tzu")
|
|
|
34 |
</statement>
|
|
|
35 |
</com:TTextHighlighter>
|
|
|
36 |
|
|
|
37 |
<p>The above example is obviously unlikely, unless you are running a
|
|
|
38 |
test. But it does shows that you can use SQLMap to execute arbitrary SQL
|
|
|
39 |
statements. More likely, you will use the object mapping features with
|
|
|
40 |
<a href="?page=Manual.ParameterMap">Parameter Maps</a> and
|
|
|
41 |
<a href="?page=Manual.ResultMaps">Result Maps</a> since that's where the magic happens.</p>
|
|
|
42 |
|
|
|
43 |
<h2>Statement Types</h2>
|
|
|
44 |
<p>The <tt><statement></tt> element is a general "catch all" element that can be
|
|
|
45 |
used for any type of SQL statement. Generally it is a good idea to use one of
|
|
|
46 |
the more specific statement-type elements. The more specific elements provided
|
|
|
47 |
better error-checking and even more functionality. (For example, the insert
|
|
|
48 |
statement can return a database-generated key.) The following table
|
|
|
49 |
summarizes the statement-type elements and their supported attributes and
|
|
|
50 |
features. </p>
|
|
|
51 |
|
|
|
52 |
<!-- tabular: align=|l|l|l|l|, width=(0.2 0.2 0.2 0.2) -->
|
|
|
53 |
<table class="tabular">
|
|
|
54 |
<tr>
|
|
|
55 |
<th>Statement Element</th>
|
|
|
56 |
<th>Attribute</th>
|
|
|
57 |
<th>Child Elements</th>
|
|
|
58 |
<th>Methods</th>
|
|
|
59 |
</tr>
|
|
|
60 |
<tr>
|
|
|
61 |
<td><tt><statement></tt></td>
|
|
|
62 |
<td>
|
|
|
63 |
<tt>id</tt><br />
|
|
|
64 |
<tt>parameterClass</tt><br />
|
|
|
65 |
<tt>resultClass</tt><br />
|
|
|
66 |
<tt>listClass</tt><br />
|
|
|
67 |
<tt>parameterMap</tt><br />
|
|
|
68 |
<tt>resultMap</tt><br />
|
|
|
69 |
<tt>cacheModel</tt>
|
|
|
70 |
</td>
|
|
|
71 |
<td>None</td>
|
|
|
72 |
<td>
|
|
|
73 |
<tt>Insert</tt><br />
|
|
|
74 |
<tt>Update</tt><br />
|
|
|
75 |
<tt>Delete</tt><br />
|
|
|
76 |
All query methods
|
|
|
77 |
</td>
|
|
|
78 |
</tr>
|
|
|
79 |
|
|
|
80 |
<tr>
|
|
|
81 |
<td><tt><insert></tt></td>
|
|
|
82 |
<td>
|
|
|
83 |
<tt>id</tt><br />
|
|
|
84 |
<tt>parameterClass</tt><br />
|
|
|
85 |
<tt>parameterMap</tt>
|
|
|
86 |
</td>
|
|
|
87 |
<td>
|
|
|
88 |
<tt><selectKey></tt><br />
|
|
|
89 |
<tt><generate></tt>
|
|
|
90 |
</td>
|
|
|
91 |
<td>
|
|
|
92 |
<tt>Insert</tt><br />
|
|
|
93 |
<tt>Update</tt><br />
|
|
|
94 |
<tt>Delete</tt>
|
|
|
95 |
</td>
|
|
|
96 |
</tr>
|
|
|
97 |
|
|
|
98 |
<tr>
|
|
|
99 |
<td><tt><update></tt></td>
|
|
|
100 |
<td>
|
|
|
101 |
<tt>id</tt><br />
|
|
|
102 |
<tt>parameterClass</tt><br />
|
|
|
103 |
<tt>parameterMap</tt><br />
|
|
|
104 |
<tt>extends</tt>
|
|
|
105 |
</td>
|
|
|
106 |
<td><tt><generate></tt></td>
|
|
|
107 |
<td>
|
|
|
108 |
<tt>Insert</tt><br />
|
|
|
109 |
<tt>Update</tt><br />
|
|
|
110 |
<tt>Delete</tt>
|
|
|
111 |
</td>
|
|
|
112 |
</tr>
|
|
|
113 |
|
|
|
114 |
<tr>
|
|
|
115 |
<td><tt><delete></tt></td>
|
|
|
116 |
<td>
|
|
|
117 |
<tt>id</tt><br />
|
|
|
118 |
<tt>parameterClass</tt><br />
|
|
|
119 |
<tt>parameterMap</tt><br />
|
|
|
120 |
<tt>extends</tt>
|
|
|
121 |
</td>
|
|
|
122 |
<td><tt><generate></tt></td>
|
|
|
123 |
<td>
|
|
|
124 |
<tt>Insert</tt><br />
|
|
|
125 |
<tt>Update</tt><br />
|
|
|
126 |
<tt>Delete</tt>
|
|
|
127 |
</td>
|
|
|
128 |
</tr>
|
|
|
129 |
|
|
|
130 |
<tr>
|
|
|
131 |
<td><tt><select></tt></td>
|
|
|
132 |
<td>
|
|
|
133 |
<tt>id</tt><br />
|
|
|
134 |
<tt>parameterClass</tt><br />
|
|
|
135 |
<tt>resultClass</tt><br />
|
|
|
136 |
<tt>listClass</tt><br />
|
|
|
137 |
<tt>parameterMap</tt><br />
|
|
|
138 |
<tt>resultMap</tt><br />
|
|
|
139 |
<tt>cacheModel</tt><br />
|
|
|
140 |
<tt>extends</tt>
|
|
|
141 |
</td>
|
|
|
142 |
<td><tt><generate></tt></td>
|
|
|
143 |
<td>
|
|
|
144 |
All query methods
|
|
|
145 |
</td>
|
|
|
146 |
</tr>
|
|
|
147 |
|
|
|
148 |
<tr>
|
|
|
149 |
<td><tt><procedure></tt></td>
|
|
|
150 |
<td>
|
|
|
151 |
<tt>id</tt><br />
|
|
|
152 |
<tt>parameterClass</tt><br />
|
|
|
153 |
<tt>resultClass</tt><br />
|
|
|
154 |
<tt>listClass</tt><br />
|
|
|
155 |
<tt>parameterMap</tt><br />
|
|
|
156 |
<tt>resultMap</tt><br />
|
|
|
157 |
<tt>cacheModel</tt>
|
|
|
158 |
</td>
|
|
|
159 |
<td>None</td>
|
|
|
160 |
<td>
|
|
|
161 |
<tt>Insert</tt><br />
|
|
|
162 |
<tt>Update</tt><br />
|
|
|
163 |
<tt>Delete</tt><br />
|
|
|
164 |
All query methods
|
|
|
165 |
</td>
|
|
|
166 |
</tr>
|
|
|
167 |
</table>
|
|
|
168 |
|
|
|
169 |
<h2>Stored Procedures</h2>
|
|
|
170 |
|
|
|
171 |
<p>TODO</p>
|
|
|
172 |
|
|
|
173 |
</com:TContent>
|