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

📄 procedures.html

📁 通用的数据库中间库
💻 HTML
字号:
<html><head><meta name="KEYWORDS" content="      library, C++,       Oracle, SQLServer, DB2, Sybase, Informix, InterBase, SQLBase, ODBC, 
      SQL, server, client, database, programming, development, software, 
      Win32, Windows, Linux, Unix, Solaris,
      Microsoft, Borland, Centura, Gupta, IBM"><meta name="DESCRIPTION" content=
"SQLAPI++ is C++ library for accessing SQL databases (Oracle, SQLServer, Sybase, DB2, InterBase, SQLBase, Informix, ODBC).
It uses native APIs, provides low-level access to database-specific features."><title>SQLAPI++ Library - How To - Executing stored procedures</title></head><body bgcolor="#ffffff" BACKGROUND="../images/bg.gif" text="#000000"><!--class="GlbHdr"--> 
<table WIDTH=600 height=40 
frame=hsides BORDER="2" BORDERCOLOR="#004fcd" align="right" cellpadding="0" cellspacing="2" id="TABLE1">
    
    <tr><!--class="GlbDefault"-->
        <td width=70 bgcolor=#000094 bordercolor=black align=middle><A href="../index.html" style="TEXT-DECORATION: none" >
			<font color=white size=3 face=sans-serif>
			<b>Home</b></font></A></td></TD>
		<!--class="GlbActive"-->
        <td width=70 bgcolor=#00bb00 bordercolor=black align=middle><A href="../HowTo/index.html" style="TEXT-DECORATION: none" >
			<font color=white size=3  
      face=sans-serif>
			<b>How To</b></font></A></td>
		<!--class="GlbDefault"-->
        <td width=70 bgcolor=#000094 bordercolor=black align=middle><A href="../OnLineDoc/index.html" style="TEXT-DECORATION: none" >
			<font color=white size=3  
            face=sans-serif>
			<b>Online Documentation</b></font></A></td><!--class="GlbDefault"-->
        <td width=70 bgcolor=#000094 bordercolor=black align=middle><A href="../Support/index.html" style="TEXT-DECORATION: none" >
			<font color=white size=3  
            face=sans-serif>
			<b>Support</b></font></A></td>
        <td width=70 bgcolor=#000094 bordercolor=black align=middle><A href="../Download/index.html" style="TEXT-DECORATION: none" >
			<font color=white size=3  
            face=sans-serif>
			<b>Download</b></font></A></td>
        <td width=70 bgcolor=#000094 bordercolor=black align=middle><A href="../Order/index.html" style="TEXT-DECORATION: none" >
			<font color=white size=3  
      face=sans-serif>
			<b>Order</b></font></A></td>
    </tr>
</table>&nbsp;

