Browse code

core, lib, modules: restructured source code tree

- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)

Daniel-Constantin Mierla authored on 07/12/2016 11:03:51
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,242 +0,0 @@
1
-/* 
2
- * MySQL module result related functions
3
- *
4
- * Copyright (C) 2001-2003 FhG Fokus
5
- * Copyright (C) 2007-2008 1&1 Internet AG
6
- *
7
- * This file is part of Kamailio, a free SIP server.
8
- *
9
- * Kamailio is free software; you can redistribute it and/or modify
10
- * it under the terms of the GNU General Public License as published by
11
- * the Free Software Foundation; either version 2 of the License, or
12
- * (at your option) any later version
13
- *
14
- * Kamailio is distributed in the hope that it will be useful,
15
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
- * GNU General Public License for more details.
18
- *
19
- * You should have received a copy of the GNU General Public License 
20
- * along with this program; if not, write to the Free Software 
21
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22
- */
23
-
24
-
25
-/*! \file
26
- *  \brief DB_MYSQL :: Result related functions
27
- *  \ingroup db_mysql
28
- *  Module: \ref db_mysql
29
- */
30
-
31
-
32
-#include <string.h>
33
-#include <mysql.h>
34
-#include "../../lib/srdb1/db_res.h"
35
-#include "../../mem/mem.h"
36
-#include "../../dprint.h"
37
-#include "km_row.h"
38
-#include "km_my_con.h"
39
-#include "km_res.h"
40
-
41
-
42
-/*!
43
- * \brief Get and convert columns from a result
44
- *
45
- * Get and convert columns from a result, fills the result structure
46
- * with data from the database.
47
- * \param _h database connection
48
- * \param _r database result set
49
- * \return 0 on success, negative on failure
50
- */
51
-int db_mysql_get_columns(const db1_con_t* _h, db1_res_t* _r)
52
-{
53
-	int col;
54
-	MYSQL_FIELD* fields;
55
-
56
-	if ((!_h) || (!_r)) {
57
-		LM_ERR("invalid parameter\n");
58
-		return -1;
59
-	}
60
-
61
-	RES_COL_N(_r) = mysql_field_count(CON_CONNECTION(_h));
62
-	if (!RES_COL_N(_r)) {
63
-		LM_ERR("no columns returned from the query\n");
64
-		return -2;
65
-	} else {
66
-		LM_DBG("%d columns returned from the query\n", RES_COL_N(_r));
67
-	}
68
-	
69
-	if (db_allocate_columns(_r, RES_COL_N(_r)) != 0) {
70
-		RES_COL_N(_r) = 0;
71
-		LM_ERR("could not allocate columns\n");
72
-		return -3;
73
-	}
74
-
75
-	fields = mysql_fetch_fields(RES_RESULT(_r));
76
-	for(col = 0; col < RES_COL_N(_r); col++) {
77
-		RES_NAMES(_r)[col] = (str*)pkg_malloc(sizeof(str));
78
-		if (! RES_NAMES(_r)[col]) {
79
-			LM_ERR("no private memory left\n");
80
-			db_free_columns(_r);
81
-			return -4;
82
-		}
83
-		LM_DBG("allocate %lu bytes for RES_NAMES[%d] at %p\n",
84
-				(unsigned long)sizeof(str), col, RES_NAMES(_r)[col]);
85
-
86
-		/* The pointer that is here returned is part of the result structure. */
87
-		RES_NAMES(_r)[col]->s = fields[col].name;
88
-		RES_NAMES(_r)[col]->len = strlen(fields[col].name);
89
-
90
-		LM_DBG("RES_NAMES(%p)[%d]=[%.*s]\n", RES_NAMES(_r)[col], col,
91
-				RES_NAMES(_r)[col]->len, RES_NAMES(_r)[col]->s);
92
-
93
-		switch(fields[col].type) {
94
-			case MYSQL_TYPE_TINY:
95
-			case MYSQL_TYPE_SHORT:
96
-			case MYSQL_TYPE_LONG:
97
-			case MYSQL_TYPE_INT24:
98
-			case MYSQL_TYPE_TIMESTAMP:
99
-				LM_DBG("use DB1_INT result type\n");
100
-				RES_TYPES(_r)[col] = DB1_INT;
101
-				break;
102
-
103
-			case MYSQL_TYPE_LONGLONG:
104
-				LM_DBG("use DB1_BIGINT result type\n");
105
-				RES_TYPES(_r)[col] = DB1_BIGINT;
106
-				break;
107
-
108
-			case MYSQL_TYPE_FLOAT:
109
-			case MYSQL_TYPE_DOUBLE:
110
-				LM_DBG("use DB1_DOUBLE result type\n");
111
-				RES_TYPES(_r)[col] = DB1_DOUBLE;
112
-				break;
113
-
114
-			case MYSQL_TYPE_DATETIME:
115
-				LM_DBG("use DB1_DATETIME result type\n");
116
-				RES_TYPES(_r)[col] = DB1_DATETIME;
117
-				break;
118
-
119
-			case MYSQL_TYPE_BLOB:
120
-				LM_DBG("use DB1_BLOB result type\n");
121
-				RES_TYPES(_r)[col] = DB1_BLOB;
122
-				break;
123
-
124
-			case FIELD_TYPE_SET:
125
-				LM_DBG("use DB1_BITMAP result type\n");
126
-				RES_TYPES(_r)[col] = DB1_BITMAP;
127
-				break;
128
-
129
-			case MYSQL_TYPE_DECIMAL:
130
-			#if MYSQL_VERSION_ID > 49999
131
-			case MYSQL_TYPE_NEWDECIMAL:
132
-			#endif
133
-			case MYSQL_TYPE_STRING:
134
-			case MYSQL_TYPE_VAR_STRING:
135
-				LM_DBG("use DB1_STRING result type\n");
136
-				RES_TYPES(_r)[col] = DB1_STRING;
137
-				break;
138
-
139
-			default:
140
-				LM_WARN("unhandled data type column (%.*s) type id (%d), "
141
-						"use DB1_STRING as default\n", RES_NAMES(_r)[col]->len,
142
-						RES_NAMES(_r)[col]->s, fields[col].type);
143
-				RES_TYPES(_r)[col] = DB1_STRING;
144
-				break;
145
-		}
146
-	}
147
-	return 0;
148
-}
149
-
150
-
151
-/*!
152
- * \brief Convert rows from mysql to db API representation
153
- * \param _h database connection
154
- * \param _r database result set
155
- * \return 0 on success, negative on failure
156
- */
157
-static inline int db_mysql_convert_rows(const db1_con_t* _h, db1_res_t* _r)
158
-{
159
-	int row;
160
-
161
-	if ((!_h) || (!_r)) {
162
-		LM_ERR("invalid parameter\n");
163
-		return -1;
164
-	}
165
-
166
-	RES_ROW_N(_r) = mysql_num_rows(RES_RESULT(_r));
167
-	if (!RES_ROW_N(_r)) {
168
-		LM_DBG("no rows returned from the query\n");
169
-		RES_ROWS(_r) = 0;
170
-		return 0;
171
-	}
172
-
173
-	if (db_allocate_rows(_r) < 0) {
174
-		LM_ERR("could not allocate rows");
175
-		RES_ROW_N(_r) = 0;
176
-		return -2;
177
-	}
178
-
179
-	for(row = 0; row < RES_ROW_N(_r); row++) {
180
-		RES_ROW(_r) = mysql_fetch_row(RES_RESULT(_r));
181
-		if (!RES_ROW(_r)) {
182
-			LM_ERR("driver error: %s\n", mysql_error(CON_CONNECTION(_h)));
183
-			RES_ROW_N(_r) = row;
184
-			db_free_rows(_r);
185
-			return -3;
186
-		}
187
-		if (db_mysql_convert_row(_h, _r, &(RES_ROWS(_r)[row])) < 0) {
188
-			LM_ERR("error while converting row #%d\n", row);
189
-			RES_ROW_N(_r) = row;
190
-			db_free_rows(_r);
191
-			return -4;
192
-		}
193
-	}
194
-	return 0;
195
-}
196
-
197
-
198
-/*!
199
- * \brief Fill the result structure with data from database
200
- * \param _h database connection
201
- * \param _r database result
202
- * \return 0 on success, negative on failure
203
- */
204
-int db_mysql_convert_result(const db1_con_t* _h, db1_res_t* _r)
205
-{
206
-	if ((!_h) || (!_r)) {
207
-		LM_ERR("invalid parameter\n");
208
-		return -1;
209
-	}
210
-
211
-	if (db_mysql_get_columns(_h, _r) < 0) {
212
-		LM_ERR("error while getting column names\n");
213
-		return -2;
214
-	}
215
-
216
-	if (db_mysql_convert_rows(_h, _r) < 0) {
217
-		LM_ERR("error while converting rows\n");
218
-		db_free_columns(_r);
219
-		return -3;
220
-	}
221
-	return 0;
222
-}
223
-
224
-
225
-/*!
226
- * \brief Allocate new result set with private structure
227
- * \return db1_res_t object on success, NULL on failure
228
- */
229
-db1_res_t* db_mysql_new_result(void)
230
-{
231
-	db1_res_t* obj;
232
-
233
-	obj = db_new_result();
234
-	if (!obj)
235
-		return NULL;
236
-	RES_PTR(obj) = pkg_malloc(sizeof(struct my_res));
237
-	if (!RES_PTR(obj)) {
238
-		db_free_result(obj);
239
-		return NULL;
240
-	}
241
-	return obj;
242
-}
Browse code

