group__complex.html

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

HTML
1,170
字号
<!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>The advanced interface.</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>The advanced interface.</h1>This functions offer more flexibility in terms of datatypes, but they need (much) more parameters. 
<a href="#_details">More...</a><table border=0 cellpadding=0 cellspacing=0>
<tr><td></td></tr>
<tr><td colspan=2><br><h2>Functions</h2></td></tr>
<tr><td nowrap align=right valign=top>int&nbsp;</td><td valign=bottom><a class="el" href="group__complex.html#a0">sqlo_prepare</a> (<a class="el" href="group__typedefs.html#a0">sqlo_db_handle_t</a> dbh, const char *stmt)</td></tr>
<tr><td>&nbsp;</td><td><font size=-1><em>Parse a statement.</em> <a href="#a0"></a><em></em></font><br><br></td></tr>
<tr><td nowrap align=right valign=top>int&nbsp;</td><td valign=bottom><a class="el" href="group__complex.html#a1">sqlo_bind_by_name</a> (<a class="el" href="group__typedefs.html#a1">sqlo_stmt_handle_t</a> sth, const char *name, int param_type, const void *param_addr, unsigned int param_size, short *ind_addr, int is_array)</td></tr>
<tr><td>&nbsp;</td><td><font size=-1><em>Bind a variable by name.</em> <a href="#a1"></a><em></em></font><br><br></td></tr>
<tr><td nowrap align=right valign=top>int&nbsp;</td><td valign=bottom><a class="el" href="group__complex.html#a2">sqlo_bind_ref_cursor</a> (<a class="el" href="group__typedefs.html#a1">sqlo_stmt_handle_t</a> sth, const char *cursor_name, int *sth2p)</td></tr>
<tr><td>&nbsp;</td><td><font size=-1><em>Bind a REF CURSOR.</em> <a href="#a2"></a><em></em></font><br><br></td></tr>
<tr><td nowrap align=right valign=top>int&nbsp;</td><td valign=bottom><a class="el" href="group__complex.html#a3">sqlo_bind_by_pos</a> (<a class="el" href="group__typedefs.html#a1">sqlo_stmt_handle_t</a> sth, int position, int param_type, const void *param_addr, unsigned int param_size, short *ind_addr, int is_array)</td></tr>
<tr><td>&nbsp;</td><td><font size=-1><em>Bind a variable by position.</em> <a href="#a3"></a><em></em></font><br><br></td></tr>
<tr><td nowrap align=right valign=top>int&nbsp;</td><td valign=bottom><a class="el" href="group__complex.html#a4">sqlo_bind_by_pos2</a> (<a class="el" href="group__typedefs.html#a1">sqlo_stmt_handle_t</a> sth, int position, int param_type, const void *param_addr, unsigned int param_size, short *ind_addr, unsigned short *rcode_addr, unsigned int skip_size)</td></tr>
<tr><td>&nbsp;</td><td><font size=-1><em>Bind a variable by position.</em> <a href="#a4"></a><em></em></font><br><br></td></tr>
<tr><td nowrap align=right valign=top>int&nbsp;</td><td valign=bottom><a class="el" href="group__complex.html#a5">sqlo_define_by_pos</a> (<a class="el" href="group__typedefs.html#a1">sqlo_stmt_handle_t</a> sth, int value_pos, int value_type, const void *value_addr, unsigned int value_size, short *ind_addr, short *rlen_addr, int is_array)</td></tr>
<tr><td>&nbsp;</td><td><font size=-1><em>Define a output variable of the select list.</em> <a href="#a5"></a><em></em></font><br><br></td></tr>
<tr><td nowrap align=right valign=top>int&nbsp;</td><td valign=bottom><a class="el" href="group__complex.html#a6">sqlo_define_by_pos2</a> (<a class="el" href="group__typedefs.html#a1">sqlo_stmt_handle_t</a> sth, int value_pos, int value_type, const void *value_addr, unsigned int value_size, short *ind_addr, unsigned short *rlen_addr, unsigned short *rcode_addr, unsigned int skip_size)</td></tr>
<tr><td>&nbsp;</td><td><font size=-1><em>Define a output variable of the select list.</em> <a href="#a6"></a><em></em></font><br><br></td></tr>
<tr><td nowrap align=right valign=top>int&nbsp;</td><td valign=bottom><a class="el" href="group__complex.html#a7">sqlo_define_ntable</a> (<a class="el" href="group__typedefs.html#a1">sqlo_stmt_handle_t</a> sth, unsigned int pos, int *sth2p)</td></tr>
<tr><td>&nbsp;</td><td><font size=-1><em>Define a nested table Please visit the example for details.</em> <a href="#a7"></a><em></em></font><br><br></td></tr>
<tr><td nowrap align=right valign=top>int&nbsp;</td><td valign=bottom><a class="el" href="group__complex.html#a8">sqlo_execute</a> (<a class="el" href="group__typedefs.html#a1">sqlo_stmt_handle_t</a> sth, unsigned int iterations)</td></tr>
<tr><td>&nbsp;</td><td><font size=-1><em>Execute a statement.</em> <a href="#a8"></a><em></em></font><br><br></td></tr>
</table>
<hr><a name="_details"></a><h2>Detailed Description</h2>
This functions offer more flexibility in terms of datatypes, but they need (much) more parameters.
<p>
Use these functions if you want to execute PL/SQL or stored procedures. <hr><h2>Function Documentation</h2>
<a name="a1" doxytag="sqlora.h::sqlo_bind_by_name"></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_bind_by_name </td>
          <td class="md" valign="top">(&nbsp;</td>
          <td class="md" nowrap valign="top"><a class="el" href="group__typedefs.html#a1">sqlo_stmt_handle_t</a>&nbsp;</td>
          <td class="mdname" nowrap>&nbsp; <em>sth</em>, </td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td class="md" nowrap>const char *&nbsp;</td>
          <td class="mdname" nowrap>&nbsp; <em>name</em>, </td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td class="md" nowrap>int&nbsp;</td>
          <td class="mdname" nowrap>&nbsp; <em>param_type</em>, </td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td class="md" nowrap>const void *&nbsp;</td>
          <td class="mdname" nowrap>&nbsp; <em>param_addr</em>, </td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td class="md" nowrap>unsigned int&nbsp;</td>
          <td class="mdname" nowrap>&nbsp; <em>param_size</em>, </td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td class="md" nowrap>short *&nbsp;</td>
          <td class="mdname" nowrap>&nbsp; <em>ind_addr</em>, </td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td class="md" nowrap>int&nbsp;</td>
          <td class="mdname" nowrap>&nbsp; <em>is_array</em></td>
        </tr>
        <tr>
          <td></td>
          <td class="md">)&nbsp;</td>
          <td class="md" colspan="2"></td>
        </tr>

      </table>
    </td>
  </tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