<p>&nbsp;</p>
<p>&nbsp;</p>
<table width="100%" cellpadding=1 cellspacing=1>
	<tr>
		<td valign="top" align=left><!--class="LeftMenu"-->
			<table frame="void" CELLSPACING=2 cellpadding=2 width=165>
				<tr>
					<td><img align="middle" src="../images/green.gif" WIDTH="12" HEIGHT="12">
					<A href="connect.html" style ="TEXT-DECORATION: none" >
					<font color="white" size="2" face="sans-serif">
					Connecting to databases</font></A> </td>
				</tr>
				<tr>
					<td><img align="middle" src="../images/green.gif" WIDTH="12" HEIGHT="12">
					<A href="transactions.html" style ="TEXT-DECORATION: none" >
					<font color="white" face="sans-serif" size=2>
					Transactions</font></A> </td>
				</tr>
				<tr>
					<td><img align="middle" src="../images/green.gif" WIDTH="12" HEIGHT="12">
					<A href="commands.html" style ="TEXT-DECORATION: none" >
					<font color="white" size="2" face="sans-serif">
					Executing an SQL command</A> </FONT> </td>
				</tr>
				<tr>
					<td><img align="middle" src="../images/red.gif" WIDTH="12" 
                        HEIGHT="12" 
                       >
					<A href="procedures.html" style ="TEXT-DECORATION: none" >
					<font color="white" size="2" face="sans-serif">
					Executing stored procedures</A> 
                        </FONT> </td>
				</tr>
				<tr>
					<td><img align="middle" src="../images/green.gif" WIDTH="12" HEIGHT="12">
					<A href="bind.html" style ="TEXT-DECORATION: none" >
					<font color="white" size="2" face="sans-serif">
					Binding input parameters</A> </FONT> </td>
				</tr>
				<tr>
					<td><img align="middle" src="../images/green.gif" WIDTH="12" HEIGHT="12">
					<A href="fetch.html" style ="TEXT-DECORATION: none" >
					<font color="white" size="2" face="sans-serif">
					Fetching result set</A> </FONT> </td>
				</tr>
				<tr>
					<td><img align="middle" src="../images/green.gif" WIDTH="12" HEIGHT="12" 
                       >
					<A href="fetch_multiple.html" style ="TEXT-DECORATION: none" >
					<font color="white" size="2" face="sans-serif">
					Fetching multiple result sets</A> </FONT> </td>
				</tr>
				<tr>
					<td><img align="middle" src="../images/green.gif" WIDTH="12" HEIGHT="12" 
                       >
					<A href="performance.html" style ="TEXT-DECORATION: none" >
					<font color="white" size="2" face="sans-serif">
					Optimizing Database Performance</A> </FONT> </td>
				</tr>
				<tr>
					<td><img align="middle" src="../images/green.gif" WIDTH="12" HEIGHT="12">
					<A href="return_param.html" style ="TEXT-DECORATION: none" >
					<font color="white" size="2" face="sans-serif">
					Returning output parameters</A> </FONT> </td>
				</tr>
				<tr>
					<td><img align="middle" src="../images/green.gif" WIDTH="12" HEIGHT="12">
					<A href="blobs.html" style ="TEXT-DECORATION: none" >
					<font color="white" size="2" face="sans-serif">
					Working with 
					Long or Lob(CLob, BLob) Data</A> 
                        </FONT> </td>
				</tr>
				<tr>
					<td><img align="middle" src="../images/green.gif" WIDTH="12" HEIGHT="12"><A href="datetime.html" style="TEXT-DECORATION: none">
					<font color="white" size="2" face="sans-serif">
					Working with date/time values</A> </FONT> </td>
				</tr>
				<tr>
					<td><img align="middle" src="../images/green.gif" WIDTH="12" HEIGHT="12">
					<A href="errors.html" style ="TEXT-DECORATION: none" >
					<font color="white" size="2" face="sans-serif">
					Error handling</A> </FONT> </td>
				</tr>
				<tr>
					<td><img align="middle" src="../images/green.gif" WIDTH="12" HEIGHT="12">
					<A href="query_exampl.html" style ="TEXT-DECORATION: none" >
					<font color="white" size="2" face="sans-serif">
					Query examples</A> </FONT> </td>
				</tr>
			</table>
		</td>
		<td width="30">
			<p>  </p>
		</td>
		<td valign="top">
			<center>
			<h1>Executing stored procedures</h1>
			</center>
			<p>Calling (executing) a stored procedure (function) requires the following steps:</p>
      <OL>
			<li>Create a command object and pass stored 
                procedure      name to it. 
        
			<li>      Bind input parameters
        
			<li>      Execute stored procedure 
        
			<li>Process output parameters and possibly result set</li></OL>
			<p>Suppose, we want to call a procedure 
            <EM>TestProc</EM> with two numeric parameters <EM>n1</EM> and 
            <EM>n2</EM> where <EM>n1</EM> is input parameter and <EM>n2</EM> is 
            input/output parameter. Procedure will add <EM>n1</EM> and 
            <EM>n2</EM> and assign the result to <EM>n2</EM> (<EM>n2 = 
            n1+n2</EM>        ).</p>
			<h4>Step 1. Creating a command object and passing stored procedure name to it.</h4>
			<p>As usual, the first thing to do is to create 
            the objects. To execute a stored procedure we need two objects: <A 
            href="../OnLineDoc/Connection.html">SAConnection</A>
            (connection object) and <A 
            href="../OnLineDoc/Command.html">SACommand</A>           
                 (command object).</p>
			<p><STRONG><FONT face="" size=2><FONT 
            face=System>SACommand cmd(&amp;Connection, 
            &quot;TestProc&quot;);</FONT></FONT></STRONG><FONT><FONT 
            face=System></FONT></FONT>        </p>
			<p>The line above creates a command object 
            <EM>cmd</EM> based on previously created and connected connection 
            object <EM>Connection</EM> (for creating and connection 
            <EM>Connection</EM>  
        object see <A href="connect.html">Connecting to 
      databases</A>). 
            Second parameter is the name of the required procedure. Required 
            procedure can also be provided using <A 
            href="../OnLineDoc/Command_setCommandText.html">SACommand::setCommandText</A>         
               method.</p>
			<p><FONT face=System size=2><STRONG>SACommand 
      cmd(&amp;Connection);<BR>        cmd.setCommandText(&quot;TestProc&quot;);</STRONG></FONT>        </p>
			<p><FONT face=System 
            size=2><STRONG></STRONG></FONT>        &nbsp;</p>
			<h4>    Step 2. Binding input parameters</h4>
			<p>After parameters are created (automatically by the 
      Library or manually) they all initialized to null values. There are two methods of assigning values to them.</p>
			<p><STRONG>First: </STRONG>      using ordinary assignment:</p>
			<p><STRONG><FONT face=System 
            size=2>cmd.Param(&quot;n1&quot;).setAsLong() =   
      5;<BR>cmd.Param(&quot;n2&quot;).setAsLong() =   