db_mysql: updated include paths for libmysqlclient

- direct use of mysql_config, the old substitution done in module
Makefile can break the includes of libmysqlclient files
- reported by Ian Yu-Hsun Lin, GH#419

Daniel-Constantin Mierla authored on 26/11/2015 23:03:26
Showing 1 changed files
... ...
@@ -30,7 +30,7 @@
30 30
 
31 31
 
32 32
 #include <string.h>
33
-#include <mysql/mysql.h>
33
+#include <mysql.h>
34 34
 #include "../../lib/srdb1/db_res.h"
35 35
 #include "../../mem/mem.h"
36 36
 #include "../../dprint.h"
Browse code

db_mysql: Remove SVN ID's, remove history sections

Olle E. Johansson authored on 11/03/2015 15:26:21
Showing 1 changed files
... ...
@@ -1,6 +1,4 @@
1 1
 /* 
2
- * $Id$ 
3
- *
4 2
  * MySQL module result related functions
5 3
  *
6 4
  * Copyright (C) 2001-2003 FhG Fokus
Browse code

all: updated FSF address in GPL text

Anthony Messina authored on 04/07/2014 09:36:37 • Daniel-Constantin Mierla committed on 04/07/2014 09:37:36
Showing 1 changed files
... ...
@@ -20,7 +20,7 @@
20 20
  *
21 21
  * You should have received a copy of the GNU General Public License 
22 22
  * along with this program; if not, write to the Free Software 
23
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
24 24
  */
25 25
 
26 26
 
Browse code

db_mysql: properly free db result structure if db_mysql_convert_result() fails

- reported by Torrey Searle, FS#420

Daniel-Constantin Mierla authored on 16/04/2014 17:43:45
Showing 1 changed files
... ...
@@ -69,6 +69,7 @@ int db_mysql_get_columns(const db1_con_t* _h, db1_res_t* _r)
69 69
 	}
70 70
 	
