📄 ex13_8c-example.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>libsqlora8: Example Documentation</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.3.6 --><div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</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></div><h1>ex13.c</h1>Example for inserting data into a blob column from an internal buffer. <div class="fragment"><pre><span class="comment">/* $Id: ex13.c,v 1.6 2004/01/03 16:48:19 kpoitschke 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> insert_into_blob_table(<a class="code" href="group__typedefs.html#ga0">sqlo_db_handle_t</a> dbh, <span class="keywordtype">int</span> key ){ <span class="keywordtype">char</span> * stmt = <span class="stringliteral">"INSERT INTO T_SQLORA_BLOB (KEY, CDATA) "</span> <span class="stringliteral">"VALUES (:b1, EMPTY_CLOB()) RETURNING CDATA INTO :b2"</span>; <span class="keywordtype">char</span> data[MAX_BLOB_BUFFER_DATA]; <span class="comment">/* a data buffer */</span> <a class="code" href="group__typedefs.html#ga2">sqlo_lob_desc_t</a> loblp; <span class="comment">/* the lob locator */</span> <a class="code" href="group__typedefs.html#ga1">sqlo_stmt_handle_t</a> sth; <span class="keywordtype">int</span> status; <span class="keywordtype">int</span> k = key; printf(<span class="stringliteral">"Insert CLOB\n"</span>); <span class="comment">/* create the test table */</span> create_blob_table(dbh); <span class="comment">/* fill the data buffer with some characters */</span> fillbuf(data, MAX_BLOB_BUFFER_DATA); <span class="comment">/* parse the statement */</span> <span class="keywordflow">if</span> (0>(sth = <a name="a11"></a><a class="code" href="group__complex.html#ga186">sqlo_prepare</a>(dbh, stmt))) error_exit(dbh, <span class="stringliteral">"sqlo_prepare"</span>); <span class="comment">/* alloate the lob descriptor */</span> <span class="keywordflow">if</span> (0 > <a name="a12"></a><a class="code" href="group__lob.html#ga205">sqlo_alloc_lob_desc</a>(dbh, &loblp)) error_exit(dbh, <span class="stringliteral">"sqlo_alloc_lob_desc"</span>); <span class="comment">/* bind input variables. Note: we bind the lob descriptor here */</span> <span class="keywordflow">if</span> (<a class="code" href="group__constants.html#gga3a25">SQLO_SUCCESS</a> != (<a name="a13"></a><a class="code" href="group__complex.html#ga190">sqlo_bind_by_pos</a>(sth, 1, SQLOT_INT, &k, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>), NULL, 0)) || (<a class="code" href="group__complex.html#ga190">sqlo_bind_by_pos</a>(sth, 2, SQLOT_CLOB, &loblp, 0, NULL, 0)) ) { <a name="a14"></a><a class="code" href="group__lob.html#ga206">sqlo_free_lob_desc</a>(dbh, &loblp); error_exit(dbh, <span class="stringliteral">"sqlo_bind_by_pos"</span>); } <span class="comment">/* execute the statement */</span> status = <a name="a15"></a><a class="code" href="group__complex.html#ga194">sqlo_execute</a>(sth, 1); <span class="keywordflow">if</span> (<a class="code" href="group__constants.html#gga3a25">SQLO_SUCCESS</a> != status) { <a class="code" href="group__lob.html#ga206">sqlo_free_lob_desc</a>(dbh, &loblp); error_exit(dbh, <span class="stringliteral">"sqlo_execute"</span>); } <span class="comment">/* write the lob */</span> status = <a name="a16"></a><a class="code" href="group__lob.html#ga207">sqlo_lob_write_buffer</a>(dbh, loblp, MAX_BLOB_BUFFER_DATA, data, MAX_BLOB_BUFFER_DATA, SQLO_ONE_PIECE); <span class="keywordflow">if</span> (status < 0) { <a class="code" href="group__lob.html#ga206">sqlo_free_lob_desc</a>(dbh, &loblp); error_exit(dbh, <span class="stringliteral">"sqlo_log_write_buffer"</span>); } <a class="code" href="group__lob.html#ga206">sqlo_free_lob_desc</a>(dbh, &loblp); <a name="a17"></a><a class="code" href="group__easy.html#ga172">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#ga0">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#gga3a25">SQLO_SUCCESS</a> != <a name="a18"></a><a class="code" href="group__easy.html#ga163">sqlo_exec</a>(dbh, stmt)) <span class="keywordflow">if</span> (<a name="a19"></a><a class="code" href="group__error.html#ga159">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#ga0">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#gga3a25">SQLO_SUCCESS</a> != <a class="code" href="group__easy.html#ga163">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 < len; ++i) { data[i] = <span class="charliteral">'A'</span> + i % 26; }}<span class="comment">/* $Id */</span></pre></div> <hr size="1"><address style="align: right;"><small>Generated on Sun Jun 13 04:51:41 2004 for libsqlora8 by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 > </a>1.3.6 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -