group__lob.html

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

HTML
1,040
字号
  <span class="keywordflow">if</span> (<a class="code" href="group__constants.html#a3a25">SQLO_SUCCESS</a> != status) {
    <a class="code" href="group__lob.html#a1">sqlo_free_lob_desc</a>(dbh, &amp;loblp);
    error_exit(dbh, <span class="stringliteral">"sqlo_execute"</span>);
  }

  <span class="comment">/* write the lob */</span>
  status = <a class="code" href="group__lob.html#a2">sqlo_lob_write_buffer</a>(dbh, loblp, MAX_BLOB_BUFFER_DATA, data, 
                                 MAX_BLOB_BUFFER_DATA, <a class="code" href="group__constants.html#a5a50">SQLO_ONE_PIECE</a>);

  <span class="keywordflow">if</span> (status &lt; 0) {
    <a class="code" href="group__lob.html#a1">sqlo_free_lob_desc</a>(dbh, &amp;loblp);
    error_exit(dbh, <span class="stringliteral">"sqlo_log_write_buffer"</span>);
  }

  <a class="code" href="group__lob.html#a1">sqlo_free_lob_desc</a>(dbh, &amp;loblp);
  <a class="code" href="group__easy.html#a13">sqlo_close</a>(sth);
  
  <span class="keywordflow">return</span> (1);
}

<span class="keywordtype">void</span> create_blob_table(<a class="code" href="group__typedefs.html#a0">sqlo_db_handle_t</a> dbh)
{
  <span class="keywordtype">char</span> * stmt=
    <span class="stringliteral">"CREATE TABLE T_SQLORA_BLOB (KEY INTEGER, CDATA CLOB, BDATA BLOB)"</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))
    <span class="keywordflow">if</span> (<a class="code" href="group__error.html#a1">sqlo_geterrcode</a>(dbh) != 955) <span class="comment">/* table exists already */</span>
      error_exit(dbh, <span class="stringliteral">"sqlo_exec"</span>);
}

<span class="keywordtype">void</span> drop_blob_table(<a class="code" href="group__typedefs.html#a0">sqlo_db_handle_t</a> dbh)
{
  <span class="keywordtype">char</span> * stmt = <span class="stringliteral">"DROP TABLE T_SQLORA_BLOB"</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, <span class="stringliteral">"sqlo_exec"</span>);
}

<span class="keywordtype">void</span> fillbuf(<span class="keywordtype">char</span> * data, <span class="keywordtype">int</span> len)
{
  <span class="keywordtype">int</span> i;
  <span class="keywordflow">for</span> (i = 0; i &lt; len; ++i) {
    data[i] = <span class="charliteral">'A'</span> + i % 26;
  }
}

<span class="comment">/* $Id */</span>
</pre></div> </dl>    </td>
  </tr>
