📄 group__complex.html
字号:
<tr><td valign=top><em>value_type</em> </td><td>I - The datatype of the bind parameter (<a class="el" href="group__constants.html#ga6">sqlo_data_types</a>). </td></tr> <tr><td valign=top><em>value_addr</em> </td><td>I - The pointer to the parameter data. </td></tr> <tr><td valign=top><em>value_size</em> </td><td>I - The size of the object at param_addr in bytes. </td></tr> <tr><td valign=top><em>ind_addr</em> </td><td>I - The pointer to the NULL indicator variable (optional). </td></tr> <tr><td valign=top><em>rlen_addr</em> </td><td>I - The pointer where library puts the actual return length. </td></tr> <tr><td valign=top><em>rcode_addr</em> </td><td>I - The address where the library puts the return code for the column </td></tr> <tr><td valign=top><em>skip_size</em> </td><td>I - In case into an array of structures, set to sizeof(your_struct), otherwise set it to 0.</td></tr> </table></dl><dl compact><dt><b>Returns:</b></dt><dd><ul><li>SQLO_SUCCESS </li><li>< 0 on error </li></ul></dd></dl><dl compact><dt><b>Example:</b></dt><dd>This is an example of a fetch into an array of structure. <div class="fragment"><pre><span class="comment">/* $Id: ex12.c,v 1.4 2002/08/24 12:54:47 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="keyword">enum</span> { MAX_NAME_LEN = 64, MAX_ARRAY_SIZE = 4 <span class="comment">/* Note: usually this should be 100 or so. </span><span class="comment"> * Used a smaller one to do test all paths in the code</span><span class="comment"> */</span>};<span class="keyword">typedef</span> <span class="keyword">struct </span>_result_t { <span class="keywordtype">char</span> name[MAX_NAME_LEN+1]; <span class="comment">/* output ENAME */</span> <span class="keywordtype">double</span> salary; <span class="comment">/* output SAL */</span> <span class="keywordtype">short</span> name_ind; <span class="comment">/* indicator variable of ENAME */</span> <span class="keywordtype">short</span> sal_ind; <span class="comment">/* indicator variable of SAL */</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> name_rlen; <span class="comment">/* the actual length of ENAME */</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> name_rcode; <span class="comment">/* the return code of ENAME */</span>} result_t;<span class="keywordtype">void</span> print_record __P((result_t * r));<span class="keywordtype">int</span> do_array_select(<a class="code" href="group__typedefs.html#ga0">sqlo_db_handle_t</a> dbh, <span class="keywordtype">double</span> min_salary){ <a class="code" href="group__typedefs.html#ga1">sqlo_stmt_handle_t</a> sth; <span class="comment">/* statement handle */</span> <span class="keywordtype">int</span> i; <span class="comment">/* loop variable */</span> <span class="keywordtype">int</span> status; <span class="comment">/* return code of sqlo_... */</span> result_t result[MAX_ARRAY_SIZE]; <span class="keywordtype">int</span> rows_fetched; <span class="comment">/* number of rows fetched per execute */</span> <span class="keywordtype">int</span> rows_fetched_total = 0; <span class="comment">/* total number of rows */</span> <span class="keywordtype">int</span> done_fetching = 0; <span class="comment">/* flag indicating end of fetch */</span> <span class="keywordtype">double</span> salary = min_salary; <span class="comment">/* input variable for SAL */</span> <span class="keywordtype">int</span> skip_size = <span class="keyword">sizeof</span>(result[0]); <span class="comment">/* The skip size */</span> sth = prepare_cursor(dbh, &salary); <span class="comment">/* see ex10.c */</span> <span class="comment">/* define output */</span> <span class="keywordflow">if</span> (<a class="code" href="group__constants.html#gga3a25">SQLO_SUCCESS</a> != (<a class="code" href="group__complex.html#ga193">sqlo_define_by_pos2</a>(sth, 1, SQLOT_STR, result[0].name, <span class="keyword">sizeof</span>(result[0].name), &result[0].name_ind, &result[0].name_rlen, &result[0].name_rcode, skip_size)) || (<a class="code" href="group__complex.html#ga193">sqlo_define_by_pos2</a>(sth, 2, SQLOT_FLT, &result[0].salary, <span class="keyword">sizeof</span>(result[0].salary), &result[0].sal_ind, 0, 0, skip_size))) { error_exit(dbh, <span class="stringliteral">"sqlo_define_by_pos"</span>); } <span class="comment">/* execute and fetch the result */</span> status = <a class="code" href="group__complex.html#ga194">sqlo_execute</a>(sth, 0); <span class="keywordflow">while</span> (!done_fetching) { rows_fetched = MAX_ARRAY_SIZE; <span class="comment">/* get the next set */</span> status = <a class="code" href="group__easy.html#ga167">sqlo_fetch</a>(sth, MAX_ARRAY_SIZE); <span class="keywordflow">if</span> (0 > status) error_exit(dbh, <span class="stringliteral">"sqlo_execute(NEXT)"</span>); <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="group__constants.html#gga3a32">SQLO_NO_DATA</a> == status) { rows_fetched = <a class="code" href="group__easy.html#ga169">sqlo_prows</a>(sth); <span class="comment">/* sqlo_prows returns now the total number of fetched rows</span><span class="comment"> * the difference to the previous total fechted rows is</span><span class="comment"> * the number of rows fetched in this last call to sqlo_execute</span><span class="comment"> */</span> rows_fetched = rows_fetched - rows_fetched_total; done_fetching = 1; } <span class="comment">/* print the records */</span> <span class="keywordflow">for</span> (i = 0; i < rows_fetched; ++i) print_record(&result[i]); rows_fetched_total += rows_fetched; } printf(<span class="stringliteral">"Selected %d employees\n"</span>, rows_fetched_total); <span class="comment">/* finished. */</span> <a class="code" href="group__easy.html#ga172">sqlo_close</a>(sth); <span class="keywordflow">return</span> 1;}<span class="comment">/* print record */</span><span class="keywordtype">void</span> print_record(result_t * r <span class="comment">/* I - The record */</span> ){ printf(<span class="stringliteral">"Name=%-8s Salary= %6.2f\n"</span>, (r->name_ind == SQLO_NULL_IND ? <span class="stringliteral">"NULL"</span> : r->name), (r->sal_ind == SQLO_NULL_IND ? -1.0 : r->salary));}<span class="comment">/* $Id: ex12.c,v 1.4 2002/08/24 12:54:47 kpoitschke Exp $ */</span></pre></div></dd></dl><dl compact><dt><b>See also:</b></dt><dd><a class="el" href="group__complex.html#ga0">sqlo_prepare</a>, <a class="el" href="group__complex.html#ga1">sqlo_bind_by_name</a>, <a class="el" href="group__complex.html#ga5">sqlo_define_by_pos</a>, <a class="el" href="group__complex.html#ga8">sqlo_execute</a> </dd></dl><dl compact><dt><b>Since:</b></dt><dd>Version 2.2 </dd></dl><p>Definition at line <a class="el" href="sqlora_8c-source.html#l06835">6835</a> of file <a class="el" href="sqlora_8c-source.html">sqlora.c</a>.<p>References <a class="el" href="sqlora_8c-source.html#l03132">_define_by_pos2()</a>, <a class="el" href="sqlora_8c-source.html#l02822">_get_data_type_str()</a>, <a class="el" href="sqlora_8c-source.html#l04319">_get_trace_fp()</a>, <a class="el" href="sqlora_8c-source.html#l00367">CHECK_STHANDLE</a>, <a class="el" href="sqlora_8c-source.html#l00565">_sqlo_stmt_struct::dbp</a>, <a class="el" href="group__constants.html#gga4a36">SQLO_INVALID_STMT_HANDLE</a>, <a class="el" href="sqlora_8c.html#a35">sqlo_stmt_struct_ptr_t</a>, and <a class="el" href="sqlora_8c-source.html#l00238">TRACE</a>. </td> </tr></table><p>Here is the call graph for this function:<p><center><img src="group__complex_ga6_cgraph.png" border="0" usemap="#group__complex_ga6_cgraph_map" alt=""></center><map name="group__complex_ga6_cgraph_map"><area href="sqlora_8c.html#a115" shape="rect" coords="208,91,323,110" alt=""><area href="sqlora_8c.html#a128" shape="rect" coords="551,51,647,70" alt=""><area href="sqlora_8c.html#a111" shape="rect" coords="372,141,503,159" alt=""><area href="sqlora_8c.html#a122" shape="rect" coords="387,5,488,23" alt=""><area href="sqlora_8c.html#a109" shape="rect" coords="391,98,484,117" alt=""></map><a class="anchor" name="ga7" doxytag="sqlora.h::sqlo_define_ntable" ></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0"> <tr> <td class="mdRow"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> int sqlo_define_ntable </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top"><a class="el" href="group__typedefs.html#ga1">sqlo_stmt_handle_t</a> </td> <td class="mdname" nowrap> <em>sth</em>, </td> </tr> <tr> <td class="md" nowrap align="right"></td> <td></td> <td class="md" nowrap>unsigned int </td> <td class="mdname" nowrap> <em>pos</em>, </td> </tr> <tr> <td class="md" nowrap align="right"></td> <td></td> <td class="md" nowrap>int * </td> <td class="mdname" nowrap> <em>sth2p</em></td> </tr> <tr> <td></td> <td class="md">) </td> <td class="md" colspan="2"></td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p>Define a nested table Please visit the example for details. <p><dl compact><dt><b>Note:</b></dt><dd>You can also use <a class="el" href="group__complex.html#ga5">sqlo_define_by_pos</a> with type == SQLOT_RSET and passing the address of the new sth as value_addr and set all other parameters to 0.</dd></dl><dl compact><dt><b>Parameters:</b></dt><dd> <table border="0" cellspacing="2" cellpadding="0"> <tr><td valign=top><em>sth</em> </td><td>I - The statement handle </td></tr> <tr><td valign=top><em>pos</em> </td><td>I - The define position of the nested table </td></tr> <tr><td valign=top><em>sth2p</em> </td><td>O - The new statement handle for the nested table. </td></tr> </table></dl><dl compact><dt><b>Examples:</b></dt><dd><div class="fragment"><pre><span class="comment">/* $Id: ex19.c,v 1.4 2002/08/24 12:54:47 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> select_ntable(<a class="code" href="group__typedefs.html#ga0">sqlo_db_handle_t</a> dbh){ <a class="code" href="group__typedefs.html#ga1">sqlo_stmt_handle_t</a> sth = <a class="code" href="group__constants.html#gga5a49">SQLO_STH_INIT</a>; <a class="code" href="group__typedefs.html#ga1">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 class="code" href="group__complex.html#ga186">sqlo_prepare</a>(dbh, stmt))) { <span class="comment">/* bind all variables */</span> <span class="keywordflow">if</span> (<a class="code" href="group__constants.html#gga3a25">SQLO_SUCCESS</a> != (<a class="code" href="group__complex.html#ga187">sqlo_bind_by_name</a>(sth, <span class="stringliteral">":deptno"</span>, SQLOT_INT, &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#gga3a25">SQLO_SUCCESS</a> != ( <a class="code" href="group__complex.html#ga192">sqlo_define_by_pos</a>(sth, 1, SQLOT_STR, ename, <span class="keyword">sizeof</span>(ename), &
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -