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

📄 command_examples.html

📁 能够连接各种数据库的API
💻 HTML
📖 第 1 页 / 共 2 页
字号:
			<A name=FetchNext></A>
			<H3>FetchNext</H3>
			<FONT face=Courier>
			<P>
			/*<BR>
			Fetch result set 
            row by row.<BR>     
			Exception handling is omitted 
            for simplicity.<BR>
			*/</P>
			<P>SAConnection con;</P>
			<P>con.Connect(&quot;dbname&quot;, 
            &quot;username&quot;, &quot;password&quot;, SA_Oracle_Client);</P>
			<P>SACommand cmd(&amp;con, &quot;Select * from 
            test_tbl&quot;);</P>
			<P>cmd.Execute();</P>
			<P>while(<STRONG>cmd.FetchNext()</STRONG>)<BR>{<BR>&nbsp;&nbsp;&nbsp; ...<BR>} 
			</FONT></P>
      <P>

			<HR>
			<A name=CreateParam></A>
      <P></P>
			<H3>CreateParam</H3>
			<FONT face=Courier>
			<P>
			/*<BR>
			  Create params 
            explicitly.<BR>     
			Exception handling is omitted 
            for simplicity.<BR>
			*/</P>
			<P>SAConnection con;</P>
			<P>con.Connect(&quot;dbname&quot;, 
            &quot;username&quot;, &quot;password&quot;, SA_Oracle_Client);</P>
			<P> SACommand cmd(&amp;con, 
            &quot;test_proc&quot;);</P>
			<P><STRONG>cmd.CreateParam(&quot;nInput&quot;, SA_dtLong, sizeof(long), 
            SA_ParamInput);</STRONG>   </P>
			<P><STRONG><STRONG>cmd.CreateParam(&quot;nOutput&quot;, SA_dtLong, 
            sizeof(long), SA_ParamOutput);</STRONG></STRONG>   </P>
			<P>cmd &lt;&lt; SAPos(&quot;nInput&quot;) 
            &lt;&lt; 1L; /*bind input*/</P>
			<P>   cmd.Execute();</P>
			<P>printf(&quot;Output value: %ld\n&quot;, 
            cmd.Param(&quot;nOutput&quot;).asLong());</P>
			</FONT>

			<HR>
			<A name=DestroyParams></A>
			<H3>DestroyParams</H3>
			<FONT face=Courier>
			<P>
			/*<BR>
			   Destroy params 
            explicitly.<BR>&gt; Exception handling is 
            omitted for simplicity.<BR>
			*/</P>
			<P>
			SAConnection con;</P>
			<P>SACommand cmd(&amp;con, 
            &quot;test_proc&quot;);</P>
			<P>...</P>
			<P><STRONG>cmd.DestroyParams();</STRONG></P>
			</FONT>

			<HR>
			<A name=ParamCount></A>
			<H3>ParamCount</H3>
			<FONT face=Courier>
			<P>
			/*<BR>
			 Print procedure 
            parameters names.<BR>     
			Exception handling is 
            omitted for simplicity.<BR>
			*/</P>
			<P>SAConnection con;</P>
			<P>con.Connect(&quot;dbname&quot;, 
            &quot;username&quot;, &quot;password&quot;, SA_Oracle_Client);</P>
			<P>SACommand cmd(&amp;con, 
            &quot;test_proc&quot;);</P>
			<P>for(int i = 0; i &lt; <STRONG>cmd.ParamCount(); 
      </STRONG>++i)<BR>{<BR>&nbsp;&nbsp;&nbsp; printf(&quot;Param %d name: 
            %s\n&quot;, i+1, (const char *)cmd.ParamByIndex().Name());<BR>}</P>
			</FONT>

			<HR>
			<A name=ParamByIndex></A>
			<H3>ParamByIndex</H3>
			<FONT face=Courier>
			<P>
			<FONT face=Courier>
			/*<BR>
			 Print procedure parameters 
            names.<BR>     
			Exception handling is omitted for 
            simplicity.<BR>
			*/</P>
			<P>SAConnection con;</P>
			<P>con.Connect(&quot;dbname&quot;, 
            &quot;username&quot;, &quot;password&quot;, SA_Oracle_Client);</P>
			<P>SACommand cmd(&amp;con, 
            &quot;test_proc&quot;);</P>
			<P>for(int i = 0; i &lt; cmd.ParamCount(); 
            ++i)<BR>{<BR>&nbsp;&nbsp;&nbsp; printf(&quot;Param %d name: %s\n&quot;, 
            i+1, (const char *)<STRONG>cmd.ParamByIndex(i)</STRONG>.Name());<BR>}</P>
			</FONT></FONT>

			<HR>
			<A name=Param></A>
			<H3>Param</H3>
			<FONT face=Courier>
			<P>
			/*<BR>
			Bind parameters 
            by name and position.<BR>     
			Exception handling is 
            omitted for simplicity.<BR>
			*/</P>
			<P>SAConnection con;</P>
			<P>con.Connect(&quot;dbname&quot;, 
            &quot;username&quot;, &quot;password&quot;, SA_Oracle_Client);</P>
			<P>SACommand cmd(&amp;con, &quot;Select * from 
            test_tbl where fid = :1 or fid = :fidvalue2&quot;);</P>
			<P><STRONG>cmd.Param(1)</STRONG>.setAsLong() = 15;</P>
			<P><STRONG>cmd.Param(&quot;fidvalue2&quot;)</STRONG>.setAsLong() = 