10;</FONT></STRONG> 
            </p>
			<p><STRONG>Second: </STRONG>     using stream binding operator:</p>
			<p><STRONG><FONT face=System size=2>cmd 
            &lt;&lt; SAPos(&quot;n1&quot;) &lt;&lt; 5 &lt;&lt; 
            SAPos(&quot;n2&quot;) &lt;&lt; 10;</FONT></STRONG>       </p>
			<p><STRONG><FONT face=System 
            size=2></FONT></STRONG>       &nbsp;</p>
			<h4>    Step 3. Executing stored procedure</h4>
			<p>To actually execute a procedure call <A 
            href="../OnLineDoc/Command_Execute.html">SACommand::Execute</A>       method.</p>
			<p><STRONG><FONT face=System 
            size=2>cmd.Execute();</FONT></STRONG>        </p>
			<p>        &nbsp;</p>
			<h4>Step 4. Processing output parameters and possibly result set(s)</h4>
			<p>If stored procedure does not generate result 
            set(s) you can reach output parameters immediately after calling 
            <A 
            href="../OnLineDoc/Command_Execute.html" >SACommand::Execute</A>         
           :</p>
			<p><STRONG><FONT face=System 
            size=2>printf(&quot;%d\n&quot;, 
            cmd.Param(&quot;n2&quot;).asLong());</FONT></STRONG>        </p>
			<p>After the statement has been executed, 
            SQLAPI++ stores the returned values of output parameters in the <A 
            href="../OnLineDoc/Param.html">SAParam</A>     
                      
             objects bound to those parameters. On some servers these 
            returned values are not guaranteed to be set until all results 
            returned by the procedure have been fetched (using 
            <A href="../OnLineDoc/Command_FetchNext.html" >SACommand::FetchNext</A>
            method). See <A href="../ServerSpecific/index.html">Server specific 
            information</A> 
                 on output parameters 
            availability on different 
           DBMSs.</p>
      <P>For processing result set(s) (if any) see <A 
      href="fetch.html" 
     >Fetching result set</A>
     and <A 
            href="fetch_multiple.html">Fetching multiple result sets</A>.</P>
			<p>That is all there is to it. <STRONG>Steps 
            2-4</STRONG>        can be 
      repeated if you need to call procedure several times.</p>
			<p>          
              &nbsp;</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>
			<p>          
              &nbsp;</p>
		</td>
	<tr></tr>
</table></FONT>
</body></html>

⌨️ 快捷键说明

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