Bind a variable by name.
<p>
Use this to bind a variable in a query or a stored procedure call.
<p>
If is_array is 1, the parameters param_addr and ind_addr must point to arrays. ind_addr is optional and can be passed a NULL. The param_size is still the size of one array element, not the whole array size!<dl compact><dt><b>Parameters: </b></dt><dd>
<table border=0 cellspacing=2 cellpadding=0>
<tr><td valign=top><em>sth</em>&nbsp;</td><td>
I - The statement handle. </td></tr>
<tr><td valign=top><em>name</em>&nbsp;</td><td>
I - The bind parameter name. </td></tr>
<tr><td valign=top><em>param_type</em>&nbsp;</td><td>
I - The datatype of the bind parameter (see <a class="el" href="group__constants.html#a6">Constants</a>). </td></tr>
<tr><td valign=top><em>param_addr</em>&nbsp;</td><td>
I - The address of a variable or array. </td></tr>
<tr><td valign=top><em>param_size</em>&nbsp;</td><td>
I - The size of the object at param_addr in bytes. </td></tr>
<tr><td valign=top><em>ind_addr</em>&nbsp;</td><td>
I - The pointer to the NULL indicator variable (optional). </td></tr>
<tr><td valign=top><em>is_array</em>&nbsp;</td><td>
I - 1 means param_addr points to an array, 0 means a single variable.</td></tr>
</table>
</dl><dl compact><dt><b>Returns: </b></dt><dd>
<ul>
<li>SQLO_SUCCESS <li> &lt; 0 on error </ul>
</dl><dl compact><dt><b>Example:</b></dt><dd>
  <div class="fragment"><pre><span class="comment">/* $Id: group__complex.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="keyword">static</span> <span class="keywordtype">void</span> create_sp __P((<a class="code" href="group__typedefs.html#a0">sqlo_db_handle_t</a> dbh));

<span class="keywordtype">int</span> call_plsql(<a class="code" href="group__typedefs.html#a0">sqlo_db_handle_t</a> dbh)
{
  <span class="keywordtype">double</span> ip1;
  <span class="keywordtype">int</span>  ip2;
  <span class="keywordtype">char</span> op[80];
  <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="comment">/* the stored procecdure call */</span>
  <span class="keywordtype">char</span> * stmt = 
    <span class="stringliteral">"BEGIN\n"</span>
    <span class="stringliteral">"    EX9(:ip1, :ip2, :op);\n"</span>
    <span class="stringliteral">"END;\n"</span>;


  create_sp(dbh);               <span class="comment">/* create the test stored procedure */</span>

  ip1 = 1.5;
  ip2 = 20;


  <span class="comment">/* parse the statement */</span>
  <span class="keywordflow">if</span> ( 0 &lt;= (sth = <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 class="code" href="group__complex.html#a1">sqlo_bind_by_name</a>(sth, <span class="stringliteral">":ip1"</span>, <a class="code" href="group__constants.html#a6a57">SQLOT_FLT</a>, &amp;ip1, <span class="keyword">sizeof</span>(ip1), 0, 0) ||
         <a class="code" href="group__complex.html#a1">sqlo_bind_by_name</a>(sth, <span class="stringliteral">":ip2"</span>, <a class="code" href="group__constants.html#a6a56">SQLOT_INT</a>, &amp;ip2, <span class="keyword">sizeof</span>(ip2), 0, 0) ||
         <a class="code" href="group__complex.html#a1">sqlo_bind_by_name</a>(sth, <span class="stringliteral">":op"</span>, <a class="code" href="group__constants.html#a6a58">SQLOT_STR</a>, &amp;op, <span class="keyword">sizeof</span>(op), 0, 0)
         )) {

      error_exit(dbh, <span class="stringliteral">"sqlo_bind_by_name"</span>);
    } <span class="keywordflow">else</span> {
      <span class="comment">/* execute the call */</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>(sth, 1))
        error_exit(dbh, <span class="stringliteral">"sqlo_execute"</span>);
    }

    <span class="comment">/* print the result */</span>
    <span class="keywordflow">if</span> (atof(op) != (ip1 + ip2))
      printf(<span class="stringliteral">"Stored procudure returned wrong result %s, expected %6.2f\n"</span>,
             op, (ip1 + ip2));

    <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_execute"</span>);

  } <span class="keywordflow">else</span> {
    error_exit(dbh, <span class="stringliteral">"sqlo_prepare"</span>);
  }

  <span class="keywordflow">if</span> ( 0 &gt; <a class="code" href="group__easy.html#a14">sqlo_exec</a>(dbh, <span class="stringliteral">"DROP PROCEDURE EX9"</span>))
    error_exit(dbh, <span class="stringliteral">"sqlo_exec"</span>);

  <span class="keywordflow">return</span> 1;
}

