group__easy.html
来自「一个很好用的Linux/Unix下Oracle OCI开发接口封装库」· HTML 代码 · 共 1,235 行 · 第 1/4 页
HTML
1,235 行
<a class="code" href="group__typedefs.html#a1">sqlo_stmt_handle_t</a> reopen_cursor(<a class="code" href="group__typedefs.html#a0">sqlo_db_handle_t</a> dbh, <span class="keywordtype">double</span> min_income)
{
<span class="keyword">static</span> <a class="code" href="group__typedefs.html#a1">sqlo_stmt_handle_t</a> sth = <a class="code" href="group__constants.html#a5a49">SQLO_STH_INIT</a>;
<span class="keywordtype">int</span> argc = 0;
<span class="keyword">const</span> <span class="keywordtype">char</span> * argv[1];
<span class="keywordtype">char</span> hlp[64];
sprintf(hlp, <span class="stringliteral">"%f"</span>, min_income);
argv[argc++] = hlp;
<span class="keywordflow">if</span> (<a class="code" href="group__constants.html#a5a49">SQLO_STH_INIT</a> == sth) {
<span class="comment">/* first time, open a new cursor */</span>
<span class="keywordflow">if</span> ( 0 > (<a class="code" href="group__easy.html#a4">sqlo_open2</a>(&sth, dbh,
<span class="stringliteral">"SELECT ENAME, SAL FROM EMP WHERE SAL >= :1"</span>,
argc, argv))) {
error_exit(dbh, <span class="stringliteral">"sqlo_open"</span>);
}
} <span class="keywordflow">else</span> {
<span class="comment">/* next time, bind again with new variables */</span>
<span class="keywordflow">if</span> ( 0 > <a class="code" href="group__easy.html#a5">sqlo_reopen</a>(sth, argc, argv))
error_exit(dbh, <span class="stringliteral">"sqlo_reopen"</span>);
}
<span class="keywordflow">return</span> sth;
}
<span class="comment">/* $Id: group__easy.html,v 1.1 2005/01/13 02:56:43 cvsroot Exp $ */</span>
</pre></div></dl><dl compact><dt><b>See also: </b></dt><dd>
<a class="el" href="group__easy.html#a4">sqlo_open2</a>, <a class="el" href="group__easy.html#a6">sqlo_fetch</a>, <a class="el" href="group__easy.html#a7">sqlo_values</a>, <a class="el" href="group__easy.html#a13">sqlo_close</a> </dl><dl compact><dt><b>Examples: </b></dt><dd>
<a class="el" href="ex6_8c-example.html#a1">ex6.c</a>.</dl> </td>
</tr>
</table>
<a name="a2" doxytag="sqlora.h::sqlo_run"></a><p>
<table width="100%" cellpadding="2" cellspacing="0" border="0">
<tr>
<td class="md">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> int sqlo_run </td>
<td class="md" valign="top">( </td>
<td class="md" nowrap valign="top"><a class="el" href="group__typedefs.html#a0">sqlo_db_handle_t</a> </td>
<td class="mdname" nowrap> <em>dbh</em>, </td>
</tr>
<tr>
<td></td>
<td></td>
<td class="md" nowrap>const char * </td>
<td class="mdname" nowrap> <em>stmt</em>, </td>
</tr>
<tr>
<td></td>
<td></td>
<td class="md" nowrap>int </td>
<td class="mdname" nowrap> <em>argc</em>, </td>
</tr>
<tr>
<td></td>
<td></td>
<td class="md" nowrap>const char ** </td>
<td class="mdname" nowrap> <em>argv</em></td>
</tr>
<tr>
<td></td>
<td class="md">) </td>
<td class="md" colspan="2"></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
Run a simple sql statements with parameters.
<p>
Like <a class="el" href="group__easy.html#a14">The easy interface</a>, but with bind parameters. This is basically the same as calling <a class="el" href="group__easy.html#a3">The easy interface</a> followed by <a class="el" href="group__easy.html#a6">The easy interface</a> and <a class="el" href="group__easy.html#a13">The easy interface</a>.<dl compact><dt><b>Parameters: </b></dt><dd>
<table border=0 cellspacing=2 cellpadding=0>
<tr><td valign=top><em>dbh</em> </td><td>
I - A database handle </td></tr>
<tr><td valign=top><em>stmt</em> </td><td>
I - A sql statement (non-query). </td></tr>
<tr><td valign=top><em>argc</em> </td><td>
I - Number of arguments in argv. </td></tr>
<tr><td valign=top><em>argv</em> </td><td>
I - The arguments</td></tr>
</table>
</dl><dl compact><dt><b>Returns: </b></dt><dd>
<ul>
<li>The number of processed rows. <li>SQLO_STILL_EXECUTING in non-blocking mode. <li> < 0 on error. </ul>
</dl><dl compact><dt><b>Example:</b></dt><dd>
<div class="fragment"><pre><span class="comment">/* $Id: group__easy.html,v 1.1 2005/01/13 02:56:43 cvsroot Exp $ */</span>
<span class="preprocessor">#include <stdio.h></span>
<span class="preprocessor">#include <stdlib.h></span>
<span class="preprocessor">#include "examples.h"</span>
<span class="keywordtype">int</span> update_manager(<a class="code" href="group__typedefs.html#a0">sqlo_db_handle_t</a> dbh)
{
<span class="keyword">const</span> <span class="keywordtype">char</span> * argv[2];
<span class="keywordtype">int</span> stat;
argv[0] = <span class="stringliteral">"0.5"</span>;
argv[1] = <span class="stringliteral">"MANAGER"</span>;
stat = <a class="code" href="group__easy.html#a2">sqlo_run</a>(dbh, <span class="stringliteral">"UPDATE EMP SET SAL = SAL * :1 WHERE JOB = :2"</span>,
2, argv);
<span class="keywordflow">if</span> (0 > stat) {
error_exit(dbh, <span class="stringliteral">"sqlo_run"</span>);
}
<span class="keywordflow">return</span> stat;
}
<span class="comment">/* $Id: group__easy.html,v 1.1 2005/01/13 02:56:43 cvsroot Exp $ */</span>
</pre></div> </dl><dl compact><dt><b>Examples: </b></dt><dd>
<a class="el" href="ex3_8c-example.html#a0">ex3.c</a>.</dl> </td>
</tr>
</table>
<a name="a8" doxytag="sqlora.h::sqlo_value_lens"></a><p>
<table width="100%" cellpadding="2" cellspacing="0" border="0">
<tr>
<td class="md">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> const unsigned short* sqlo_value_lens </td>
<td class="md" valign="top">( </td>
<td class="md" nowrap valign="top"><a class="el" href="group__typedefs.html#a1">sqlo_stmt_handle_t</a> </td>
<td class="mdname" nowrap> <em>sth</em>, </td>
</tr>
<tr>
<td></td>
<td></td>
<td class="md" nowrap>int * </td>
<td class="mdname" nowrap> <em>num</em></td>
</tr>
<tr>
<td></td>
<td class="md">) </td>
<td class="md" colspan="2"></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
Get the length of the returned values.
<p>
Returns the length in number of characters (bytes for non-unicode chars) for a dataset fetched by sqlo_fetch.<dl compact><dt><b>Parameters: </b></dt><dd>
<table border=0 cellspacing=2 cellpadding=0>
<tr><td valign=top><em>sth</em> </td><td>
I - A statement handle </td></tr>
<tr><td valign=top><em>num</em> </td><td>
O - A destination where the function can write the size of the returned array (optional).</td></tr>
</table>
</dl><dl compact><dt><b>Returns: </b></dt><dd>
A pointer to an array of unsigned shorts containing the lengths</dl><dl compact><dt><b>See also: </b></dt><dd>
<a class="el" href="group__easy.html#a6">sqlo_fetch</a>, <a class="el" href="group__easy.html#a7">sqlo_values</a>, <a class="el" href="group__easy.html#a4">sqlo_open2</a>, <a class="el" href="group__easy.html#a13">sqlo_close</a>. </dl><dl compact><dt><b>Examples: </b></dt><dd>
<a class="el" href="ex7_8c-example.html#a4">ex7.c</a>.</dl> </td>
</tr>
</table>
<a name="a7" doxytag="sqlora.h::sqlo_values"></a><p>
<table width="100%" cellpadding="2" cellspacing="0" border="0">
<tr>
<td class="md">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> const char** sqlo_values </td>
<td class="md" valign="top">( </td>
<td class="md" nowrap valign="top"><a class="el" href="group__typedefs.html#a1">sqlo_stmt_handle_t</a> </td>
<td class="mdname" nowrap> <em>sth</em>, </td>
</tr>
<tr>
<td></td>
<td></td>
<td class="md" nowrap>int * </td>
<td class="mdname" nowrap> <em>num</em>, </td>
</tr>
<tr>
<td></td>
<td></td>
<td class="md" nowrap>int </td>
<td class="mdname" nowrap> <em>dostrip</em></td>
</tr>
<tr>
<td></td>
<td class="md">) </td>
<td class="md" colspan="2"></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
Get one dataset.
<p>
Returns the data for one set of data fetched via <a class="el" href="group__easy.html#a6">The easy interface</a>.<dl compact><dt><b>Parameters: </b></dt><dd>
<table border=0 cellspacing=2 cellpadding=0>
<tr><td valign=top><em>sth</em> </td><td>
I - A statement handle </td></tr>
<tr><td valign=top><em>num</em> </td><td>
O - A destination where the function could write the size of the returned array (optional) </td></tr>
<tr><td valign=top><em>dostrip</em> </td><td>
I - A flag indicating whether trailing blanks should be stripped off (leading blanks in case of numbers).</td></tr>
</table>
</dl><dl compact><dt><b>Returns: </b></dt><dd>
A pointer to an array of strings containing the data values</dl><dl compact><dt><b>Example:</b></dt><dd>
<div class="fragment"><pre><span class="comment">/* $Id: group__easy.html,v 1.1 2005/01/13 02:56:43 cvsroot Exp $ */</span>
<span class="preprocessor">#include <stdio.h></span>
<span class="preprocessor">#include <stdlib.h></span>
<span class="preprocessor">#include "examples.h"</span>
<span class="keywordtype">int</span> do_select(<a class="code" href="group__typedefs.html#a0">sqlo_db_handle_t</a> dbh, <span class="keywordtype">double</span> min_income)
{
<a class="code" href="group__typedefs.html#a1">sqlo_stmt_handle_t</a> sth; <span class="comment">/* statement handle */</span>
<span class="keywordtype">int</span> status; <span class="comment">/* status of sqlo calls */</span>
<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i,j; <span class="comment">/* loop counter */</span>
<span class="keyword">const</span> <span class="keywordtype">char</span> ** v; <span class="comment">/* values */</span>
<span class="keyword">const</span> <span class="keywordtype">char</span> ** n; <span class="comment">/* column names */</span>
CONST <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> *nl; <span class="comment">/* column name lengths */</span>
CONST <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> *vl; <span class="comment">/* value lengths */</span>
<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> nc; <span class="comment">/* number of columns */</span>
sth = reopen_cursor(dbh, min_income); <span class="comment">/* see example of sqlo_reopen (ex6.c) */</span>
<span class="comment">/* get the output column names */</span>
n = <a class="code" href="group__easy.html#a9">sqlo_ocol_names</a>(sth, &nc);
<span class="comment">/* get the output column name lengths */</span>
nl = <a class="code" href="group__easy.html#a10">sqlo_ocol_name_lens</a>(sth, NULL);
printf(<span class="stringliteral">"Employees with SAL > %-8.2f:\n"</span>, min_income);
<span class="comment">/* print the header */</span>
<span class="keywordflow">for</span> (i = 0; i < nc; ++i)
printf(<span class="stringliteral">"%-*s "</span>, nl[i], n[i]);
printf(<span class="stringliteral">"\n"</span>);
<span class="keywordflow">for</span> (i = 0; i < nc; ++i) {
<span class="keywordflow">for</span> (j = 0; j < nl[i]; ++j) {
putchar(<span class="charliteral">'-'</span>);
}
putchar(<span class="charliteral">'+'</span>);
}
putchar(<span class="charliteral">'\n'</span>);
<span class="comment">/* fetch the data */</span>
<span class="keywordflow">while</span> ( <a class="code" href="group__constants.html#a3a25">SQLO_SUCCESS</a> == (status = (<a class="code" href="group__easy.html#a6">sqlo_fetch</a>(sth, 1)))) {
<span class="comment">/* get one record */</span>
v = <a class="code" href="group__easy.html#a7">sqlo_values</a>(sth, NULL, 1);
<span class="comment">/* get the length of the data items */</span>
vl = <a class="code" href="group__easy.html#a8">sqlo_value_lens</a>(sth, NULL);
<span class="comment">/* print the column values */</span>
<span class="keywordflow">for</span> (i = 0; i < nc; ++i)
printf(<span class="stringliteral">"%-*s "</span>, (vl[i] > nl[i] ? vl[i] : nl[i]), v[i]);
printf(<span class="stringliteral">"\n"</span>);
}
<span class="keywordflow">if</span> (0 > status) {
error_exit(dbh, <span class="stringliteral">"sqlo_fetch"</span>);
}
<span class="keywordflow">if</span> ( <a class="code" href="group__constants.html#a3a25">SQLO_SUCCESS</a> != <a class="code" href="group__easy.html#a13">sqlo_close</a>(sth))
error_exit(dbh, <span class="stringliteral">"sqlo_close"</span>);
<span class="keywordflow">return</span> 1;
}
<span class="comment">/* $Id: group__easy.html,v 1.1 2005/01/13 02:56:43 cvsroot Exp $ */</span>
</pre></div></dl><dl compact><dt><b>See also: </b></dt><dd>
<a class="el" href="group__easy.html#a6">sqlo_fetch</a>, <a class="el" href="group__easy.html#a8">sqlo_value_lens</a>, <a class="el" href="group__easy.html#a3">sqlo_open</a>, <a class="el" href="group__easy.html#a13">sqlo_close</a>. </dl><dl compact><dt><b>Examples: </b></dt><dd>
<a class="el" href="ex17_8c-example.html#a5">ex17.c</a>, and <a class="el" href="ex7_8c-example.html#a3">ex7.c</a>.</dl> </td>
</tr>
</table>
<hr><address style="align: right;"><small>Generated on Thu Aug 14 18:02:53 2003 for libsqlora8 by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0
width=110 height=53></a>1.2.18 </small></address>
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?