ex7_8c-example.html

来自「一个很好用的Linux/Unix下Oracle OCI开发接口封装库」· HTML 代码 · 共 86 行

HTML
86
字号
<!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> &nbsp; <a class="qindex" href="modules.html">Modules</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="globals.html">Globals</a> &nbsp; <a class="qindex" href="pages.html">Related Pages</a> &nbsp; <a class="qindex" href="examples.html">Examples</a> &nbsp; </center>
<hr><h1>ex7.c</h1> Example for using sqlo_fetch, sqlo_values, sqlo_ocol_name_lens, sqlo_ocol_names, sqlo_value_lens.
<p>
<div class="fragment"><pre><span class="comment">/* $Id: ex7_8c-example.html,v 1.1 2005/01/13 02:56:43 cvsroot Exp $ */</span>
<span class="preprocessor">#include &lt;stdio.h&gt;</span>
<span class="preprocessor">#include &lt;stdlib.h&gt;</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 name="a0"></a><a class="code" href="group__easy.html#a9">sqlo_ocol_names</a>(sth, &amp;nc);

  <span class="comment">/* get the output column name lengths */</span>
  nl = <a name="a1"></a><a class="code" href="group__easy.html#a10">sqlo_ocol_name_lens</a>(sth, NULL);

  printf(<span class="stringliteral">"Employees with SAL &gt; %-8.2f:\n"</span>, min_income);

  <span class="comment">/* print the header */</span>
  <span class="keywordflow">for</span> (i = 0; i &lt; 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 &lt; nc; ++i) {
    <span class="keywordflow">for</span> (j = 0; j &lt; 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 name="a2"></a><a class="code" href="group__easy.html#a6">sqlo_fetch</a>(sth, 1)))) {
    
    <span class="comment">/* get one record */</span>
    v = <a name="a3"></a><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 name="a4"></a><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 &lt; nc; ++i)
      printf(<span class="stringliteral">"%-*s "</span>, (vl[i] &gt; nl[i] ? vl[i] : nl[i]), v[i]);

    printf(<span class="stringliteral">"\n"</span>);

  }

  <span class="keywordflow">if</span> (0 &gt; 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 name="a5"></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: ex7_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 + -
显示快捷键?