File: db_val_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 (241 lines) | stat: -rw-r--r-- 5,709 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<?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_val_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_val_t</type></title>
    <para>
	This structure represents a value in the database. Several data-types
	are recognized and converted by the database <acronym>API</acronym>:
	<itemizedlist>
	    <listitem>
		<para>
		    <emphasis>DB_INT</emphasis> - Value in the database
		    represents an integer number.
		</para>
	    </listitem>
	    <listitem>
		<para>
		    <emphasis>DB_DOUBLE</emphasis> - Value in the database
		    represents a decimal number.
		</para>
	    </listitem>
	    <listitem>
		<para>
		    <emphasis>DB_STRING</emphasis> - Value in the database
		    represents a string.
		</para>
	    </listitem>
	    <listitem>
		<para>
		    <emphasis>DB_STR</emphasis> - Value in the database
		    represents a string.
		</para>
	    </listitem>
	    <listitem>
		<para>
		    <emphasis>DB_DATETIME</emphasis> - Value in the database
		    represents date and time.
		</para>
	    </listitem>
	    <listitem>
		<para>
		    <emphasis>DB_BLOB</emphasis> - Value in the database
		    represents binary large object.
		</para>
	    </listitem>
	</itemizedlist>
	These data-types are automatically recognized, converted from internal
	database representation and stored in a variable of corresponding type.
    </para>
    <programlisting>
typedef struct db_val {
    db_type_t type;              /* Type of the value */
    int nul;                     /* NULL flag */
    union {                      
        int int_val;             /* Integer value */
        double double_val;       /* Double value */
        time_t time_val;         /* Unix time_t value */
        const char* string_val;  /* Zero terminated string */
        str str_val;             /* str structure */
        str blob_val;            /* Structure describing blob */
    } val;
} db_val_t;
    </programlisting>
    <note>
	<para>
	    All macros expect pinter to <type>db_val_t</type> variable as a
	    parameter.
	</para>
    </note>
    <itemizedlist>
	<listitem>
	    <para>
		<function>VAL_TYPE(value)</function> Macro.
	    </para>
	    <para>
		Use this macro if you need to set/get the type of the value
	    </para>
	    <example>
		<title>VAL_TYPE Macro</title>
		<programlisting>
...
VAL_TYPE(val) = DB_INT;
if (VAL_TYPE(val) == DB_FLOAT)
...
		</programlisting>
	    </example>
	</listitem>
	
	<listitem>
	    <para>
		<function>VAL_NULL(value)</function> Macro.
	    </para>
	    <para>
		Use this macro if you need to set/get the null flag. Non-zero
		flag means that the corresponding cell in the database
		contained no data (NULL value in <acronym>MySQL</acronym>
		terminology).
	    </para>
	    <example>
		<title>VAL_NULL Macro</title>
		<programlisting>
...
if (VAL_NULL(val) == 1) {
    printf("The cell is NULL");
}
...
		</programlisting>
	    </example>
	</listitem>
	
	<listitem>
	    <para>
		<function>VAL_INT(value)</function> Macro.
	    </para>
	    <para>
		Use this macro if you need to access <type>integer</type> value
		in <type>db_val_t</type> structure.
	    </para>
	    <example>
		<title>VAL_INT Macro</title>
		<programlisting>
...
if (VAL_TYPE(val) == DB_INT) {
    printf("%d", VAL_INT(val));
}
...
		</programlisting>
	    </example>
	</listitem>
	
	<listitem>
	    <para>
		<function>VAL_DOUBLE(value)</function> Macro.
	    </para>
	    <para>
		Use this macro if you need to access <type>double</type> value
		in the <type>db_val_t</type> structure.
	    </para>
	    <example>
		<title>VAL_DOUBLE Macro</title>
		<programlisting>
...
if (VAL_TYPE(val) == DB_DOUBLE) {
    printf("%f", VAL_DOUBLE(val));
}
...
		</programlisting>
	    </example>
	</listitem>
	
	<listitem>
	    <para>
		<function>VAL_TIME(value)</function> Macro.
	    </para>
	    <para>
		Use this macro if you need to access <type>time_t</type> value
		in <type>db_val_t</type> structure.
	    </para>
	    <example>
		<title>VAL_TIME Macro</title>
		<programlisting>
...
time_t tim;
if (VAL_TYPE(val) == DB_DATETIME) {
    tim = VAL_TIME(val);
}
...
		</programlisting>
	    </example>
	</listitem>
	
	<listitem>
	    <para>
		<function>VAL_STRING(value)</function> Macro.
	    </para>
	    <para>
		Use this macro if you need to access <type>string</type> value
		in <type>db_val_t</type> structure.
	    </para>
	    <example>
		<title>VAL_STRING Macro</title>
		<programlisting>
...
if (VAL_TYPE(val) == DB_STRING) {
    printf("%s", VAL_STRING(val));
}
...
		</programlisting>
	    </example>
	</listitem>
	
	<listitem>
	    <para>
		<function>VAL_STR(value)</function> Macro.
	    </para>
	    <para>
		Use this macro if you need to access <type>str</type> structure
		in <type>db_val_t</type> structure.
	    </para>
	    <example>
		<title>VAL_STR Macro</title>
		<programlisting>
...
if (VAL_TYPE(val) == DB_STR) {
    printf("%.*s", VAL_STR(val).len, VAL_STR(val).s);
}
...
		</programlisting>
	    </example>
	</listitem>
	
	<listitem>
	    <para>
		<function>VAL_BLOB(value)</function> Macro.
	    </para>
	    <para>
		Use this macro if you need to access <type>blob</type> value in <type>db_val_t</type> structure.
	    </para>
	    <example>
		<title>VAL_STR Macro</title>
		<programlisting>
...
if (VAL_TYPE(val) == DB_BLOB) {
    printf("%.*s", VAL_BLOB(val).len, VAL_BLOB(val).s);
}
...
		</programlisting>
	    </example>
	</listitem>
    </itemizedlist>
</section>