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

📄 connection_examples.html

📁 通用的数据库中间库
💻 HTML
📖 第 1 页 / 共 2 页
字号:
      <P><FONT face=Courier>&nbsp;&nbsp;&nbsp; SAConnection con;</FONT></P>
      <P><FONT face=Courier>/* connect to database and so on 
*/<BR>...</FONT></P>
      <P><FONT face=Courier>}</FONT></P>
      <P><FONT face=Courier>/* At this point con is physically disconnected from 
      database in SAConnection destructor */</FONT></P>
      <P><FONT face=Courier>SAConnection *pCon = new 
      SAConnection;</FONT></P><FONT face=Courier>
      <P><FONT face=Courier>/* connect to database and so on 
*/<BR>...</FONT></P>
      <P>/* next line will disconnect from database if needed */</P>
      <P>delete pCon;</P></FONT>  
            			
	  <HR id=HR1>
	  <A name=setIsolationLevel></A>
      <H3>setIsolationLevel</H3>
      <P><FONT face=Courier>/*<BR>Sets transaction isolation level.<BR>     
      Exception handling is omitted for simplicity.<BR>*/</FONT><FONT face=Courier></FONT></P><FONT face=Courier>
      <P><FONT face=Courier>SAConnection con;</FONT></P>
      <P>con.Connect(&quot;dbname&quot;, &quot;username&quot;, &quot;password&quot;, 
      SA_Oracle_Client);</P>
      <P><STRONG>con.setIsolationLevel(SA_Serializable);</STRONG></P>  </FONT>

	  <HR id=HR1>
	  <A name=IsolationLevel></A>
      <H3>IsolationLevel</H3>
      <P><FONT face=Courier>/*<BR>Query current isolation level.<BR>     
      Exception handling is omitted for simplicity.<BR>*/</FONT><FONT face=Courier></FONT></P><FONT face=Courier>
      <P><FONT face=Courier>SAConnection con;</FONT></P>
      <P><FONT face=Courier><FONT face=Courier>/* connect to database and so on 
      */<BR></FONT>...</FONT></P>
      <P><FONT face=Courier>switch(</FONT><FONT 
      face=Courier><STRONG>con.IsolationLevel()</STRONG>)<BR></FONT><FONT 
      face=Courier>{<BR></FONT><FONT face=Courier>&nbsp;&nbsp;&nbsp; case 
      SA_LevelUnknown:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /*do smth. 
      specific for default 
      isolation*/<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      break;<BR>&nbsp;&nbsp;&nbsp; case 
      SA_ReadCommitted:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /*do smth. 
      specific for Read 
      Committed*/<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      break;<BR>&nbsp;&nbsp;&nbsp; case 
      SA_ReadCommitted:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /*do smth. 
      specific for Read 
      Committed*/<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      break;<BR>&nbsp;&nbsp;&nbsp; case 
      SA_RepeatableRead:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /*do 
      smth. specific for Repeatable 
      Read*/<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      break;<BR>&nbsp;&nbsp;&nbsp; case 
      SA_Serializable:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /*do smth. 
      specific for Serializable*/<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      break;<BR></FONT><FONT face=Courier>}</FONT></P>  </FONT>

	  <HR id=HR1>
	  <A name=setAutoCommit></A>
      <H3>setAutoCommit</H3>
      <P><FONT face=Courier>/*<BR>This example turns autocommit on.<BR>     
      Exception handling is omitted for simplicity.<BR>*/</FONT><FONT face=Courier></FONT></P><FONT face=Courier>
      <P><FONT face=Courier>SAConnection con;</FONT></P>
      <P>con.Connect(&quot;dbname&quot;, &quot;username&quot;, &quot;password&quot;, 
      SA_Oracle_Client);</P>
      <P><STRONG>con.setAutoCommit(SA_AutoCommitOn);</STRONG>   
      </P>  </FONT>

	  <HR id=HR1>
	  <A name=AutoCommit></A>
      <H3>AutoCommit</H3>
      <P><FONT face=Courier>/*<BR>Query current autocommit option<BR>     
      Exception handling is omitted for simplicity.<BR>*/</FONT><FONT face=Courier></FONT></P><FONT face=Courier>
      <P><FONT face=Courier>SAConnection con;</FONT></P>
      <P>con.Connect(&quot;dbname&quot;, &quot;username&quot;, &quot;password&quot;, 
      SA_Oracle_Client);</P>
      <P>   
      ...</P>
      <P>switch(<STRONG>con.AutoCommit()</STRONG>)<BR>{<BR>&nbsp;&nbsp;&nbsp; 
      case SA_AutoCommitUnknown:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      printf(&quot;Autocommit mode is unknown 
      (default)&quot;);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>&nbsp;&nbsp;&nbsp; 
      case SA_AutoCommitOff:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      printf(&quot;Autocommit mode is 
      off&quot;);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>&nbsp;&nbsp;&nbsp; 
      case SA_AutoCommitOn:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      printf(&quot;Autocommit mode is 
      on&quot;);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>    }</P>  </FONT>

	  <HR id=HR1>
	  <A name=Commit></A>
      <H3>Commit</H3>
      <P><FONT face=Courier>/*<BR>  Commits transaction.<BR>     
      Exception handling is omitted for simplicity.<BR>*/</FONT><FONT face=Courier></FONT></P><FONT face=Courier>
      <P><FONT face=Courier>SAConnection con;</FONT></P>
      <P>con.Connect(&quot;dbname&quot;, &quot;username&quot;, &quot;password&quot;, 
      SA_Oracle_Client);</P>
      <P>/*Create commands, execute SQL 
      statements*/<BR>   
      ...</P>
      <P><STRONG>con.Commit()</STRONG>   
      ;</P>  </FONT>

	  <HR id=HR1>
	  <A name=Rollback></A>
      <H3>Rollback</H3><FONT face=Courier>
      <P><FONT face=Courier>/*<BR>  Rollbacks transaction.<BR>     
      Exception handling is omitted for simplicity.<BR>*/</FONT><FONT face=Courier></FONT></P><FONT face=Courier>
      <P><FONT face=Courier>SAConnection con;</FONT></P>
      <P>con.Connect(&quot;dbname&quot;, &quot;username&quot;, &quot;password&quot;, 
      SA_Oracle_Client);</P>
      <P>/*Create commands, execute SQL 
      statements*/<BR>   
      ...</P>
      <P><STRONG>con.Rollback()</STRONG>   
      ;</P>  </FONT>  </FONT>

	  <HR id=HR1>
	  <A name=NativeAPI></A>
      <H3>NativeAPI</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;ora8API.h&gt;</P> </FONT>
      <P><FONT face=Courier>SAConnection con;</FONT></P>
      <P>con.Connect(&quot;dbname&quot;, &quot;username&quot;, &quot;password&quot;, 
      SA_Oracle_Client);</P>
      <P>if(con.ClientVersion() &gt;= 0x0008000) /* OCI 8.x 
      */<BR>   
      {</P>
      <P>&nbsp;&nbsp;&nbsp; ora8API *p_ora8API =             (ora8API 
      *)<STRONG>con.NativeAPI()</STRONG>   
      ;</P>
      <P>&nbsp;&nbsp;&nbsp; /* call any OCI* function(s) 
      */<BR>&nbsp;&nbsp;&nbsp; /* f.ex., p_ora8API-&gt;OCIStmtExecute(...) 
      */<BR>  &nbsp;&nbsp;&nbsp; 
      ...</P>
      <P>}<BR>else /* OCI 7.x */<BR>   
      {</P>
      <P>&nbsp;&nbsp;&nbsp; ora7API *p_ora7API =             (ora7API 
      *)<STRONG>con.NativeAPI()</STRONG>   
      ;</P>
      <P>&nbsp;&nbsp;&nbsp; /* call any o* function(s) 
      */<BR>&nbsp;&nbsp;&nbsp; /* f.ex., p_ora7API-&gt;oparse(...) 
      */<BR>  &nbsp;&nbsp;&nbsp; 
      ...</P>
      <P>   
      }</P>  </FONT>

	  <HR id=HR1>
	  <A name=NativeHandles></A>
      <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;ora8API.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>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; ora8ConnectionHandles *p_ora8CH 
      =  (ora8ConnectionHandles 
      *)con.NativeHandles();</P>
      <P>&nbsp;&nbsp;&nbsp; /* call any OCI* function(s) 
      */<BR>&nbsp;&nbsp;&nbsp; /*&nbsp;passing required connection handles 
      */<BR>&nbsp;&nbsp;&nbsp; /* f.ex., p_ora8CH-&gt;m_pOCIServer 
      */<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; ora7ConnectionHandles *p_ora7CH 
      =  (ora7ConnectionHandles 
      *)con.NativeHandles();</P>
      <P>&nbsp;&nbsp;&nbsp; /* call any o* function(s) 
      */<BR>&nbsp;&nbsp;&nbsp; /*&nbsp;passing required connection handles 
      */<BR>&nbsp;&nbsp;&nbsp; /* f.ex., p_ora7CH-&gt;m_lda 
      */<BR>  &nbsp;&nbsp;&nbsp; 
      ...</P>
      <P>   
      }</P>  </FONT>

			<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><STRONG>con.setOption(&quot;SQLDialect&quot;)</STRONG>=&quot;1&quot;;<BR>/* 
            All of the following commands associated with the connection will 
            use SQL Dialect 1<BR>  
               */</P>
      <P> SACommand cmd1(&amp;con, 
            &quot;Select task from test_tbl&quot;);</P>
      <P>  
               cmd1.Execute();</P>
      <P> SACommand cmd2(&amp;con, &quot;Update 
            test_tbl set task=3 where task=  
               8&quot;);</P>
      <P>  
               cmd2.Execute();</P>
      <P> /* assume t_field is a TIMESTAMP type field 
            (introduced in SQLDialect 3)<BR>*/<BR>SACommand cmd3(&amp;con, 
            &quot;Select t_field from test_tbl&quot;);</P>
      <P><STRONG></STRONG>/* You 
            have to change SQLDialect option to SQL Dialect 3 to execute this 
            command correctly<BR>*/<BR><STRONG>cmd3.setOption(&quot;SQLDialect&quot;)</STRONG>= 
 
     &quot;3&quot;;</P>
      <P>cmd3.Execute(); // no error</P>
			<FONT face=Courier><FONT face=Courier>
			<P>
			cmd2.setCommandText(&quot;Delete from 
            test_tbl where task=0&quot;);<BR>/* cmd2 still use SQL Dialect 1 
            
			*/
			</P>
			<P>
			// See also <A 
            href="Command_Examples.html#Option">SACommand::Option 
            examples</A>
			
			</P></FONT>
			</FONT></FONT>
			</FONT>

	  <HR id=HR1>

			<h3>&nbsp;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>
		</td>
	<tr></tr>
</table>
</body></html>

⌨️ 快捷键说明

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