| 1 |
lars |
1 |
<com:TContent ID="body">
|
|
|
2 |
<h1>Inline Parameter Maps</h1>
|
|
|
3 |
|
|
|
4 |
<p>If you prefer to use inline parameters instead of parameter maps, you can add
|
|
|
5 |
extra type information inline too. The inline parameter map syntax lets you
|
|
|
6 |
embed the property name, the property type, the column type, and a null value
|
|
|
7 |
replacement into a parametrized SQL statement. The next four examples shows
|
|
|
8 |
statements written with inline parameters.</p>
|
|
|
9 |
|
|
|
10 |
<com:TTextHighlighter Language="xml" CssClass="source">
|
|
|
11 |
<statement id="insertProduct" parameterClass="Product">
|
|
|
12 |
insert into PRODUCT (PRD_ID, PRD_DESCRIPTION)
|
|
|
13 |
values (#id#, #description#)
|
|
|
14 |
</statement>
|
|
|
15 |
</com:TTextHighlighter>
|
|
|
16 |
|
|
|
17 |
<p>The following example shows how <tt>dbTypes</tt> can be declared inline.</p>
|
|
|
18 |
|
|
|
19 |
<com:TTextHighlighter Language="xml" CssClass="source">
|
|
|
20 |
<statement id="insertProduct" parameterClass="Product">
|
|
|
21 |
insert into PRODUCT (PRD_ID, PRD_DESCRIPTION)
|
|
|
22 |
values (#id, dbType=int#, #description, dbType=VarChar#)
|
|
|
23 |
</statement>
|
|
|
24 |
</com:TTextHighlighter>
|
|
|
25 |
|
|
|
26 |
<p>The next example shows how <tt>dbTypes</tt> and null value replacements can also
|
|
|
27 |
be declared inline.</p>
|
|
|
28 |
|
|
|
29 |
<com:TTextHighlighter Language="xml" CssClass="source">
|
|
|
30 |
<statement id="insertProduct" parameterClass="Product">
|
|
|
31 |
insert into PRODUCT (PRD_ID, PRD_DESCRIPTION)
|
|
|
32 |
values (#id, dbType=int, nullValue=-999999#, #description, dbType=VarChar#)
|
|
|
33 |
</statement>
|
|
|
34 |
</com:TTextHighlighter>
|
|
|
35 |
|
|
|
36 |
<p>A more complete example.</p>
|
|
|
37 |
|
|
|
38 |
<com:TTextHighlighter Language="xml" CssClass="source">
|
|
|
39 |
<update id="UpdateAccountViaInlineParameters" parameterClass="Account">
|
|
|
40 |
update Accounts set
|
|
|
41 |
Account_FirstName = #FirstName#,
|
|
|
42 |
Account_LastName = #LastName#,
|
|
|
43 |
Account_Email = #EmailAddress,type=string,dbType=Varchar,nullValue=no_email@provided.com#
|
|
|
44 |
where
|
|
|
45 |
Account_ID = #Id#
|
|
|
46 |
</update>
|
|
|
47 |
</com:TTextHighlighter>
|
|
|
48 |
|
|
|
49 |
<div class="note"><b class="tip">Note:</b>
|
|
|
50 |
Inline parameter maps are handy for small jobs, but when there are a lot of
|
|
|
51 |
type descriptors and null value replacements in a complex statement, an
|
|
|
52 |
industrial-strength, external <tt>parameterMap</tt> can be easier.
|
|
|
53 |
</div>
|
|
|
54 |
|
|
|
55 |
<h1>Standard Type Parameters</h1>
|
|
|
56 |
<p>In practice, you will find that many statements take a single parameter, often
|
|
|
57 |
an <tt>integer</tt> or a <tt>string</tt>. Rather than wrap a single value in another
|
|
|
58 |
object, you can use the standard library object (string, integer, et cetera)
|
|
|
59 |
as the parameter directly. The following example shows a statement using
|
|
|
60 |
a standard type parameter.</p>
|
|
|
61 |
|
|
|
62 |
<com:TTextHighlighter Language="xml" CssClass="source">
|
|
|
63 |
<statement id="getProduct" parameterClass="System.Int32">
|
|
|
64 |
select * from PRODUCT where PRD_ID = #value#
|
|
|
65 |
</statement>
|
|
|
66 |
</com:TTextHighlighter>
|
|
|
67 |
|
|
|
68 |
<p>Assuming <tt>PRD_ID</tt> is a numeric type, when a call is made to this Mapped
|
|
|
69 |
Statement, a standard integer can be passed in. The <tt>#value#</tt> parameter
|
|
|
70 |
will be replaced with the value of the integer. The name <tt>value</tt> is simply
|
|
|
71 |
a placeholder, you can use another moniker of your choice. Result Maps support
|
|
|
72 |
primitive types as results as well.</p>
|
|
|
73 |
|
|
|
74 |
<p>For your convenience, the following PHP primitive types are supported.</p>
|
|
|
75 |
<ul>
|
|
|
76 |
<li><tt>string</tt></li>
|
|
|
77 |
<li><tt>float</tt> or <tt>double</tt></li>
|
|
|
78 |
<li><tt>integer</tt> or <tt>int</tt></li>
|
|
|
79 |
<li><tt>bool</tt> or <tt>boolean</tt></li>
|
|
|
80 |
</ul>
|
|
|
81 |
|
|
|
82 |
<h1>Array Type Parameters</h1>
|
|
|
83 |
<p>You can also pass in a array as a parameter object. This would usually be a an
|
|
|
84 |
associative array. The following example shows a <tt><statement></tt> using
|
|
|
85 |
an array for a <tt>parameterClass</tt>.</p>
|
|
|
86 |
|
|
|
87 |
<com:TTextHighlighter Language="xml" CssClass="source">
|
|
|
88 |
<statement id="getProduct" parameterClass="array">
|
|
|
89 |
select * from PRODUCT
|
|
|
90 |
where PRD_CAT_ID = #catId#
|
|
|
91 |
and PRD_CODE = #code#
|
|
|
92 |
</statement>
|
|
|
93 |
</com:TTextHighlighter>
|
|
|
94 |
|
|
|
95 |
<p>In the above example, notice that the SQL in this Mapped Statement
|
|
|
96 |
looks like any other. There is no difference in how the inline parameters are
|
|
|
97 |
used. If an associative array is passed, it must contain keys named <tt>catId</tt>
|
|
|
98 |
and <tt>code</tt>. The values referenced by those keys must be of the appropriate
|
|
|
99 |
type for the column, just as they would be if passed from a properties object.</p>
|
|
|
100 |
|
|
|
101 |
|
|
|
102 |
</com:TContent>
|