📄 connection_examples.html
字号:
<P><FONT face=Courier>if(con.isConnected())</FONT></P>
<P><FONT face=Courier>
<STRONG>con.Disconnect();</STRONG>
</FONT></P>
<P><FONT face=Courier>/*<BR>Second example.<BR>Disconnect is made
implicitly in destructor.<BR>*/</FONT></P>
<P><FONT face=Courier>{</FONT></P>
<P><FONT face=Courier> 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("dbname", "username", "password",
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> case
SA_LevelUnknown:<BR> /*do smth.
specific for default
isolation*/<BR>
break;<BR> case
SA_ReadCommitted:<BR> /*do smth.
specific for Read
Committed*/<BR>
break;<BR> case
SA_ReadCommitted:<BR> /*do smth.
specific for Read
Committed*/<BR>
break;<BR> case
SA_RepeatableRead:<BR> /*do
smth. specific for Repeatable
Read*/<BR>
break;<BR> case
SA_Serializable:<BR> /*do smth.
specific for Serializable*/<BR>
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("dbname", "username", "password",
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("dbname", "username", "password",
SA_Oracle_Client);</P>
<P>
...</P>
<P>switch(<STRONG>con.AutoCommit()</STRONG>)<BR>{<BR>
case SA_AutoCommitUnknown:<BR>
printf("Autocommit mode is unknown
(default)");<BR> break;<BR>
case SA_AutoCommitOff:<BR>
printf("Autocommit mode is
off");<BR> break;<BR>
case SA_AutoCommitOn:<BR>
printf("Autocommit mode is
on");<BR> 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("dbname", "username", "password",
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("dbname", "username", "password",
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 <ora7API.h><BR>#include <oraAPI.h></P> </FONT>
<P><FONT face=Courier>SAConnection con;</FONT></P>
<P>con.Connect("dbname", "username", "password",
SA_Oracle_Client);</P>
<P>if(con.ClientVersion() >= 0x0008000) /* OCI 8.x
*/<BR>
{</P>
<P> ora8API *p_ora8API = (ora8API
*)<STRONG>con.NativeAPI()</STRONG>
;</P>
<P> /* call any OCI* function(s)
*/<BR> /* f.ex., p_ora8API->OCIStmtExecute(...)
*/<BR>
...</P>
<P>}<BR>else /* OCI 7.x */<BR>
{</P>
<P> ora7API *p_ora7API = (ora7API
*)<STRONG>con.NativeAPI()</STRONG>
;</P>
<P> /* call any o* function(s)
*/<BR> /* f.ex., p_ora7API->oparse(...)
*/<BR>
...</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 <ora7API.h><BR>#include <oraAPI.h></P>
<P>SAConnection con;</FONT></P>
<P>con.Connect("dbname", "username", "password",
SA_Oracle_Client);</P>
<P>if(con.ClientVersion() >= 0x0008000) /* OCI 8.x
*/<BR>
{</P>
<P> ora8API *p_ora8API = (ora8API
*)con.NativeAPI();</P>
<P> ora8ConnectionHandles *p_ora8CH
= (ora8ConnectionHandles
*)con.NativeHandles();</P>
<P> /* call any OCI* function(s)
*/<BR> /* passing required connection handles
*/<BR> /* f.ex., p_ora8CH->m_pOCIServer
*/<BR>
...</P>
<P>}<BR>else /* OCI 7.x */<BR>
{</P>
<P> ora7API *p_ora7API = (ora7API
*)con.NativeAPI();</P>
<P> ora7ConnectionHandles *p_ora7CH
= (ora7ConnectionHandles
*)con.NativeHandles();</P>
<P> /* call any o* function(s)
*/<BR> /* passing required connection handles
*/<BR> /* f.ex., p_ora7CH->m_lda
*/<BR>
...</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("dbname", "username", "password", SA_InterBase_Client);</P>
<P><STRONG>con.setOption("SQLDialect")</STRONG>="1";<BR>/*
All of the following commands associated with the connection will
use SQL Dialect 1<BR>
*/</P>
<P> SACommand cmd1(&con,
"Select task from test_tbl");</P>
<P>
cmd1.Execute();</P>
<P> SACommand cmd2(&con, "Update
test_tbl set task=3 where task=
8");</P>
<P>
cmd2.Execute();</P>
<P> /* assume t_field is a TIMESTAMP type field
(introduced in SQLDialect 3)<BR>*/<BR>SACommand cmd3(&con,
"Select t_field from test_tbl");</P>
<P><STRONG></STRONG>/* You
have to change SQLDialect option to SQL Dialect 3 to execute this
command correctly<BR>*/<BR><STRONG>cmd3.setOption("SQLDialect")</STRONG>=
"3";</P>
<P>cmd3.Execute(); // no error</P>
<FONT face=Courier><FONT face=Courier>
<P>
cmd2.setCommandText("Delete from
test_tbl where task=0");<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> 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 + -