32;</P>
			<P>   cmd.Execute();</P>
			<P>   ...</P>
			</FONT>

			<HR>
			<A name=operator_bind></A>
			<H3>operator &lt;&lt;</H3>
			<FONT face=Courier>
			<FONT face=Courier>
			<P>
			/*<BR>
			Bind parameters 
            by name and position.<BR>     
			Exception handling is 
            omitted for simplicity.<BR>
			*/</P>
			<P>SAConnection con;</P>
			<P>con.Connect(&quot;dbname&quot;, 
            &quot;username&quot;, &quot;password&quot;, SA_Oracle_Client);</P>
			<P>SACommand cmd(&amp;con, &quot;Select * from 
            test_tbl where fid = :1 or fid = :fidvalue2&quot;);</P>
			<P><STRONG>cmd &lt;&lt; 
            15L &lt;&lt; SAPos(&quot;fidvalue2&quot;) &lt;&lt; 32L;</STRONG> 
   </P>
			<P>   cmd.Execute();</P>
			<P>   ...</P>
			</FONT>
			</FONT>
      <P></P>

			<HR>
			<A name=FieldCount></A>
			<H3>FieldCount</H3>
			<FONT face=Courier>
			<P><FONT face=Courier>
			</P>
      <P>/*<BR>Print select 
            statement fields names.<BR>Exception handling 
            is omitted for simplicity.<BR>*/</P>
      <P>SAConnection con;</P>
      <P>con.Connect(&quot;dbname&quot;, 
            &quot;username&quot;, &quot;password&quot;, SA_Oracle_Client);</P>
      <P>SACommand cmd(&amp;con, &quot;Select * from 
            test_tbl&quot;);</P>
      <P>cmd.Execute();</P>
      <P>for(int i = 0; i &lt; <STRONG>cmd.FieldCount(); 
      </STRONG>++i)<BR>{<BR>&nbsp;&nbsp;&nbsp; printf(&quot;Field %d name: 
            %s\n&quot;, i+1, (const char *)cmd.Field(i+1).Name());<BR>}</P>
			</FONT></FONT>

			<HR>
			<A name=Field></A>
			<H3>Field</H3>
			<FONT face=Courier>
      <P>/*<BR>Exception 
            handling is omitted for simplicity.<BR>*/</P>
      <P>SAConnection con;</P>
      <P>con.Connect(&quot;dbname&quot;, 
            &quot;username&quot;, &quot;password&quot;, SA_Oracle_Client);</P>
      <P>SACommand cmd(&amp;con, &quot;Select fid 
            from test_tbl&quot;);</P>
      <P>cmd.Execute();</P>
      <P>if(cmd.FetchNext())<BR>{<BR>&nbsp;&nbsp;&nbsp; if(<STRONG>cmd.Field(1)</STRONG>.asLong() != 
      <STRONG>cmd.Field(&quot;fid&quot;)</STRONG>.asLong())<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot;Very 
            strange!\n&quot;);<BR>}</P>
			<P>
			</FONT>

			<HR>
			<A name="operator_get"></A>
      <P></P>
			<H3>operator []</H3>
			<FONT face=Courier>
			<P><FONT face=Courier>/*<BR>Exception handling is omitted for 
            simplicity.<BR>
			*/</P>
      <P>SAConnection con;</P>
      <P>con.Connect(&quot;dbname&quot;, 
            &quot;username&quot;, &quot;password&quot;, SA_Oracle_Client);</P>
      <P>SACommand cmd(&amp;con, &quot;Select fid 
            from test_tbl&quot;);</P>
      <P>cmd.Execute();</P>
      <P>if(cmd.FetchNext())<BR>{<BR>&nbsp;&nbsp;&nbsp; if(<STRONG>cmd[1]</STRONG>.asLong() != 
      <STRONG>cmd[&quot;fid&quot;]</STRONG>.asLong())<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            printf(&quot;Very strange!\n&quot;);<BR>}</P>
			<P>
			</FONT></FONT>
            			
			<HR>
			<A name=NativeHandles></A>
            <P></P>
			<H3>NativeHandles</H3>
      <P><FONT face=Courier>/*<BR>Exception handling is omitted for 
            simplicity.<BR>*/</FONT><FONT face=Courier></FONT></P><FONT 
      face=Courier><FONT face=Courier>
      <P>#include &lt;ora7API.h&gt;<BR>#include &lt;oraAPI.h&gt;</P>
      <P>SAConnection con;</FONT></P>
      <P>con.Connect(&quot;dbname&quot;, 
            &quot;username&quot;, &quot;password&quot;, SA_Oracle_Client);</P>
      <P>SACommand cmd(&amp;con, &quot;Select * from 
            test_tbl&quot;);</P>
      <P>cmd.Open(); /* make sure command handles are 
            initialized*/</P>
      <P>if(con.ClientVersion() &gt;= 0x0008000) /* 
            OCI 8.x */<BR>{</P>
      <P>&nbsp;&nbsp;&nbsp; ora8API *p_ora8API = 
            (ora8API *)con.NativeAPI();</P>
      <P>&nbsp;&nbsp;&nbsp; ora8CommandHandles 
            *p_ora8CH = (ora8CommandHandles *)cmd.NativeHandles();</P>
      <P>&nbsp;&nbsp;&nbsp; /* call any OCI* 
            function(s) */<BR>&nbsp;&nbsp;&nbsp; /* passing 
            required command handles */<BR>&nbsp;&nbsp;&nbsp; /* f.ex., p_ora8CH-&gt;m_pOCIStmt */<BR>&nbsp;&nbsp;&nbsp; ...</P>
      <P>}<BR>else /* OCI 7.x 
            */<BR>{</P>
      <P>&nbsp;&nbsp;&nbsp; ora7API *p_ora7API = 
            (ora7API *)con.NativeAPI();</P>
      <P>&nbsp;&nbsp;&nbsp; ora7CommandHandles 
            *p_ora7CH = (ora7CommandHandles *)cmd.NativeHandles();</P>
      <P>&nbsp;&nbsp;&nbsp; /* call any o* 
            function(s) */<BR>&nbsp;&nbsp;&nbsp; /* passing 
            required command handles */<BR>&nbsp;&nbsp;&nbsp; /* f.ex., p_ora7CH-&gt;m_cda */<BR>&nbsp;&nbsp;&nbsp; ...</P>
      <P>}</FONT></P>

			<HR>
			<H3><A name=Option>Option</A></H3>
			<FONT face=Courier><FONT face=Courier>
			<P>
			/*<BR>
			 
			  Example 1. 
            InterBase server option SQL Dialect.<BR>Exception handling is omitted for simplicity.<BR>
			*/ 
			</P>
      <P>SAConnection con;</P>
      <P>con.Connect(&quot;dbname&quot;, 
            &quot;username&quot;, &quot;password&quot;, 
SA_InterBase_Client);</P>
      <P> /* assume t_field is a TIMESTAMP type field 
            (introduced in SQL Dialect 3)<BR>*/<BR>SACommand cmd(&amp;con, &quot;Select t_field 
            from test_tbl&quot;);</P>
      <P><STRONG>cmd.setOption(&quot;SQLDialect&quot;)</STRONG>= 
            &quot;1&quot;;</P>
      <P>cmd.Execute(); // returns an error<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            // because there is no TIMESTAMP 
            <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            // data type in SQL Dialect 1.</P>
      <P><STRONG>cmd.setOption(&quot;SQLDialect&quot;)</STRONG>=&quot;3&quot;;</P>
      <P>   cmd.setCommandText(&quot;Select t_field from 
            test_tbl&quot;);</P>
      <P>cmd.Execute(); // no error</P>
      <P>while(cmd.FetchNext())<BR>{<BR>&nbsp;&nbsp;&nbsp; ...<BR>}</P>
			<FONT face=Courier><FONT face=Courier>
			<P>
			/*<BR>
			 
			  Example 2. 
            SQLBase server option SQLPPCX (cursor-context preservation).<BR>Exception handling is omitted for 
            simplicity.<BR>
			*/ 
			</P>
      <P>SAConnection con;</P>
      <P>con.Connect(&quot;dbname&quot;, 
            &quot;username&quot;, &quot;password&quot;, SA_SQLBase_Client);</P>
      <P> SACommand cmd(&amp;con, &quot;Select fid 
            from test_tbl&quot;);</P><STRONG>
      <P>cmd.setOption(&quot;SQLPPCX&quot;)</STRONG>=&quot;on&quot;;</P>
      <P>cmd.Execute();</P>
      <P>con.Commit(); // result set will not be 
            destroyed<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            // after that command because SQLPPCX<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            // option is &quot;on&quot;&nbsp;</P>
      <P>while(cmd.FetchNext())<BR>{&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; printf(&quot;%d\n&quot;, 
            cmd[1].asLong());<BR>}</P>
      <P><STRONG>cmd.setOption(&quot;SQLPPCX&quot;)</STRONG>=&quot;off&quot;;</P>
      <P>   cmd.setCommandText(&quot;Select t_field from 
            test_tbl&quot;);</P>
      <P>cmd.Execute();</P>
      <P>con.Commit(); // result set will be 
            destroyed<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            // after that command because SQPPCX<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            // option is &quot;off&quot;&nbsp;</P>
			<FONT face=Courier><FONT face=Courier>
			<P>
			/*<BR>
			 
			  Example 3. 
            SQLServer command option OpenCursor.<BR>Exception handling is omitted for simplicity.<BR>
			*/ 
			</P>
      <P>/*The following code of Example 3 is 
            incorrect,<BR>it cause an error. See the right code below.*/</P>
      <P>SAConnection con;</P>
      <P>con.Connect(&quot;dbname&quot;, 
            &quot;username&quot;, &quot;password&quot;, 
SA_SQLServer_Client);</P>
      <P> SACommand cmd1(&amp;con, &quot;Select fid 
            from test_tbl&quot;);</P>
      <P> SACommand cmd2(&amp;con, &quot;Insert into 
            temp_tbl (fid_tmp) values (:1)&quot;);</P>
      <P>cmd1.Execute();</P>
      <P>while(cmd1.FetchNext())<BR>{&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; cmd2 &lt;&lt; 
            cmd1[1].asLong();<BR>&nbsp;&nbsp;&nbsp; cmd2.Execute(); // returns 
            an 
            error<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            // &quot;Attempt to 
            initiate<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            // a new SQLServer operation 
            with<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            // results pending&quot;<BR>}<BR>/* end of 
            incorrect code */</P>
      <P>/*The following code of Example 3 is 
            correct.*/</P>
      <P>SAConnection con;</P>
      <P>con.Connect(&quot;dbname&quot;, 
            &quot;username&quot;, &quot;password&quot;, 
SA_SQLServer_Client);</P>
      <P> SACommand cmd1(&amp;con, &quot;Select fid 
            from test_tbl&quot;);</P>
      <P><STRONG>cmd1.setOption(&quot;OpenCursor&quot;)</STRONG>=&quot;100&quot;;</P>
      <P> SACommand cmd2(&amp;con, &quot;Insert into 
            temp_tbl (fid_tmp) values (:1)&quot;);</P>
      <P>cmd1.Execute();<BR></P>
      <P>while(cmd1.FetchNext())<BR>{&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; cmd2 &lt;&lt; 
            cmd1[1].asLong();<BR>&nbsp;&nbsp;&nbsp; cmd2.Execute(); // no 
            error<BR>}<BR></P>
      <P></P>
      <P>con.Commit();&nbsp;&nbsp;</FONT> 
            
			</FONT></P></FONT>
			</FONT></FONT>
			</FONT>

			<HR>
			<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 + -