summaryrefslogtreecommitdiff
path: root/demos/sqlmap/protected/pages/Manual/MappedStatements.page
blob: c4dfa3d9cc406a5a6db35b7bda94a6ad5c2da03e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<com:TContent ID="body">

<h1>Mapped Statements</h1>
<p>Mapped Statements can hold any SQL statement and can use Parameter Maps and
Result Maps for input and output. (A stored procedure is a specialized form of
a statement. </p>

<p>If the case is simple, the Mapped Statement can reference the parameter and
result classes directly. Mapped Statements support caching through reference
to a Cache Model element. The following example shows the syntax for a
statement element.</p>

<com:TTextHighlighter Language="xml" CssClass="source">
<statement id="statement.name"
  [parameterMap="parameterMap.name"]
  [parameterClass="class.name"]
  [resultMap="resultMap.name"]
  [resultClass="class.name"]
  [listClass="class.name"]
  [cacheModel="cache.name"]
>
  select * from Products where Product_Id = [?|#propertyName#]
  order by [$simpleDynamic$]
</statement>
</com:TTextHighlighter>

<p>The <tt>[bracketed]</tt> parts are optional, and some
options are mutually exclusive. It is perfectly legal to have a Mapped
Statement as simple as shown by the following example.</p>

<com:TTextHighlighter Language="xml" CssClass="source">
<statement id="InsertTestProduct" >
  insert into Products (Product_Id, Product_Description) values (1, "Shih Tzu")
</statement>
</com:TTextHighlighter>

<p>The above example is obviously unlikely, unless you are running a
test. But it does shows that you can use SQLMap to execute arbitrary SQL
statements. More likely, you will use the object mapping features with
<a href="?page=Manual.ParameterMap">Parameter Maps</a> and 
<a href="?page=Manual.ResultMaps">Result Maps</a> since that's where the magic happens.</p>

<h2>Statement Types</h2>
<p>The <tt>&lt;statement&gt;</tt> element is a general "catch all" element that can be
used for any type of SQL statement. Generally it is a good idea to use one of
the more specific statement-type elements. The more specific elements provided
better error-checking and even more functionality. (For example, the insert
statement can return a database-generated key.) The following table
summarizes the statement-type elements and their supported attributes and
features. </p>

<!-- tabular: align=|l|l|l|l|, width=(0.2 0.2 0.2 0.2) --> 
<table class="tabular">
	<tr>
		<th>Statement Element</th>
		<th>Attribute</th>
		<th>Child Elements</th>
		<th>Methods</th>
	</tr>
	<tr>
		<td><tt>&lt;statement&gt;</tt></td>
		<td>
			<tt>id</tt><br />
			<tt>parameterClass</tt><br />
			<tt>resultClass</tt><br />
			<tt>listClass</tt><br />
			<tt>parameterMap</tt><br />
			<tt>resultMap</tt><br />
			<tt>cacheModel</tt>
		</td>
		<td>None</td>
		<td>
	      	<tt>Insert</tt><br /> 
	      	<tt>Update</tt><br /> 
	      	<tt>Delete</tt><br /> 
	      	All query methods
	    </td>
	</tr>
	
	<tr>
		<td><tt>&lt;insert&gt;</tt></td>
		<td>
			<tt>id</tt><br />
			<tt>parameterClass</tt><br />
			<tt>parameterMap</tt>
		</td>
		<td>     
			<tt>&lt;selectKey&gt;</tt><br />
     		<tt>&lt;generate&gt;</tt>
		</td>
		<td>
	      	<tt>Insert</tt><br /> 
	      	<tt>Update</tt><br /> 
	      	<tt>Delete</tt> 
	    </td>
	</tr>

	<tr>
		<td><tt>&lt;update&gt;</tt></td>
		<td>
			<tt>id</tt><br />
			<tt>parameterClass</tt><br />
			<tt>parameterMap</tt><br />
			<tt>extends</tt>
		</td>
		<td><tt>&lt;generate&gt;</tt></td>
		<td>
	      	<tt>Insert</tt><br /> 
	      	<tt>Update</tt><br /> 
	      	<tt>Delete</tt>
	    </td>
	</tr>

	<tr>
		<td><tt>&lt;delete&gt;</tt></td>
		<td>
			<tt>id</tt><br />
			<tt>parameterClass</tt><br />
			<tt>parameterMap</tt><br />
			<tt>extends</tt>
		</td>
		<td><tt>&lt;generate&gt;</tt></td>
		<td>
	      	<tt>Insert</tt><br /> 
	      	<tt>Update</tt><br /> 
	      	<tt>Delete</tt>
	    </td>
	</tr>

	<tr>
		<td><tt>&lt;select&gt;</tt></td>
		<td>
			<tt>id</tt><br />
			<tt>parameterClass</tt><br />
			<tt>resultClass</tt><br />
			<tt>listClass</tt><br />
			<tt>parameterMap</tt><br />
			<tt>resultMap</tt><br />
			<tt>cacheModel</tt><br />
			<tt>extends</tt>
		</td>
		<td><tt>&lt;generate&gt;</tt></td>
		<td>
	      	All query methods
	    </td>
	</tr>			

	<tr>
		<td><tt>&lt;procedure&gt;</tt></td>
		<td>
			<tt>id</tt><br />
			<tt>parameterClass</tt><br />
			<tt>resultClass</tt><br />
			<tt>listClass</tt><br />
			<tt>parameterMap</tt><br />
			<tt>resultMap</tt><br />
			<tt>cacheModel</tt>
		</td>
		<td>None</td>
		<td>
	      	<tt>Insert</tt><br /> 
	      	<tt>Update</tt><br /> 
	      	<tt>Delete</tt><br /> 
	      	All query methods
	    </td>
	</tr>	
</table>

<h2>Stored Procedures</h2>

<p>TODO</p>

</com:TContent>