<span class="comment">/* creates the stored procedure used above */</span>
<span class="keyword">static</span> <span class="keywordtype">void</span>
create_sp(<a class="code" href="group__typedefs.html#a0">sqlo_db_handle_t</a> dbh)
{
  <span class="keywordtype">char</span> * stmt =
    <span class="stringliteral">"CREATE OR REPLACE PROCEDURE EX9(ipNum1 IN NUMBER, ipNum2 IN NUMBER, opStr OUT VARCHAR)\n"</span>
    <span class="stringliteral">"IS\n"</span>
    <span class="stringliteral">"BEGIN\n"</span>
    <span class="stringliteral">"  opStr := TO_CHAR(ipNum1 + ipNum2);\n"</span>
    <span class="stringliteral">"END;\n"</span>;

  <span class="keywordflow">if</span> (<a class="code" href="group__constants.html#a3a25">SQLO_SUCCESS</a> != <a class="code" href="group__easy.html#a14">sqlo_exec</a>(dbh, stmt))
    error_exit(dbh, stmt);

}

<span class="comment">/* $Id: group__complex.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__complex.html#a0">sqlo_prepare</a>, <a class="el" href="group__complex.html#a3">sqlo_bind_by_pos</a>, <a class="el" href="group__complex.html#a5">sqlo_define_by_pos</a> </dl><dl compact><dt><b>Examples: </b></dt><dd>
<a class="el" href="ex17_8c-example.html#a2">ex17.c</a>, <a class="el" href="ex18_8c-example.html#a1">ex18.c</a>, <a class="el" href="ex19_8c-example.html#a1">ex19.c</a>, and <a class="el" href="ex9_8c-example.html#a1">ex9.c</a>.</dl>    </td>
  </tr>
</table>
<a name="a3" doxytag="sqlora.h::sqlo_bind_by_pos"></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_bind_by_pos </td>
          <td class="md" valign="top">(&nbsp;</td>
          <td class="md" nowrap valign="top"><a class="el" href="group__typedefs.html#a1">sqlo_stmt_handle_t</a>&nbsp;</td>
          <td class="mdname" nowrap>&nbsp; <em>sth</em>, </td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td class="md" nowrap>int&nbsp;</td>
          <td class="mdname" nowrap>&nbsp; <em>position</em>, </td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td class="md" nowrap>int&nbsp;</td>
          <td class="mdname" nowrap>&nbsp; <em>param_type</em>, </td>
        </tr>
        <tr>
          <td></td>
          <td></td>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?