File: db_res_t.xml

package info (click to toggle)
kamailio 5.6.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 68,332 kB
  • sloc: ansic: 744,091; xml: 196,848; cpp: 14,471; makefile: 8,859; sh: 8,814; sql: 7,844; yacc: 3,863; perl: 2,955; python: 2,710; java: 449; javascript: 269; php: 258; ruby: 225; cs: 40; awk: 27
file content (123 lines) | stat: -rw-r--r-- 3,023 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" 
   "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">

<section id="db_res_t" xmlns:xi="http://www.w3.org/2001/XInclude">
    <sectioninfo>
	<revhistory>
	    <revision>
		<revnumber>$Revision$</revnumber>
		<date>$Date$</date>
	    </revision>
	</revhistory>
    </sectioninfo>
    
    <title>Type <type>db_res_t</type></title>
    <para>
	This type represents a result returned by <function>db_query</function>
	function (see below). The result can consist of zero or more rows (see
	<type>db_row_t</type> description).
    </para>
    <note>
	<para>
	    A variable of type <type>db_res_t</type> returned by
	    <function>db_query</function> function uses dynamically allocated
	    memory, don't forget to call <function>db_free_result</function> if
	    you don't need the variable anymore.  You will encounter memory
	    leaks if you fail to do this !
	</para>
    </note>
    <para>
	In addition to zero or more rows, each <type>db_res_t</type> object
	contains also an array of <type>db_key_t</type> objects. The objects
	represent keys (names of columns).
    </para>
    <programlisting>
typedef struct db_res {
    struct {
        db_key_t* keys;    /* Array of column names */
        db_type_t* types;  /* Array of column types */
        int n;             /* Number of columns */
    } col;
    struct db_row* rows;   /* Array of rows */
    int n;                 /* Number of rows */
} db_res_t;
    </programlisting>
    <itemizedlist>
	<listitem>
	    <para>
		<function>RES_NAMES(res)</function> Macro.
	    </para>
	    <para>
		Use this macro if you want to obtain pointer to an array of
		cell names.
	    </para>
	    <example>
		<title>RES_NAMES Macro</title>
		<programlisting>
...
db_key_t* column_names = ROW_NAMES(row);
...
		</programlisting>
	    </example>
	</listitem>
	
	<listitem>
	    <para>
		<function>RES_COL_N(res)</function> Macro.
	    </para>
	    <para>
		Use this macro if you want to get the number of columns in the result.
	    </para>
	    <example>
		<title>RES_COL_N Macro</title>
		<programlisting>
<![CDATA[
...
int ncol = RES_COL_N(res);
for(i = 0; i < ncol; i++) {
    /* do something with the column */
}
...
]]>
		</programlisting>
	    </example>
	</listitem>
	
	<listitem>
	    <para>
		<function>RES_ROWS(res)</function> Macro.
	    </para>
	    <para>
		Use this macro if you need to obtain pointer to array of rows.
	    </para>
	    <example>
		<title>RES_ROWS Macro</title>
		<programlisting>
...
db_row_t* rows = RES_ROWS(res);
...
		</programlisting>
	    </example>
	</listitem>
	
	<listitem>
	    <para>
		<function>RES_ROW_N(res)</function> Macro.
	    </para>
	    <para>
		Use this macro if you need to obtain the number of rows in the
		result.
	    </para>
	    <example>
		<title>RES_ROW_N Macro</title>
		<programlisting>
...
int n = RES_ROW_N(res);
...
		</programlisting>
	    </example>
	</listitem>
    </itemizedlist>
</section>