</table>
<a name="a5" doxytag="sqlora.h::sqlo_lob_get_length"></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_lob_get_length </td>
          <td class="md" valign="top">(&nbsp;</td>
          <td class="md" nowrap valign="top"><a class="el" href="group__typedefs.html#a0">sqlo_db_handle_t</a>&nbsp;</td>
          <td class="mdname" nowrap>&nbsp; <em>dbh</em>, </td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td class="md" nowrap><a class="el" href="group__typedefs.html#a2">sqlo_lob_desc_t</a>&nbsp;</td>
          <td class="mdname" nowrap>&nbsp; <em>loblp</em>, </td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td class="md" nowrap>unsigned int *&nbsp;</td>
          <td class="mdname" nowrap>&nbsp; <em>loblenp</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>
Get the length of a lob.
<p>
<dl compact><dt><b>Parameters: </b></dt><dd>
<table border=0 cellspacing=2 cellpadding=0>
<tr><td valign=top><em>dbh</em>&nbsp;</td><td>
I - Database handle </td></tr>
<tr><td valign=top><em>loblp</em>&nbsp;</td><td>
I - A lob descriptor </td></tr>
<tr><td valign=top><em>loblenp</em>&nbsp;</td><td>
O - The length of the lob</td></tr>
</table>
</dl><dl compact><dt><b>Returns: </b></dt><dd>
<ul>
<li>SQLO_SUCCESS <li>SQLO_STILL_EXECUTING <li>SQLO_ERROR </ul>
</dl><dl compact><dt><b>Examples: </b></dt><dd>
<a class="el" href="ex15_8c-example.html#a6">ex15.c</a>, and <a class="el" href="ex16_8c-example.html#a6">ex16.c</a>.</dl>    </td>
  </tr>
</table>
<a name="a6" doxytag="sqlora.h::sqlo_lob_read_buffer"></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_lob_read_buffer </td>
          <td class="md" valign="top">(&nbsp;</td>
          <td class="md" nowrap valign="top"><a class="el" href="group__typedefs.html#a0">sqlo_db_handle_t</a>&nbsp;</td>
          <td class="mdname" nowrap>&nbsp; <em>dbh</em>, </td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td class="md" nowrap><a class="el" href="group__typedefs.html#a2">sqlo_lob_desc_t</a>&nbsp;</td>
          <td class="mdname" nowrap>&nbsp; <em>loblp</em>, </td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td class="md" nowrap>unsigned int&nbsp;</td>
          <td class="mdname" nowrap>&nbsp; <em>loblen</em>, </td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td class="md" nowrap>void *&nbsp;</td>
          <td class="mdname" nowrap>&nbsp; <em>bufp</em>, </td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td class="md" nowrap>unsigned int&nbsp;</td>
          <td class="mdname" nowrap>&nbsp; <em>bufl</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>
Read lob data from lob column into a buffer.
<p>
Reads data from the lob and writes it into the supplied buffer.
<p>
Use <a class="el" href="group__lob.html#a5">Functions to insert/select LOBs</a> to get the loblen you have to use here.<dl compact><dt><b>Parameters: </b></dt><dd>
<table border=0 cellspacing=2 cellpadding=0>
<tr><td valign=top><em>dbh</em>&nbsp;</td><td>
I - A database handle. </td></tr>
<tr><td valign=top><em>loblp</em>&nbsp;</td><td>
I - A lob locator. </td></tr>
<tr><td valign=top><em>loblen</em>&nbsp;</td><td>
I - The length of the lob </td></tr>
<tr><td valign=top><em>bufp</em>&nbsp;</td><td>
O - The output data. </td></tr>
<tr><td valign=top><em>bufl</em>&nbsp;</td><td>
I - The capacity of the buffer in terms of bytes.</td></tr>
</table>
</dl><dl compact><dt><b>Returns: </b></dt><dd>
<ul>
<li>SQLO_SUCCESS <li>SQLO_NEED_DATA <li>SQLO_STILL_EXECUTING <li>SQLO_ERROR </ul>
</dl><dl compact><dt><b>Since: </b></dt><dd>
Version 2.2 </dl><dl compact><dt><b>Example:</b></dt><dd>
 <div class="fragment"><pre><span class="comment">/* $Id: group__lob.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> select_from_blob_table(<a class="code" href="group__typedefs.html#a0">sqlo_db_handle_t</a> dbh, <span class="keywordtype">int</span> key )
{
  <span class="keywordtype">char</span> * stmt = 
    <span class="stringliteral">"SELECT KEY, CDATA FROM T_SQLORA_BLOB WHERE KEY = :1"</span>;
  <span class="keywordtype">int</span> status;
  <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> k = key;
  <span class="keywordtype">char</span> * data;
  <span class="keywordtype">short</span> ind;
  <span class="keywordtype">char</span> cmp_data[MAX_BLOB_BUFFER_DATA];        <span class="comment">/* our buffer to compare the result */</span>
  <a class="code" href="group__typedefs.html#a2">sqlo_lob_desc_t</a> loblp;
  <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> loblen;

  fillbuf(cmp_data, MAX_BLOB_BUFFER_DATA); <span class="comment">/* our reference data */</span>

  <span class="comment">/* parse */</span>
  <span class="keywordflow">if</span> (0 &gt; (sth = <a class="code" href="group__complex.html#a0">sqlo_prepare</a>(dbh, stmt)))
    error_exit(dbh, <span class="stringliteral">"sqlo_prepare"</span>);

  <span class="comment">/* bind input */</span>
  <span class="keywordflow">if</span> (<a class="code" href="group__constants.html#a3a25">SQLO_SUCCESS</a> != 
      (<a class="code" href="group__complex.html#a3">sqlo_bind_by_pos</a>(sth, 1, <a class="code" href="group__constants.html#a6a56">SQLOT_INT</a>, &amp;k, <span class="keyword">sizeof</span>(k), 0, 0))) {
      error_exit(dbh, <span class="stringliteral">"sqlo_bind_by_pos"</span>);
    }
      
  <span class="comment">/* allocate a lob descriptor */</span>
  <span class="keywordflow">if</span> (0 &gt; <a class="code" href="group__lob.html#a0">sqlo_alloc_lob_desc</a>(dbh, &amp;loblp))
    error_exit(dbh, <span class="stringliteral">"sqlo_alloc_lob_desc"</span>);

  <span class="comment">/* define output */</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>(sth, 1, <a class="code" href="group__constants.html#a6a56">SQLOT_INT</a>, &amp;k, <span class="keyword">sizeof</span>(k), 0, 0, 0)) ||
      (<a class="code" href="group__complex.html#a5">sqlo_define_by_pos</a>(sth, 2, <a class="code" href="group__constants.html#a6a81">SQLOT_CLOB</a>, &amp;loblp, 0, &amp;ind, 0, 0))) {

      <a class="code" href="group__lob.html#a1">sqlo_free_lob_desc</a>(dbh, &amp;loblp);
      error_exit(dbh, <span class="stringliteral">"sqlo_define_by_pos2"</span>);
    }      

  <span class="comment">/* execute */</span>
  status = <a class="code" href="group__complex.html#a8">sqlo_execute</a>(sth, 1);

  <span class="keywordflow">if</span> (<a class="code" href="group__constants.html#a3a25">SQLO_SUCCESS</a> != status)  {
    <a class="code" href="group__lob.html#a1">sqlo_free_lob_desc</a>(dbh, &amp;loblp);
    error_exit(dbh, <span class="stringliteral">"sqlo_execute"</span>);
  }

  <span class="keywordflow">if</span> (ind != <a class="code" href="group__constants.html#a5a47">SQLO_NULL_IND</a>) 
    {
      status = <a class="code" href="group__lob.html#a5">sqlo_lob_get_length</a>(dbh, loblp, &amp;loblen);

      <span class="keywordflow">if</span> ( 0 &gt; status) {
        <a class="code" href="group__lob.html#a1">sqlo_free_lob_desc</a>(dbh, &amp;loblp);
        error_exit(dbh, <span class="stringliteral">"sqlo_free_lob_desc"</span>);
      }

      <span class="keywordflow">if</span> (loblen != MAX_BLOB_BUFFER_DATA) {
        printf(<span class="stringliteral">"Invalid LOB size. Expected %d, got %d\n"</span>, MAX_BLOB_BUFFER_DATA,
               loblen);
        <a class="code" href="group__lob.html#a1">sqlo_free_lob_desc</a>(dbh, &amp;loblp);
        <a class="code" href="group__easy.html#a13">sqlo_close</a>(sth);
        <span class="keywordflow">return</span> 0;
      }

      <span class="comment">/* allocate the buffer for the data */</span>
      data = malloc(loblen * <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>));
      <span class="keywordflow">if</span> (!data) {
          printf(<span class="stringliteral">"FATAL: malloc error at %d\n"</span>, __LINE__);
          <a class="code" href="group__lob.html#a1">sqlo_free_lob_desc</a>(dbh, &amp;loblp);
          exit(EXIT_FAILURE);
      }

⌨️ 快捷键说明

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