⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bind.html

📁 通用的数据库中间库
💻 HTML
📖 第 1 页 / 共 2 页
字号:
                (for more details see 
                <A href="commands.html">Executing an SQL command</A>
                and <A 
                href="procedures.html">Executing stored 
                procedures</A>):<BR><BR><FONT face=System>SACommand cmd(&amp;Connection, &quot;insert 
                into employees (name, age, comment) values 
                (:1, :2, :3)&quot;);</FONT><BR><BR>After creating 
                <EM>cmd</EM>
                object and passing a command text three <A 
                href="../OnLineDoc/Param.html">SAParam</A> objects are created 
                automatically. 
                <LI>Bind input variables by assigning values to <A 
                href="../OnLineDoc/Param.html">SAParam</A> objects.<BR>Because of 
                identifying parameters by their positions we should call <A 
                href="../OnLineDoc/Command_Param.html">SACommand::Param</A> 
                method with the next syntax:<BR><BR><FONT 
                face=System>cmd.Param(1).setAsString() = &quot;Roy 
                Mann&quot;;<BR>cmd.Param(2).setAsLong() = 42;<BR><FONT 
                face=System>cmd.Param(3).setAsNull();</FONT> <BR></FONT><BR>The 
                lines above set the value <EM>&quot;Roy Mann&quot;</EM> to the 
                parameter marked by <EM>:1</EM>,&nbsp; <EM>42</EM> to the parameter 
                marked by <EM>:2</EM> and <EM>null</EM> value to the 
                parameter marked by <EM>:3</EM>. 
                <LI>Execute the command:<BR><BR><FONT 
                face=System>cmd.Execute();<BR></FONT></LI></OL>
            <H3>Example 2. </H3>
            <P> We can use another variant of command text to insert a row 
            into the table:</P>
            <P><EM>insert into EMPLOYEES (NAME, AGE) values (:name, :age, 
            :comment)</EM></P>
            <P>This command has three input parameters to set values to 
            <EM>NAME</EM> and <EM>AGE</EM> columns.&nbsp; In that example input parameters 
            are marked by <EM>:name, :age, :comment</EM>. It means we will identify 
            a parameter by its <STRONG>name</STRONG>     . </P>
            <P>To create and execute the command we should do the following:</P>
            <OL>
                <LI>Create a command object <EM>cmd</EM>
                (for more details see 
                <A href="commands.html">Executing an SQL command</A>
                and <A 
                href="procedures.html">Executing stored 
                procedures</A>):<BR><BR><FONT face=System>SACommand cmd(&amp;Connection, &quot;insert 
                into employees (name, age, comment) values 
                (:name, :age, :comment)&quot;);</FONT><BR><BR>After creating 
                <EM>cmd</EM>object three <A 
                href="../OnLineDoc/Param.html">SAParam</A> 
                objects are created 
                automatically. 
                <LI>Bind input variables by assigning a value to <A 
                href="../OnLineDoc/Param.html">SAParam</A> object.<BR>Because of 
                identifying parameters by their names we should call <A 
                href="../OnLineDoc/Command_Param.html">SACommand::Param</A> 
                method with the next syntax:<BR><BR><FONT 
                face=System>cmd.Param(&quot;name&quot;).setAsString() = 
                &quot;Roy Mann&quot;;<BR>cmd.Param(&quot;age&quot;).setAsLong() = 42;<BR><FONT 
                face=System>cmd.Param(&quot;comment&quot;).setAsString() = 
                &quot;Manager&quot;;</FONT> <BR></FONT><BR>The lines above sets the value <EM>&quot;Roy 
                Mann&quot;</EM> to the parameter marked by <EM>:name</EM> , 
                <EM>42</EM> to the parameter marked by <EM>:age</EM> and <EM>&quot;Manager&quot;</EM> to the 
                parameter marked by <EM>:comment</EM>. 
                <LI>Execute the command:<BR><BR><FONT 
                face=System>cmd.Execute();<BR></FONT></LI></OL>
            <P>&nbsp;</P>
            <H2><A name="Using the stream operator<<"><A name="Using the stream operator<<">Using the stream operator&lt;&lt;</A><A name="Using the stream operator<<" 
           > 
 
   </A></A></H2>
            <P><A 
            href="../OnLineDoc/Command_operator_bind.html">SACommand::operator&lt;&lt;</A> 
            is a stream operator, so usually it is more convenient to use it 
            instead of assigning <A href="../OnLineDoc/Param.html">SAParam</A> 
            objects.</P>
            <H3>Example 3. </H3>
            <P>Let's execute the next SQL command to insert a row into the 
            table:</P>
            <P><EM>insert into 
            EMPLOYEES (NAME, AGE, COMMENT) values (:1, :2, :3)</EM></P>
            <P>This command has three input parameters to set values to 
            <EM>NAME, AGE</EM> and <EM>COMMENT</EM> columns.&nbsp; In that example input parameters 
            are marked by <EM>:1, :2, :3</EM>. It means we will identify a 
            parameter by its <STRONG>position</STRONG>     . </P>
            <P>To create and execute the command we should do the following:</P>
            <OL>
                <LI>Create a command object <EM>cmd</EM>
                (for more details see 
                <A href="commands.html">Executing an SQL command</A>
                and <A 
                href="procedures.html">Executing stored 
                procedures</A>):<BR><BR><FONT face=System>SACommand cmd(&amp;Connection, &quot;insert 
                into employees (name, age, comment) values 
                (:1, :2, :3)&quot;);</FONT><BR><BR>After creating 
                <EM>cmd</EM>
                object three <A 
                href="../OnLineDoc/Param.html">SAParam</A> 
                objects are created automatically 
                but in contrast to the previous examples we will 
                not use them explicitly. 
                <LI>Bind input variables by using <A 
                href="../OnLineDoc/Command_operator_bind.html">SACommand::operator&lt;&lt;</A>.<BR>Because 
                of identifying parameters by their positions we can put the 
                values into a stream:<BR><BR><FONT face=System>cmd &lt;&lt; &quot;Roy Mann&quot; 
                &lt;&lt; 42 &lt;&lt; SANull();<BR></FONT><BR>
                <P>The 
                line above sets the value <EM>&quot;Roy Mann&quot;</EM> to the 
                parameter marked by <EM>:1</EM>,&nbsp; <EM>42</EM> to the parameter 
                marked by <EM>:2</EM> and <EM>null</EM> value to the 
                parameter marked by <EM>:3</EM> . </P>
                <P>The order that you associate the values 
                is important (i.e. the first '&lt;&lt;' associates a bind with 
                <EM>:1</EM>, the second '&lt;&lt;' with <EM 
                >:2</EM>, the third '&lt;&lt;' with 
                <EM>:3</EM> ). </P>
                <LI>Execute the command:<BR><BR><FONT 
                face=System>cmd.Execute();<BR></FONT></LI></OL>
            <H3>Example 4. </H3>
            <P> We can use another variant of command text to insert a row 
            into the table:</P>
            <P><EM>insert into 
            EMPLOYEES (NAME, AGE, COMMENT) values (:name, :age, 
            :comment)</EM></P>
            <P>This command has three input parameters to set values to 
            <EM>NAME, AGE</EM> and <EM>COMMENT</EM> columns.&nbsp; In that example input parameters 
            are marked by <EM>:name, :age, :comment</EM>. It means we will identify 
            a parameter by its <STRONG>name</STRONG>     . </P>
            <P>To create and execute the command we should do the following:</P>
            <OL>
                <LI>Create a command object <EM>cmd</EM>
                (for more details see 
                <A href="commands.html">Executing an SQL command</A>
                and <A 
                href="procedures.html">Executing stored 
                procedures</A>):<BR><BR><FONT face=System>SACommand cmd(&amp;Connection, &quot;insert 
                into employees (name, age, comment) values 
                (:name, :age, :comment)&quot;);</FONT><BR><BR>After creating 
                <EM>cmd</EM> object three <A 
                href="http://www.sqlapi.com/OnLineDoc/Param.html">SAParam</A> objects are created automatically, but we will 
                not use them explicitly. 
                <LI>Bind input variables by putting values into a 
                stream.<BR>Because of identifying parameters by their names we 
                should use more complex sequence of stream elements. In 
                <STRONG>Example 3</STRONG> we put into a stream only parameters values 
                according to their positions (numbers). Now we should 
                explicitly specify the position of bind variable before putting 
                a value into a stream. To specify a position use 
                <STRONG>SAPos</STRONG> object:<BR><BR><FONT face=System>cmd 
                &lt;&lt; SAPos(&quot;name&quot;) &lt;&lt; &quot;Roy 
                Mann&quot; &lt;&lt; SAPos(&quot;age&quot;) &lt;&lt; 42 
                &lt;&lt; SAPos(&quot;comment&quot;) &lt;&lt; &quot;Manager&quot;;<BR></FONT><BR>
                <LI>Execute the command:<BR><BR><FONT 
                face=System>cmd.Execute();</FONT></LI></OL>
            <P>Binding Long, BLob and CLob data can have some differences from binding 
            other data types. <FONT color=black face="">See <A 
            href="blobs.html">Working with Long or Lob(CLob, BLob) Data</A> 
            to get 
            more information.</FONT></P>
            <h3>Problems and Questions</h3>
            <p>If you don't find the answer to you 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>
            <p>&nbsp;</p>
		</td>
	<tr></tr>
</table></FONT>
</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -