ex19_8c-example.html
来自「一个很好用的Linux/Unix下Oracle OCI开发接口封装库」· HTML 代码 · 共 100 行
HTML
100 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Example Documentation</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.2.18 -->
<center>
<a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="modules.html">Modules</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="globals.html">Globals</a> <a class="qindex" href="pages.html">Related Pages</a> <a class="qindex" href="examples.html">Examples</a> </center>
<hr><h1>ex19.c</h1> Example for selecting from a nested table.
<p>
<div class="fragment"><pre><span class="comment">/* $Id: ex19_8c-example.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> select_ntable(<a class="code" href="group__typedefs.html#a0">sqlo_db_handle_t</a> dbh)
{
<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>;
<a class="code" href="group__typedefs.html#a1">sqlo_stmt_handle_t</a> st2h; <span class="comment">/* handle of the ref cursor */</span>
<span class="keywordtype">int</span> status;
<span class="keywordtype">char</span> ename[11];
<span class="keywordtype">char</span> dname[15];
<span class="keywordtype">char</span> loc[14];
<span class="keywordtype">short</span> eind, dind, lind;
<span class="keywordtype">int</span> deptno = 10;
<span class="comment">/* don't know why the bind variable for deptno causes a crash */</span>
CONST <span class="keywordtype">char</span> * stmt =
<span class="stringliteral">"SELECT ENAME, CURSOR(SELECT DNAME, LOC FROM DEPT)\n"</span>
<span class="stringliteral">" FROM EMP WHERE DEPTNO = :deptno"</span>;
<span class="comment">/* parse the statement */</span>
<span class="keywordflow">if</span> ( 0 <= (sth = <a name="a0"></a><a class="code" href="group__complex.html#a0">sqlo_prepare</a>(dbh, stmt))) {
<span class="comment">/* bind all variables */</span>
<span class="keywordflow">if</span> (<a class="code" href="group__constants.html#a3a25">SQLO_SUCCESS</a> !=
(<a name="a1"></a><a class="code" href="group__complex.html#a1">sqlo_bind_by_name</a>(sth, <span class="stringliteral">":deptno"</span>, <a class="code" href="group__constants.html#a6a56">SQLOT_INT</a>, &deptno, <span class="keyword">sizeof</span>(deptno), 0, 0) ) ) {
error_exit(dbh, <span class="stringliteral">"sqlo_bind_by_name"</span>);
}
<span class="comment">/* Do the defines */</span>
<span class="comment">/* You could also do: sqlo_define_by_pos(sth, 2, SQLOT_RSET, &st2h, 0, 0, 0, 0) */</span>
<span class="keywordflow">if</span> (<a class="code" href="group__constants.html#a3a25">SQLO_SUCCESS</a> !=
( <a name="a2"></a><a class="code" href="group__complex.html#a5">sqlo_define_by_pos</a>(sth, 1, <a class="code" href="group__constants.html#a6a58">SQLOT_STR</a>, ename, <span class="keyword">sizeof</span>(ename), &eind, 0, 0) ) ||
( <a name="a3"></a><a class="code" href="group__complex.html#a7">sqlo_define_ntable</a>(sth, 2, &st2h)))
error_exit(dbh, <span class="stringliteral">"sqlo_define_ntable"</span>);
<span class="comment">/* execute the main statement */</span>
<span class="keywordflow">if</span> (<a class="code" href="group__constants.html#a3a25">SQLO_SUCCESS</a> != <a name="a4"></a><a class="code" href="group__complex.html#a8">sqlo_execute</a>(sth, 1))
error_exit(dbh, <span class="stringliteral">"sqlo_execute"</span>);
<span class="comment">/* fetch from the main statement */</span>
<span class="keywordflow">while</span> (<a class="code" href="group__constants.html#a3a25">SQLO_SUCCESS</a> == (status = <a name="a5"></a><a class="code" href="group__easy.html#a6">sqlo_fetch</a>(sth, 1))) {
printf(<span class="stringliteral">"ENAME=%11s\n"</span>, ename);
<span class="comment">/* define the output of the second cursor */</span>
<span class="keywordflow">if</span> (<a class="code" href="group__constants.html#a3a25">SQLO_SUCCESS</a> !=
( <a class="code" href="group__complex.html#a5">sqlo_define_by_pos</a>(st2h, 1, <a class="code" href="group__constants.html#a6a58">SQLOT_STR</a>, dname, <span class="keyword">sizeof</span>(dname), &dind, 0, 0) ) ||
( <a class="code" href="group__complex.html#a5">sqlo_define_by_pos</a>(st2h, 2, <a class="code" href="group__constants.html#a6a58">SQLOT_STR</a>, loc, <span class="keyword">sizeof</span>(loc), &lind, 0, 0) ) ) {
error_exit(dbh, <span class="stringliteral">"sqlo_define_by_pos"</span>);
}
<span class="comment">/* execute the cursor */</span>
<span class="keywordflow">if</span>(<a class="code" href="group__constants.html#a3a25">SQLO_SUCCESS</a> != <a class="code" href="group__complex.html#a8">sqlo_execute</a>(st2h, 1))
error_exit(dbh, <span class="stringliteral">"sqlo_execute"</span>);
<span class="comment">/* fetch from the second cursor */</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>(st2h, 1))) {
printf(<span class="stringliteral">" DNAME=%15s LOC=%15s\n"</span>, dname, loc);
}
<span class="keywordflow">if</span> (status != <a class="code" href="group__constants.html#a3a32">SQLO_NO_DATA</a>)
error_exit(dbh, <span class="stringliteral">"sqlo_fetch(st2)"</span>);
}
<span class="keywordflow">if</span> (<a class="code" href="group__constants.html#a3a25">SQLO_SUCCESS</a> != <a name="a6"></a><a class="code" href="group__easy.html#a13">sqlo_close</a>(sth))
error_exit(dbh, <span class="stringliteral">"sqlo_close(1)"</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>(st2h))
error_exit(dbh, <span class="stringliteral">"sqlo_close(2)"</span>);
} <span class="keywordflow">else</span> {
error_exit(dbh, <span class="stringliteral">"sqlo_prepare"</span>);
}
<span class="keywordflow">return</span> 1;
}
<span class="comment">/* $Id: ex19_8c-example.html,v 1.1 2005/01/13 02:56:43 cvsroot Exp $ */</span>
</pre></div><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 + -
显示快捷键?