📄 command_operator_bind.html
字号:
&</B></B></B></B></B>Value
<B>
<B>
<B>
<B><B>
);</B>
<B> <BR>throw
(SAException);</B>
</B>
</B>
</B>
</B></FONT></FONT></FONT></FONT></FONT></P>
<P><font face="Arial"><B>SACommand &operator << ( const SALongBinary
&</B>LongValue<B>
);</B>
<B> <BR>throw
(SAException);</B></font></P>
<P><font face="Arial"><B>SACommand &operator << ( const SALongChar
&</B>LongValue<B>
);</B>
<B> <BR>throw
(SAException);</B></font></P><font face="Arial"><B>
<P><font face="Arial"><B>SACommand &operator << ( const SABlob
&</B>
</B>LobValue<B><B>
)</B><B>
;</B>
<B> <BR>throw
(SAException);</B></font></P>
<P>SACommand &operator << ( const
SAClob &</B>LobValue<B>
)</B><B>
;</B>
<B> <BR>throw
(SAException);</B></FONT></P><font face="Arial"><B>
<P>SACommand &operator << ( const SAValueRead
&</B>Value<B><B>
)</B><B>
;</B>
<B> <BR>throw
(SAException);</B>
</B></P></font>
<P> Binds input
variables.
</P>
<H3>Parameters</H3>
<p><EM>Value</EM>
.
A value of an input
variable.</p>
<p><EM>LongValue</EM>. A reference to an aiding object
representing a value of a long input variable or a callback function which will be
used for getting the long
value.</p>
<p><EM>LobValue</EM>. A reference to an aiding
object representing a value
of a Lob input variable or a callback function which will be
used for getting the Lob
value.</p>
<p><EM>pos</EM>. A reference to the <STRONG>SAPos</STRONG> object which represents the position of
input parameter in the
command.</p>
<h3>Remarks</h3>
<P>This operator is used for associating data objects to the command object. Every
command object maintains an internal heterogeneous array of
parameter objects - this operator assigns values to parameter objects from this
array. </P>
<P>Because of the operator returns a reference to a
<STRONG>SACommand</STRONG> object you can chain the operator e.g.
<EM>cmd << 3 << 2.5 <<
"Istanbul";</EM></P>
<P>By default the sequence of values
corresponds to the numbers of parameters in a command text.<BR><STRONG><EM>E.g.
</EM></STRONG>(cmd is a <STRONG>SACommnad</STRONG>
object)</P>
<OL>
<LI><FONT face="Times New Roman"><EM>Select a from b where c= :1 and
d= :2<BR></EM><STRONG>cmd << 5
<< "qwerty"; </STRONG><BR>binds <STRONG>5</STRONG> to
c(:1) and <STRONG>qwerty</STRONG> to d(:2)
parameters. <BR>
<BR></FONT>
<LI><EM>Select a from b where c= :2 and d=
:1<BR></EM><STRONG>cmd << 5 <<
"qwerty"; </STRONG><BR>binds <STRONG>5</STRONG> to
d(:1) and <STRONG>qwerty</STRONG> to c(:2)
parameters (see the difference with example 1). <BR>
<BR>
<LI><EM>Select a from b where c= :1 and
d= :3<BR></EM><STRONG>cmd << 5 <<
"qwerty"; </STRONG><BR>
causes an error (throws an
exception) because <STRONG><<
"qwerty"</STRONG>
tries to bind :2 parameter and our command
does not have such.</LI></OL>
<P>If you want to assign <EM>null</EM> value to
an input variable you have to include <STRONG>SANull</STRONG> object
in the chain of bind operators in place of <EM>null</EM> value. </P>
<P><STRONG><EM>E.g.
</EM></STRONG>(cmd is a <STRONG>SACommnad</STRONG> object) </P>
<OL>
<LI><FONT face="Times New Roman"><EM>Select a from b where c= :1 and
d= :2<BR></EM><STRONG>cmd << 5
<< SANull(); </STRONG><BR>binds <STRONG>5</STRONG> to
c(:1) and <STRONG>null</STRONG> to d(:2)
parameters. <BR></FONT></LI></OL>
<P>
If you want to bind
a parameter by name or change the order of binding variables you
have to include a <STRONG>SAPos</STRONG> object before the value in the chain
of bind operators to prepare the required parameter position for the next
bind.</P>
<P><EM><STRONG>E.g.</STRONG></EM> (cmd is a
<STRONG>SACommnad</STRONG>
object)</P>
<OL>
<LI><EM>Select a from b where c = :1 and d
=
:2 </EM>
<BR><STRONG>cmd << SAPos(2) << 5 << SAPos(1)
<< "qwerty"; </STRONG><BR>first binds d(:2)
parameter with value of <STRONG>5</STRONG>, then c(:1) with
value of <STRONG>qwerty</STRONG>.<BR>
<LI><EM>Select a from b where c = :c_bind
and d =
:d_bind </EM>
<BR><STRONG>cmd << SAPos("c_bind") << 5
<< SAPos("d_bind") << "qwerty";
</STRONG><BR>
is the
right sequence to be used.</LI></OL>
<P>
</P>
<P>Values for the input parameters can also be assigned to <STRONG
>SAParam</STRONG>
object. </P>
<P>Syntax <STRONG>SACommand &operator
<< ( const SAValueRead &</B>Value );</STRONG> allows to
set input variable's value from existing <STRONG>SAParam</STRONG> or
<STRONG>SAField</STRONG> object. </P>
<H3>Server specific notes</H3>
<P>Binding Lob(CLob, BLob) data when working
with <STRONG><A
href="../ServerSpecific/Oracle.html" title="Oracle server specific information">Oracle</A></STRONG>
server has some
differences from others. It's necessary for a name of bind variable
to be the same as the column name it associated with.</P>
<P><FONT face=System>Ex.: Update TEST set <FONT
color=maroon face="">FBLOB = :fblob</FONT>
where FKEY =
'KEY'</FONT> </P>
<P>Therefore, it's impossible to bind Lob(CLob,
BLob) data to Oracle database by position. </P>
<H3>See also</H3>
<P>
<A href="Command_CreateParam.html" target="" >CreateParam</A>, <A
href="Command_Param.html">Param</A>, <A
href="Command_ParamByIndex.html"
target="">ParamByIndex</A>,
<A
href="Command_ParamCount.html">ParamCount</A>
</P>
<P><A href="Param.html" >SAParam</A>, <A
href="Field.html">SAField</A>
</P>
<p><A href="../HowTo/errors.html" >Error
handling</A> </p>
<H3>Problems and Questions</H3>
<P> If
you haven't found the answer to your questions or
have some problems on using the Library, please, send e-mail to <A
href="mailto:howto@sqlapi.com">howto@sqlapi.com</A>.
</P>
</td>
<tr></tr>
</table>
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -