forked from OpenSIPS/opensips
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_ut.h
More file actions
192 lines (162 loc) · 5.35 KB
/
Copy pathdb_ut.h
File metadata and controls
192 lines (162 loc) · 5.35 KB
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
/*
* $Id$
*
* Copyright (C) 2001-2003 FhG Fokus
* Copyright (C) 2007-2008 1&1 Internet AG
*
* This file is part of opensips, a free SIP server.
*
* opensips is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version
*
* opensips is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* \file db/db_ut.h
* \brief Utility functions for database drivers.
*
* This utility methods are used from the database SQL driver to convert
* values and print SQL queries from the internal API representation.
*/
#ifndef DB_UT_H
#define DB_UT_H
/**
* maximal SQL buffer length for database drivers
*/
#define SQL_BUF_LEN 65536
/**
* make strptime available
* use 600 for 'Single UNIX Specification, Version 3'
*/
#define _XOPEN_SOURCE 600 /* glibc2 on linux, bsd */
#define _XOPEN_SOURCE_EXTENDED 1 /* solaris */
/**
* _XOPEN_SOURCE creates conflict in swab definition in Solaris
*/
#ifdef __OS_solaris
#undef _XOPEN_SOURCE
#endif
#include <time.h>
#undef _XOPEN_SOURCE
#undef _XOPEN_SOURCE_EXTENDED
#include "db_key.h"
#include "db.h"
/**
* Converts a char into an integer value.
*
* \param _s source value
* \param _v target value
* \return zero on sucess, negative on conversion errors
*/
int db_str2int(const char* _s, int* _v);
/**
* Converts a char into a double value.
*
* \param _s source value
* \param _v target value
* \return zero on sucess, negative on conversion errors
*/
int db_str2double(const char* _s, double* _v);
/**
* Converts a integer value in a char pointer.
*
* \param _v source value
* \param _s target value
* \param _l available length and target length
* \return zero on sucess, negative on conversion errors
*/
int db_int2str(int _v, char* _s, int* _l);
/**
* Converts a double value into a char pointer.
*
* \param _v source value
* \param _s target value
* \param _l available length and target length
* \return zero on sucess, negative on conversion errors
*/
int db_double2str(double _v, char* _s, int* _l);
/**
* Convert a time_t value to string.
*
* \param _v source value
* \param _s target value
* \param _l available length and target length
* \return zero on sucess, negative on conversion errors
* \todo This functions add quotes to the time value. This
* should be done in the val2str function, as some databases
* like db_berkeley don't need or like this at all.
*/
int db_time2str(time_t _v, char* _s, int* _l);
/**
* Converts a char into a time_t value.
*
* \param _s source value
* \param _v target value
* \return zero on sucess, negative on conversion errors
*/
int db_str2time(const char* _s, time_t* _v);
int db_time2str_nq(time_t _v, char* _s, int* _l);
/**
* Print columns for a SQL statement, separated by commas.
*
* \param _b target char
* \param _l length of the target
* \param _c keys that should be printed
* \param _n number of keys
* \return the length of the printed result on success, negative on errors
*/
int db_print_columns(char* _b, const int _l, const db_key_t* _c, const int _n);
/**
* Print values for a SQL statement.
*
* \param _c structure representing database connection
* \param _b target char
* \param _l length of the target
* \param _v values that should be printed
* \param _n number of values
* \param (*val2str) function pointer to a db specific conversion function
* \return the length of the printed result on success, negative on errors
*/
int db_print_values(const db_con_t* _c, char* _b, const int _l, const db_val_t* _v,
const int _n, int (*val2str)(const db_con_t*, const db_val_t*, char*, int*));
/**
* Print where clause for a SQL statement.
*
* \param _c structure representing database connection
* \param _b target char
* \param _l length of the target
* \param _k keys that should be printed
* \param _o optional operators
* \param _v values that should be printed
* \param _n number of key/value pairs
* \param (*val2str) function pointer to a db specific conversion function
* \return the length of the printed result on success, negative on errors
*/
int db_print_where(const db_con_t* _c, char* _b, const int _l, const db_key_t* _k,
const db_op_t* _o, const db_val_t* _v, const int _n, int (*val2str)
(const db_con_t*, const db_val_t*, char*, int*));
/**
* Print set clause for a SQL statement.
*
* \param _c structure representing database connection
* \param _b target char
* \param _l length of the target
* \param _k keys that should be printed
* \param _v vals that should be printed
* \param _n number of key/value pairs
* \param (*val2str) function pointer to a db specific conversion function
* \return the length of the printed result on success, negative on errors
*/
int db_print_set(const db_con_t* _c, char* _b, const int _l,
const db_key_t* _k, const db_val_t* _v, const int _n, int (*val2str)
(const db_con_t*, const db_val_t*, char*, int*));
#endif