71 71
 	if (db_allocate_columns(_r, RES_COL_N(_r)) != 0) {
72
+		RES_COL_N(_r) = 0;
72 73
 		LM_ERR("could not allocate columns\n");
73 74
 		return -3;
74 75
 	}
... ...
@@ -173,6 +174,7 @@ static inline int db_mysql_convert_rows(const db1_con_t* _h, db1_res_t* _r)
173 174
 
174 175
 	if (db_allocate_rows(_r) < 0) {
175 176
 		LM_ERR("could not allocate rows");
177
+		RES_ROW_N(_r) = 0;
176 178
 		return -2;
177 179
 	}
178 180
 
Browse code

db_mysql: fix segfault when recursive queries are made

The MySQL result object (MYSQL_RES) should not be stored within the
srdb1 connection object, but rather within the srdb1 result object.
Otherwise recursive queries overwrite each other's result sets, which
results in segfault.

Richard Fuchs authored on 10/04/2013 13:34:49
Showing 1 changed files
... ...
@@ -73,7 +73,7 @@ int db_mysql_get_columns(const db1_con_t* _h, db1_res_t* _r)
73 73
 		return -3;
74 74
 	}
75 75
 
76
-	fields = mysql_fetch_fields(CON_RESULT(_h));
76
+	fields = mysql_fetch_fields(RES_RESULT(_r));
77 77
 	for(col = 0; col < RES_COL_N(_r); col++) {
78 78
 		RES_NAMES(_r)[col] = (str*)pkg_malloc(sizeof(str));
79 79
 		if (! RES_NAMES(_r)[col]) {
... ...
@@ -164,7 +164,7 @@ static inline int db_mysql_convert_rows(const db1_con_t* _h, db1_res_t* _r)
164 164
 		return -1;
165 165
 	}
166 166
 
167
-	RES_ROW_N(_r) = mysql_num_rows(CON_RESULT(_h));
167
+	RES_ROW_N(_r) = mysql_num_rows(RES_RESULT(_r));
168 168
 	if (!RES_ROW_N(_r)) {
169 169
 		LM_DBG("no rows returned from the query\n");
170 170
 		RES_ROWS(_r) = 0;
... ...
@@ -177,8 +177,8 @@ static inline int db_mysql_convert_rows(const db1_con_t* _h, db1_res_t* _r)
177 177
 	}
178 178
 
179 179
 	for(row = 0; row < RES_ROW_N(_r); row++) {
180
-		CON_ROW(_h) = mysql_fetch_row(CON_RESULT(_h));
181
-		if (!CON_ROW(_h)) {
180
+		RES_ROW(_r) = mysql_fetch_row(RES_RESULT(_r));
181
+		if (!RES_ROW(_r)) {
182 182
 			LM_ERR("driver error: %s\n", mysql_error(CON_CONNECTION(_h)));
183 183
 			RES_ROW_N(_r) = row;
184 184
 			db_free_rows(_r);
... ...
@@ -221,3 +221,22 @@ int db_mysql_convert_result(const db1_con_t* _h, db1_res_t* _r)
221 221
 	return 0;
222 222
 }
223 223
 
224
+
225
+/*!
226
+ * \brief Allocate new result set with private structure
227
+ * \return db1_res_t object on success, NULL on failure
228
+ */
229
+db1_res_t* db_mysql_new_result(void)
230
+{
231
+	db1_res_t* obj;
232
+
233
+	obj = db_new_result();
234
+	if (!obj)
235
+		return NULL;
236
+	RES_PTR(obj) = pkg_malloc(sizeof(struct my_res));
237
+	if (!RES_PTR(obj)) {
238
+		db_free_result(obj);
239
+		return NULL;
240
+	}
241
+	return obj;
242
+}
Browse code

DB_* renamed to DB1_* in files originating from kamailio/db_mysql.

Jan Janak authored on 16/02/2009 22:17:48
Showing 1 changed files
... ...
@@ -97,34 +97,34 @@ int db_mysql_get_columns(const db1_con_t* _h, db1_res_t* _r)
97 97
 			case MYSQL_TYPE_LONG:
98 98
 			case MYSQL_TYPE_INT24:
99 99
 			case MYSQL_TYPE_TIMESTAMP:
100
-				LM_DBG("use DB_INT result type\n");
101
-				RES_TYPES(_r)[col] = DB_INT;
100
+				LM_DBG("use DB1_INT result type\n");
101
+				RES_TYPES(_r)[col] = DB1_INT;
102 102
 				break;
103 103
 
104 104
 			case MYSQL_TYPE_LONGLONG:
105
-				LM_DBG("use DB_BIGINT result type\n");
106
-				RES_TYPES(_r)[col] = DB_BIGINT;
105
+				LM_DBG("use DB1_BIGINT result type\n");
106
+				RES_TYPES(_r)[col] = DB1_BIGINT;
107 107
 				break;
108 108
 
109 109
 			case MYSQL_TYPE_FLOAT:
110 110
 			case MYSQL_TYPE_DOUBLE:
111
-				LM_DBG("use DB_DOUBLE result type\n");
112
-				RES_TYPES(_r)[col] = DB_DOUBLE;
111
+				LM_DBG("use DB1_DOUBLE result type\n");
112
+				RES_TYPES(_r)[col] = DB1_DOUBLE;
113 113
 				break;
114 114
 
115 115
 			case MYSQL_TYPE_DATETIME:
116
-				LM_DBG("use DB_DATETIME result type\n");
117
-				RES_TYPES(_r)[col] = DB_DATETIME;
116
+				LM_DBG("use DB1_DATETIME result type\n");
117
+				RES_TYPES(_r)[col] = DB1_DATETIME;
118 118
 				break;
119 119
 
120 120
 			case MYSQL_TYPE_BLOB:
121
-				LM_DBG("use DB_BLOB result type\n");
122
-				RES_TYPES(_r)[col] = DB_BLOB;
121
+				LM_DBG("use DB1_BLOB result type\n");
122
+				RES_TYPES(_r)[col] = DB1_BLOB;
123 123
 				break;
124 124
 
125 125
 			case FIELD_TYPE_SET:
126
-				LM_DBG("use DB_BITMAP result type\n");
127
-				RES_TYPES(_r)[col] = DB_BITMAP;
126
+				LM_DBG("use DB1_BITMAP result type\n");
127
+				RES_TYPES(_r)[col] = DB1_BITMAP;
128 128
 				break;
129 129
 
130 130
 			case MYSQL_TYPE_DECIMAL:
... ...
@@ -133,15 +133,15 @@ int db_mysql_get_columns(const db1_con_t* _h, db1_res_t* _r)
133 133
 			#endif
134 134
 			case MYSQL_TYPE_STRING:
135 135
 			case MYSQL_TYPE_VAR_STRING:
136
-				LM_DBG("use DB_STRING result type\n");
137
-				RES_TYPES(_r)[col] = DB_STRING;
136
+				LM_DBG("use DB1_STRING result type\n");
137
+				RES_TYPES(_r)[col] = DB1_STRING;
138 138
 				break;
139 139
 
140 140
 			default:
141 141
 				LM_WARN("unhandled data type column (%.*s) type id (%d), "
142
-						"use DB_STRING as default\n", RES_NAMES(_r)[col]->len,
142
+						"use DB1_STRING as default\n", RES_NAMES(_r)[col]->len,
143 143
 						RES_NAMES(_r)[col]->s, fields[col].type);
144
-				RES_TYPES(_r)[col] = DB_STRING;
144
+				RES_TYPES(_r)[col] = DB1_STRING;
145 145
 				break;
146 146
 		}
147 147
 	}
Browse code

db_res renamed to db1_res in files originating from kamailio/db_mysql.

The structure db_res has been renamed in lib/srdb1 to db1_res, thus we need to
change the name of the structure in all files originating from
kamailio/modules/db_mysql (and using lib/srdb1).

Jan Janak authored on 16/02/2009 22:13:16
Showing 1 changed files
... ...
@@ -50,7 +50,7 @@
50 50
  * \param _r database result set
51 51
  * \return 0 on success, negative on failure
52 52
  */
53
-int db_mysql_get_columns(const db1_con_t* _h, db_res_t* _r)
53
+int db_mysql_get_columns(const db1_con_t* _h, db1_res_t* _r)
54 54
 {
55 55
 	int col;
56 56
 	MYSQL_FIELD* fields;
... ...
@@ -155,7 +155,7 @@ int db_mysql_get_columns(const db1_con_t* _h, db_res_t* _r)
155 155
  * \param _r database result set
156 156
  * \return 0 on success, negative on failure
157 157
  */
158
-static inline int db_mysql_convert_rows(const db1_con_t* _h, db_res_t* _r)
158
+static inline int db_mysql_convert_rows(const db1_con_t* _h, db1_res_t* _r)
159 159
 {
160 160
 	int row;
161 161
 
... ...
@@ -201,7 +201,7 @@ static inline int db_mysql_convert_rows(const db1_con_t* _h, db_res_t* _r)
201 201
  * \param _r database result
202 202
  * \return 0 on success, negative on failure
203 203
  */
204
-int db_mysql_convert_result(const db1_con_t* _h, db_res_t* _r)
204
+int db_mysql_convert_result(const db1_con_t* _h, db1_res_t* _r)
205 205
 {
206 206
 	if ((!_h) || (!_r)) {
207 207
 		LM_ERR("invalid parameter\n");
Browse code

db_con renamed to db1_con in files originating from kamailio/db_mysql.

The structure db_con has been renamed in lib/srdb1 to db1_con, thus we
need to change the name of the structure in all files originating from
kamailio/modules/db_mysql (and using lib/srdb1).

Jan Janak authored on 16/02/2009 22:09:32
Showing 1 changed files
... ...
@@ -50,7 +50,7 @@
50 50
  * \param _r database result set
51 51
  * \return 0 on success, negative on failure
52 52
  */
53
-int db_mysql_get_columns(const db_con_t* _h, db_res_t* _r)
53
+int db_mysql_get_columns(const db1_con_t* _h, db_res_t* _r)
54 54
 {
55 55
 	int col;
56 56
 	MYSQL_FIELD* fields;
... ...
@@ -155,7 +155,7 @@ int db_mysql_get_columns(const db_con_t* _h, db_res_t* _r)
155 155
  * \param _r database result set
156 156
  * \return 0 on success, negative on failure
157 157
  */
158
-static inline int db_mysql_convert_rows(const db_con_t* _h, db_res_t* _r)
158
+static inline int db_mysql_convert_rows(const db1_con_t* _h, db_res_t* _r)
159 159
 {
160 160
 	int row;
161 161
 
... ...
@@ -201,7 +201,7 @@ static inline int db_mysql_convert_rows(const db_con_t* _h, db_res_t* _r)
201 201
  * \param _r database result
202 202
  * \return 0 on success, negative on failure
203 203
  */
204
-int db_mysql_convert_result(const db_con_t* _h, db_res_t* _r)
204
+int db_mysql_convert_result(const db1_con_t* _h, db_res_t* _r)
205 205
 {
206 206
 	if ((!_h) || (!_r)) {
207 207
 		LM_ERR("invalid parameter\n");
Browse code

Integration of both modules, first step.

* Defines protecting header files from double inclusion fixed to match
filenames.
* Linked the module also with srdb1
* Fixed path to header files in lib/srdb1.
* Filenames of local included header files prefixed with km_ to match
their real filenames

Jan Janak authored on 16/02/2009 21:58:33
Showing 1 changed files
... ...
@@ -33,12 +33,12 @@
33 33
 
34 34
 #include <string.h>
35 35
 #include <mysql/mysql.h>
36
-#include "../../db/db_res.h"
36
+#include "../../lib/srdb1/db_res.h"
37 37
 #include "../../mem/mem.h"
38 38
 #include "../../dprint.h"
39
-#include "row.h"
40
-#include "my_con.h"
41
-#include "res.h"
39
+#include "km_row.h"
40
+#include "km_my_con.h"
41
+#include "km_res.h"
42 42
 
43 43
 
44 44
 /*!
Browse code

- unify common rows and row allocation functionality in the DB API core

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@5362 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt authored on 15/12/2008 16:33:22
Showing 1 changed files
... ...
@@ -157,7 +157,7 @@ int db_mysql_get_columns(const db_con_t* _h, db_res_t* _r)
157 157
  */
158 158
 static inline int db_mysql_convert_rows(const db_con_t* _h, db_res_t* _r)
159 159
 {
160
-	int row, len;
160
+	int row;
161 161
 
162 162
 	if ((!_h) || (!_r)) {
163 163
 		LM_ERR("invalid parameter\n");
... ...
@@ -171,14 +171,10 @@ static inline int db_mysql_convert_rows(const db_con_t* _h, db_res_t* _r)
171 171
 		return 0;
172 172
 	}
173 173
 
174
-	len = sizeof(db_row_t) * RES_ROW_N(_r);
175
-	RES_ROWS(_r) = (struct db_row*)pkg_malloc(len);
176
-	if (!RES_ROWS(_r)) {
177
-		LM_ERR("no private memory left\n");
174
+	if (db_allocate_rows(_r) < 0) {
175
+		LM_ERR("could not allocate rows");
178 176
 		return -2;
179 177
 	}
180
-	LM_DBG("allocate %d bytes for rows at %p\n", len, RES_ROWS(_r));
181
-	memset(RES_ROWS(_r), 0, len);
182 178
 
183 179
 	for(row = 0; row < RES_ROW_N(_r); row++) {
184 180
 		CON_ROW(_h) = mysql_fetch_row(CON_RESULT(_h));
Browse code

- fix a few errors in doxygen documentation - sync one function definitions variables with declaration

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@5254 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt authored on 25/11/2008 09:34:15
Showing 1 changed files
... ...
@@ -41,8 +41,14 @@
41 41
 #include "res.h"
42 42
 
43 43
 
44
-/*! \brief
45
- * Get and convert columns from a result
44
+/*!
45
+ * \brief Get and convert columns from a result
46
+ *
47
+ * Get and convert columns from a result, fills the result structure
48
+ * with data from the database.
49
+ * \param _h database connection
50
+ * \param _r database result set
51
+ * \return 0 on success, negative on failure
46 52
  */
47 53
 int db_mysql_get_columns(const db_con_t* _h, db_res_t* _r)
48 54
 {
... ...
@@ -143,8 +149,11 @@ int db_mysql_get_columns(const db_con_t* _h, db_res_t* _r)
143 149
 }
144 150
 
145 151
 
146
-/*! \brief
147
- * Convert rows from mysql to db API representation
152
+/*!
153
+ * \brief Convert rows from mysql to db API representation
154
+ * \param _h database connection
155
+ * \param _r database result set
156
+ * \return 0 on success, negative on failure
148 157
  */
149 158
 static inline int db_mysql_convert_rows(const db_con_t* _h, db_res_t* _r)
150 159
 {
... ...
@@ -190,8 +199,11 @@ static inline int db_mysql_convert_rows(const db_con_t* _h, db_res_t* _r)
190 199
 }
191 200
 
192 201
 
193
-/*! \brief
194
- * Fill the structure with data from database
202
+/*!
203
+ * \brief Fill the result structure with data from database
204
+ * \param _h database connection
205
+ * \param _r database result
206
+ * \return 0 on success, negative on failure
195 207
  */
196 208
 int db_mysql_convert_result(const db_con_t* _h, db_res_t* _r)
197 209
 {
Browse code

- initial support for BIGINT database in DB core and SQL based database modules, closes patch #2101659 - some tests for mysql were done, but more testing, especially for the postgres and unixodbc would be appreciated - Todo: fix other DB modules, at the moment some warnings are printed during compilation because of the unhandled BIGINT state

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4928 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt authored on 16/09/2008 16:44:10
Showing 1 changed files
... ...
@@ -90,12 +90,16 @@ int db_mysql_get_columns(const db_con_t* _h, db_res_t* _r)
90 90
 			case MYSQL_TYPE_SHORT:
91 91
 			case MYSQL_TYPE_LONG:
92 92
 			case MYSQL_TYPE_INT24:
93
-			case MYSQL_TYPE_LONGLONG:
94 93
 			case MYSQL_TYPE_TIMESTAMP:
95 94
 				LM_DBG("use DB_INT result type\n");
96 95
 				RES_TYPES(_r)[col] = DB_INT;
97 96
 				break;
98 97
 
98
+			case MYSQL_TYPE_LONGLONG:
99
+				LM_DBG("use DB_BIGINT result type\n");
100
+				RES_TYPES(_r)[col] = DB_BIGINT;
101
+				break;
102
+
99 103
 			case MYSQL_TYPE_FLOAT:
100 104
 			case MYSQL_TYPE_DOUBLE:
101 105
 				LM_DBG("use DB_DOUBLE result type\n");
Browse code

- evaluate DECIMAL (and NEW_DECIMAL) type a DB_STRING, and not DB_INT - patch from Alex Hermann, related to #2111861

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4901 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt authored on 15/09/2008 10:26:35
Showing 1 changed files
... ...
@@ -91,10 +91,6 @@ int db_mysql_get_columns(const db_con_t* _h, db_res_t* _r)
91 91
 			case MYSQL_TYPE_LONG:
92 92
 			case MYSQL_TYPE_INT24:
93 93
 			case MYSQL_TYPE_LONGLONG:
94
-			case MYSQL_TYPE_DECIMAL:
95
-			#if MYSQL_VERSION_ID > 49999
96
-			case MYSQL_TYPE_NEWDECIMAL:
97
-			#endif
98 94
 			case MYSQL_TYPE_TIMESTAMP:
99 95
 				LM_DBG("use DB_INT result type\n");
100 96
 				RES_TYPES(_r)[col] = DB_INT;
... ...
@@ -121,6 +117,10 @@ int db_mysql_get_columns(const db_con_t* _h, db_res_t* _r)
121 117
 				RES_TYPES(_r)[col] = DB_BITMAP;
122 118
 				break;
123 119
 
120
+			case MYSQL_TYPE_DECIMAL:
121
+			#if MYSQL_VERSION_ID > 49999
122
+			case MYSQL_TYPE_NEWDECIMAL:
123
+			#endif
124 124
 			case MYSQL_TYPE_STRING:
125 125
 			case MYSQL_TYPE_VAR_STRING:
126 126
 				LM_DBG("use DB_STRING result type\n");
Browse code

- fixed compile error - MYSQL_TYPE_NEWDECIMAL date type is supported only starting with mysql 5.0, Reported by Andrew Pogrebennyk. related to opensips bug 2085158, credits to Bogdan

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4801 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt authored on 02/09/2008 08:48:31
Showing 1 changed files
... ...
@@ -92,7 +92,9 @@ int db_mysql_get_columns(const db_con_t* _h, db_res_t* _r)
92 92
 			case MYSQL_TYPE_INT24:
93 93
 			case MYSQL_TYPE_LONGLONG:
94 94
 			case MYSQL_TYPE_DECIMAL:
95
+			#if MYSQL_VERSION_ID > 49999
95 96
 			case MYSQL_TYPE_NEWDECIMAL:
97
+			#endif
96 98
 			case MYSQL_TYPE_TIMESTAMP:
97 99
 				LM_DBG("use DB_INT result type\n");
98 100
 				RES_TYPES(_r)[col] = DB_INT;
Browse code

- port from opensips r4526, credits goes to bogdan - 64bits compile warnings fixed

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4618 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt authored on 06/08/2008 15:32:44
Showing 1 changed files
... ...
@@ -75,8 +75,8 @@ int db_mysql_get_columns(const db_con_t* _h, db_res_t* _r)
75 75
 			db_free_columns(_r);
76 76
 			return -4;
77 77
 		}
78
-		LM_DBG("allocate %d bytes for RES_NAMES[%d] at %p\n", sizeof(str), col,
79
-				RES_NAMES(_r)[col]);
78
+		LM_DBG("allocate %lu bytes for RES_NAMES[%d] at %p\n",
79
+				(unsigned long)sizeof(str), col, RES_NAMES(_r)[col]);
80 80
 
81 81
 		/* The pointer that is here returned is part of the result structure. */
82 82
 		RES_NAMES(_r)[col]->s = fields[col].name;
Browse code

- change name in copyright headers

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4518 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt authored on 28/07/2008 15:39:28
Showing 1 changed files
... ...
@@ -6,14 +6,14 @@
6 6
  * Copyright (C) 2001-2003 FhG Fokus
7 7
  * Copyright (C) 2007-2008 1&1 Internet AG
8 8
  *
9
- * This file is part of openser, a free SIP server.
9
+ * This file is part of Kamailio, a free SIP server.
10 10
  *
11
- * openser is free software; you can redistribute it and/or modify
11
+ * Kamailio is free software; you can redistribute it and/or modify
12 12
  * it under the terms of the GNU General Public License as published by
13 13
  * the Free Software Foundation; either version 2 of the License, or
14 14
  * (at your option) any later version
15 15
  *
16
- * openser is distributed in the hope that it will be useful,
16
+ * Kamailio is distributed in the hope that it will be useful,
17 17
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 18
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 19
  * GNU General Public License for more details.
Browse code

- small doxygen updates (group, syntax), small docs update - patch provided from Olle E. Johansson, closes #2025079

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4505 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt authored on 24/07/2008 15:20:11
Showing 1 changed files
... ...
@@ -24,6 +24,13 @@
24 24
  */
25 25
 
26 26
 
27
+/*! \file
28
+ *  \brief DB_MYSQL :: Result related functions
29
+ *  \ingroup db_mysql
30
+ *  Module: \ref db_mysql
31
+ */
32
+
33
+
27 34
 #include <string.h>
28 35
 #include <mysql/mysql.h>
29 36
 #include "../../db/db_res.h"
... ...
@@ -34,7 +41,7 @@
34 41
 #include "res.h"
35 42
 
36 43
 
37
-/**
44
+/*! \brief
38 45
  * Get and convert columns from a result
39 46
  */
40 47
 int db_mysql_get_columns(const db_con_t* _h, db_res_t* _r)
... ...
@@ -130,7 +137,7 @@ int db_mysql_get_columns(const db_con_t* _h, db_res_t* _r)
130 137
 }
131 138
 
132 139
 
133
-/**
140
+/*! \brief
134 141
  * Convert rows from mysql to db API representation
135 142
  */
136 143
 static inline int db_mysql_convert_rows(const db_con_t* _h, db_res_t* _r)
... ...
@@ -177,7 +184,7 @@ static inline int db_mysql_convert_rows(const db_con_t* _h, db_res_t* _r)
177 184
 }
178 185
 
179 186
 
180
-/**
187
+/*! \brief
181 188
  * Fill the structure with data from database
182 189
  */
183 190
 int db_mysql_convert_result(const db_con_t* _h, db_res_t* _r)
Browse code

- add a few more missing '\n' to debug messages

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4163 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt authored on 13/05/2008 12:00:36
Showing 1 changed files
... ...
@@ -155,7 +155,7 @@ static inline int db_mysql_convert_rows(const db_con_t* _h, db_res_t* _r)
155 155
 		LM_ERR("no private memory left\n");
156 156
 		return -2;
157 157
 	}
158
-	LM_DBG("allocate %d bytes for rows at %p", len, RES_ROWS(_r));
158
+	LM_DBG("allocate %d bytes for rows at %p\n", len, RES_ROWS(_r));
159 159
 	memset(RES_ROWS(_r), 0, len);
160 160
 
161 161
 	for(row = 0; row < RES_ROW_N(_r); row++) {
Browse code

- add a few missing '\n' to log messages

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4149 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt authored on 09/05/2008 15:50:17
Showing 1 changed files
... ...
@@ -56,7 +56,7 @@ int db_mysql_get_columns(const db_con_t* _h, db_res_t* _r)
56 56
 	}
57 57
 	
58 58
 	if (db_allocate_columns(_r, RES_COL_N(_r)) != 0) {
59
-		LM_ERR("could not allocate columns");
59
+		LM_ERR("could not allocate columns\n");
60 60
 		return -3;
61 61
 	}
62 62
 
... ...
@@ -87,34 +87,34 @@ int db_mysql_get_columns(const db_con_t* _h, db_res_t* _r)
87 87
 			case MYSQL_TYPE_DECIMAL:
88 88
 			case MYSQL_TYPE_NEWDECIMAL:
89 89
 			case MYSQL_TYPE_TIMESTAMP:
90
-				LM_DBG("use DB_INT result type");
90
+				LM_DBG("use DB_INT result type\n");
91 91
 				RES_TYPES(_r)[col] = DB_INT;
92 92
 				break;
93 93
 
94 94
 			case MYSQL_TYPE_FLOAT:
95 95
 			case MYSQL_TYPE_DOUBLE:
96
-				LM_DBG("use DB_DOUBLE result type");
96
+				LM_DBG("use DB_DOUBLE result type\n");
97 97
 				RES_TYPES(_r)[col] = DB_DOUBLE;
98 98
 				break;
99 99
 
100 100
 			case MYSQL_TYPE_DATETIME:
101
-				LM_DBG("use DB_DATETIME result type");
101
+				LM_DBG("use DB_DATETIME result type\n");
102 102
 				RES_TYPES(_r)[col] = DB_DATETIME;
103 103
 				break;
104 104
 
105 105
 			case MYSQL_TYPE_BLOB:
106
-				LM_DBG("use DB_BLOB result type");
106
+				LM_DBG("use DB_BLOB result type\n");
107 107
 				RES_TYPES(_r)[col] = DB_BLOB;
108 108
 				break;
109 109
 
110 110
 			case FIELD_TYPE_SET:
111
-				LM_DBG("use DB_BITMAP result type");
111
+				LM_DBG("use DB_BITMAP result type\n");
112 112
 				RES_TYPES(_r)[col] = DB_BITMAP;
113 113
 				break;
114 114
 
115 115
 			case MYSQL_TYPE_STRING:
116 116
 			case MYSQL_TYPE_VAR_STRING:
117
-				LM_DBG("use DB_STRING result type");
117
+				LM_DBG("use DB_STRING result type\n");
118 118
 				RES_TYPES(_r)[col] = DB_STRING;
119 119
 				break;
120 120
 
Browse code

- some synchronisations with db_postgres driver - move LAST_ROW incrementation to the end of the function, to only update after a successfull fetch - add two debug messages

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4138 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt authored on 08/05/2008 16:12:31
Showing 1 changed files
... ...
@@ -144,6 +144,7 @@ static inline int db_mysql_convert_rows(const db_con_t* _h, db_res_t* _r)
144 144
 
145 145
 	RES_ROW_N(_r) = mysql_num_rows(CON_RESULT(_h));
146 146
 	if (!RES_ROW_N(_r)) {
147
+		LM_DBG("no rows returned from the query\n");
147 148
 		RES_ROWS(_r) = 0;
148 149
 		return 0;
149 150
 	}
Browse code

- convert existing documentation to doxygen format - add some comments, some smaller cleanups - small adjustment of the fetch_result function to the postgres one, add one DBG message, renames a parameter

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4124 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt authored on 07/05/2008 16:36:48
Showing 1 changed files
... ...
@@ -34,7 +34,7 @@
34 34
 #include "res.h"
35 35
 
36 36
 
37
-/*
37
+/**
38 38
  * Get and convert columns from a result
39 39
  */
40 40
 int db_mysql_get_columns(const db_con_t* _h, db_res_t* _r)
... ...
@@ -130,7 +130,7 @@ int db_mysql_get_columns(const db_con_t* _h, db_res_t* _r)
130 130
 }
131 131
 
132 132
 
133
-/*
133
+/**
134 134
  * Convert rows from mysql to db API representation
135 135
  */
136 136
 static inline int db_mysql_convert_rows(const db_con_t* _h, db_res_t* _r)
... ...
@@ -154,8 +154,7 @@ static inline int db_mysql_convert_rows(const db_con_t* _h, db_res_t* _r)
154 154
 		LM_ERR("no private memory left\n");
155 155
 		return -2;
156 156
 	}
157
-	LM_DBG("allocate %d bytes for rows at %p", len,
158
-			RES_ROWS(_r));
157
+	LM_DBG("allocate %d bytes for rows at %p", len, RES_ROWS(_r));
159 158
 	memset(RES_ROWS(_r), 0, len);
160 159
 
161 160
 	for(row = 0; row < RES_ROW_N(_r); row++) {
... ...
@@ -177,7 +176,7 @@ static inline int db_mysql_convert_rows(const db_con_t* _h, db_res_t* _r)
177 176
 }
178 177
 
179 178
 
180
-/*
179
+/**
181 180
  * Fill the structure with data from database
182 181
  */
183 182
 int db_mysql_convert_result(const db_con_t* _h, db_res_t* _r)
Browse code

- extend debugging with result type information

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@3968 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt authored on 01/04/2008 08:54:30
Showing 1 changed files
... ...
@@ -87,34 +87,40 @@ int db_mysql_get_columns(const db_con_t* _h, db_res_t* _r)
87 87
 			case MYSQL_TYPE_DECIMAL:
88 88
 			case MYSQL_TYPE_NEWDECIMAL:
89 89
 			case MYSQL_TYPE_TIMESTAMP:
90
+				LM_DBG("use DB_INT result type");
90 91
 				RES_TYPES(_r)[col] = DB_INT;
91 92
 				break;
92 93
 
93 94
 			case MYSQL_TYPE_FLOAT:
94 95
 			case MYSQL_TYPE_DOUBLE:
96
+				LM_DBG("use DB_DOUBLE result type");
95 97
 				RES_TYPES(_r)[col] = DB_DOUBLE;
96 98
 				break;
97 99
 
98 100
 			case MYSQL_TYPE_DATETIME:
101
+				LM_DBG("use DB_DATETIME result type");
99 102
 				RES_TYPES(_r)[col] = DB_DATETIME;
100 103
 				break;
101 104
 
102 105
 			case MYSQL_TYPE_BLOB:
106
+				LM_DBG("use DB_BLOB result type");
103 107
 				RES_TYPES(_r)[col] = DB_BLOB;
104 108
 				break;
105 109
 
106 110
 			case FIELD_TYPE_SET:
111
+				LM_DBG("use DB_BITMAP result type");
107 112
 				RES_TYPES(_r)[col] = DB_BITMAP;
108 113
 				break;
109 114
 
110 115
 			case MYSQL_TYPE_STRING:
111 116
 			case MYSQL_TYPE_VAR_STRING:
117
+				LM_DBG("use DB_STRING result type");
112 118
 				RES_TYPES(_r)[col] = DB_STRING;
113 119
 				break;
114 120
 
115 121
 			default:
116 122
 				LM_WARN("unhandled data type column (%.*s) type id (%d), "
117
-						"use STRING as default\n", RES_NAMES(_r)[col]->len,
123
+						"use DB_STRING as default\n", RES_NAMES(_r)[col]->len,
118 124
 						RES_NAMES(_r)[col]->s, fields[col].type);
119 125
 				RES_TYPES(_r)[col] = DB_STRING;
120 126
 				break;
Browse code

- rename database modules to use the 'db_' prefix

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@3638 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt authored on 06/02/2008 13:10:03
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,196 @@
1
+/* 
2
+ * $Id$ 
3
+ *
4
+ * MySQL module result related functions
5
+ *
6
+ * Copyright (C) 2001-2003 FhG Fokus
7
+ * Copyright (C) 2007-2008 1&1 Internet AG
8
+ *
9
+ * This file is part of openser, a free SIP server.
10
+ *
11
+ * openser is free software; you can redistribute it and/or modify
12
+ * it under the terms of the GNU General Public License as published by
13
+ * the Free Software Foundation; either version 2 of the License, or
14
+ * (at your option) any later version
15
+ *
16
+ * openser is distributed in the hope that it will be useful,
17
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
+ * GNU General Public License for more details.
20
+ *
21
+ * You should have received a copy of the GNU General Public License 
22
+ * along with this program; if not, write to the Free Software 
23
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24
+ */
25
+
26
+
27
+#include <string.h>
28
+#include <mysql/mysql.h>
29
+#include "../../db/db_res.h"
30
+#include "../../mem/mem.h"
31
+#include "../../dprint.h"
32
+#include "row.h"
33
+#include "my_con.h"
34
+#include "res.h"
35
+
36
+
37
+/*
38
+ * Get and convert columns from a result
39
+ */
40
+int db_mysql_get_columns(const db_con_t* _h, db_res_t* _r)
41
+{
42
+	int col;
43
+	MYSQL_FIELD* fields;
44
+
45
+	if ((!_h) || (!_r)) {
46
+		LM_ERR("invalid parameter\n");
47
+		return -1;
48
+	}
49
+
50
+	RES_COL_N(_r) = mysql_field_count(CON_CONNECTION(_h));
51
+	if (!RES_COL_N(_r)) {
52
+		LM_ERR("no columns returned from the query\n");
53
+		return -2;
54
+	} else {
55
+		LM_DBG("%d columns returned from the query\n", RES_COL_N(_r));
56
+	}
57
+	
58
+	if (db_allocate_columns(_r, RES_COL_N(_r)) != 0) {
59
+		LM_ERR("could not allocate columns");
60
+		return -3;
61
+	}
62
+
63
+	fields = mysql_fetch_fields(CON_RESULT(_h));
64
+	for(col = 0; col < RES_COL_N(_r); col++) {
65
+		RES_NAMES(_r)[col] = (str*)pkg_malloc(sizeof(str));
66
+		if (! RES_NAMES(_r)[col]) {
67
+			LM_ERR("no private memory left\n");
68
+			db_free_columns(_r);
69
+			return -4;
70
+		}
71
+		LM_DBG("allocate %d bytes for RES_NAMES[%d] at %p\n", sizeof(str), col,
72
+				RES_NAMES(_r)[col]);
73
+
74
+		/* The pointer that is here returned is part of the result structure. */