📄 command_examples.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 - Online Documentation - SACommand Examples</title>
</head>
<body bgcolor="#ffffff" BACKGROUND="../images/bg.gif" text="#000000"><!--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>
<td width="70" bgcolor="#000094" 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="GlbActive"-->
<td width="70" bgcolor="#00bb00" 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>
<p> </p>
<table width="100%">
<tr>
<td valign="top" width="165"><!--LeftMenu-->
<table frame="void" CELLSPACING="5" width="165">
<tr><td><p> </p></td>
</tr>
<tr>
<td><img align="middle" src="../images/red.gif" WIDTH="12" HEIGHT="12"><A href="Command.html" style="TEXT-DECORATION: none">
<font color="white" size="2" face="sans-serif">
SACommand</A> </FONT> </td>
</tr>
<tr>
<td><img align="middle" src="../images/green.gif" WIDTH="12" HEIGHT="12"><A href="Connection.html" style="TEXT-DECORATION: none">
<font color="white" size="2" face="sans-serif">
SAConnection</A> </FONT> </td>
</tr>
<tr>
<td><img align="middle" src="../images/green.gif" WIDTH="12" HEIGHT="12"><A href="Exception.html" style="TEXT-DECORATION: none">
<font color="white" size="2" face="sans-serif">
SAException</font></A> </td>
</tr>
<tr>
<td><img align="middle" src="../images/green.gif" WIDTH="12" HEIGHT="12"><A href="Field.html" style="TEXT-DECORATION: none">
<font color="white" size="2" face="sans-serif">
SAField</A> </FONT> </td>
</tr>
<tr>
<td><img align="middle" src="../images/green.gif" WIDTH="12" HEIGHT="12"><A href="Param.html" style="TEXT-DECORATION: none">
<font color="white" size="2" face="sans-serif">
SAParam</A> </FONT> </td>
</tr>
<tr><td><hr></td></tr>
<tr>
<td><img align=middle src="../images/green.gif" WIDTH="12" HEIGHT="12">
<A href="String.html" style ="TEXT-DECORATION: none" >
<font color=white size=2 face=sans-serif>
SAString</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>
SADateTime</A> </FONT> </td>
</tr>
<tr>
<td><img align=middle src="../images/green.gif" WIDTH="12" HEIGHT="12">
<A href="Numeric.html" style ="TEXT-DECORATION: none" >
<font color=white size=2 face=sans-serif>
SANumeric</A> </FONT> </td>
</tr>
<tr><td><hr></td></tr>
<tr>
<td>
<A href="Enums.html" style ="TEXT-DECORATION: none" >
<font color=white size=2 face=sans-serif>
Enums and Typedefs</A> </FONT> </td>
</tr>
</table>
</td><!--empty column-->
<td width="20">
<p> </p>
</td><!--Content-->
<td valign="top" align="left">
<table width="100%" cellspacing="2" cellpadding="2">
<tr>
<td align="left"><A href="Command.html" style="TEXT-DECORATION: none"><h3>Class Members</h3></A>
</td>
<td align="left"><A href="Command_Usage.html" style="TEXT-DECORATION: none"><h3>Usage</h3></A>
</td>
</tr>
<tr>
<td colspan="2"><h1>SACommand
Examples</h1></td>
</tr>
</table>
<HR>
<A name=cnstr></A>
<H3>SACommand constructor</H3>
<FONT face=Courier>
<P>
/*<BR>
Example 1. Using
the default constructor.<BR>
*/</P>
<P>SAConnection con;</P>
<P>...</P>
<P><STRONG>SACommand
cmd;</STRONG></P>
<P>cmd.setConnection(&con);</P>
<P>cmd.setCommandText("Select * from
test_tbl");</P>
<P>...</P>
<P>/*<BR>Example 2. Using
more complex constructor.<BR>*/</P>
<P>SAConnection con;</P>
<P>...</P>
<P><STRONG>SACommand
cmd(&con, "Select * from
test_tbl");</STRONG></P>
</FONT>
<HR>
<A name=dstr></A>
<H3>SACommand destructor</H3>
<FONT face=Courier>
<P>
/*<BR>
Delete command
object<BR>
*/</P>
<P>SACommand *pCmd = new SACommand;</P>
<P>...</P>
<P><STRONG>delete
pCmd;</STRONG></P>
</FONT>
<HR>
<A name=Connection></A>
<H3>Connection</H3>
<FONT face=Courier>
<P>
/*<BR>
Return the
underlying connection and commit transaction.<BR>
Exception handling is omitted for simplicity.<BR>
*/</P>
<P>SACommand cmd;</P>
<P> ...</P>
<P>SAConnection *pCon =
<STRONG>cmd.Connection()</STRONG> ;</P>
<P>pCon->Commit();</P>
</FONT>
<HR>
<A name=setConnection></A>
<H3>setConnection</H3>
<FONT face=Courier>
<P>
/*<BR>
Associate command
and connection.<BR>
Exception handling is
omitted for simplicity.<BR>
*/</P>
<P>SAConnection con;</P>
<P>con.Connect("dbname",
"username", "password", SA_Oracle_Client);</P>
<P> SACommand cmd;</P>
<P><STRONG>cmd.setConnection(&con);</STRONG></P>
</FONT>
<HR>
<A name=Open></A>
<H3>Open</H3>
<FONT face=Courier>
<P>
/*<BR>
Explicitly open
command.<BR>
Exception handling is omitted for
simplicity.<BR>
*/</P>
<P>SAConnection con;</P>
<P>con.Connect("dbname",
"username", "password", SA_Oracle_Client);</P>
<P> SACommand cmd(&con);</P>
<P><STRONG>cmd.Open();</STRONG></P>
</FONT>
<HR>
<A name=isOpened></A>
<H3>isOpened</H3>
<FONT face=Courier>
<P>
/*<BR>
Close the command
if it is opened.<BR>
Exception handling is
omitted for simplicity.<BR>
*/</P>
<P>SAConnection con;</P>
<P>SACommand cmd(&con);</P>
<P> ...</P>
<P>if(<STRONG>cmd.isOpened()</STRONG> )</P>
<P><STRONG>
</STRONG>cmd.Close();</P>
</FONT>
<HR>
<A name=Close></A>
<H3>Close</H3>
<FONT face=Courier>
<P>
<FONT face=Courier>
/*<BR>
Close the command if it is
opened.<BR>
Exception handling is omitted for
simplicity.<BR>
*/</P>
<P>SAConnection con;</P>
<P>SACommand cmd(&con);</P>
<P> ...</P>
<P> if(cmd.isOpened())</P>
<P><STRONG> cmd.Close();</STRONG></P>
</FONT></FONT>
<HR>
<A name=setCommandText></A>
<H3>setCommandText</H3>
<FONT face=Courier>
<P>
/*<BR>
Exception
handling is omitted for simplicity.<BR>
*/</P>
<P>SAConnection con;</P>
<P>...</P>
<P>SACommand cmd(&con);</P>
<P><STRONG>cmd.setCommandText("Select * from
test_tbl");</STRONG></P>
<P>cmd.Execute();</P>
<P>...</P>
</FONT>
<HR>
<A name=CommandText></A>
<H3>CommandText</H3>
<FONT face=Courier>
<P>
/*<BR>
Queries current
command text.<BR>
*/</P>
<P>SAConnection con;</P>
<P>SACommand cmd(&con);</P>
<P> ...</P>
<P>SAString sCmd =
<STRONG>cmd.CommandText()</STRONG> ;</P>
</FONT>
<HR>
<A name=CommandType></A>
<H3>CommandType</H3>
<FONT face=Courier>
<FONT face=Courier>
<P>
/*<BR>
Queries current
command type.<BR>
*/</P>
<P>SAConnection con;</P>
<P>SACommand cmd(&con, "Select * from
test_tbl");</P>
<P>if(cmd.CommandType() != SA_CmdSQLStmt)</P>
<P> printf("Very
strange!\n");</P>
</FONT>
</FONT>
<HR>
<A name=Prepare></A>
<H3>Prepare</H3>
<FONT face=Courier>
<P>
/*<BR>
Explicitly
prepare a command.<BR>
Exception handling is
omitted for simplicity.<BR>
*/</P>
<P>SAConnection con;</P>
<P>con.Connect("dbname",
"username", "password", SA_Oracle_Client);</P>
<P>SACommand cmd(&con, "Select * from
test_tbl");</P>
<P><STRONG>cmd.Prepare();</STRONG></P>
<P>...</P>
</FONT>
<HR>
<A name=Execute></A>
<H3>Execute</H3>
<FONT face=Courier>
<P>
<FONT face=Courier>
/*<BR>
Execute a command.<BR>
Exception handling is omitted for simplicity.<BR>
*/</P>
<P>SAConnection con;</P>
<P>con.Connect("dbname",
"username", "password", SA_Oracle_Client);</P>
<P>SACommand cmd(&con, "Select * from
test_tbl");</P>
<P><STRONG>cmd.Execute();</STRONG></P>
<P>...</P>
</FONT></FONT>
<HR>
<A name=isResultSet></A>
<H3>isResultSet</H3>
<FONT face=Courier>
<P>
/*<BR>
Check whether
executed command have a result set pending (even empty).<BR>
Exception handling is omitted for
simplicity.<BR>
*/</P>
<P>SAConnection con;</P>
<P>con.Connect("dbname",
"username", "password", SA_Oracle_Client);</P>
<P>SACommand cmd(&con, "Select * from
test_tbl");</P>
<P>cmd.Execute();</P>
<P>if(<STRONG>cmd.isResultSet()</STRONG>)<BR>{<BR> /* Fetch result set
here*/<BR> ...<BR>}<BR>else<BR> printf("Very strange!\n");</P>
</FONT>
<HR>
<A name=RowsAffected></A>
<H3>RowsAffected</H3>
<FONT face=Courier>
<P>
/*<BR>
Queries number of
rows affected by the last operation.<BR>
Exception handling is omitted for simplicity.<BR>
*/</P>
<P>SAConnection con;</P>
<P>con.Connect("dbname",
"username", "password", SA_Oracle_Client);</P>
<P>SACommand cmd(&con, "Delete * from
test_tbl");</P>
<P> cmd.Execute();</P>
<P>printf("Rows deleted: %d\n",
cmd.RowsAffected());</P>
</FONT>
<HR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -