Browse code

- obsolete database example removed

Jan Janak authored on 19/07/2006 17:10:42
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,278 +0,0 @@
1
-/*
2
- * $Id$
3
- *
4
- * Copyright (C) 2001-2003 FhG Fokus
5
- *
6
- * This file is part of ser, a free SIP server.
7
- *
8
- * ser is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option) any later version
12
- *
13
- * For a license to use the ser software under conditions
14
- * other than those described here, or to purchase support for this
15
- * software, please contact iptel.org by e-mail at the following addresses:
16
- *    info@iptel.org
17
- *
18
- * ser is distributed in the hope that it will be useful,
19
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
- * GNU General Public License for more details.
22
- *
23
- * You should have received a copy of the GNU General Public License 
24
- * along with this program; if not, write to the Free Software 
25
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
- */
27
-
28
-
29
-#include "../../sr_module.h"
30
-#include <stdio.h>
31
-#include "../../db/db.h"
32
-
33
-
34
-#define DB_URL   "mysql://root@localhost/ser"
35
-#define DB_TABLE "location"
36
-
37
-#define TRUE 1
38
-#define FALSE 0
39
-
40
-
41
-/*
42
- * Database module client example
43
- */
44
-
45
-
46
-static struct module_exports dbex_exports= {	
47
-	"DBExample", 
48
-	(char*[]) {
49
-	},
50
-	(cmd_function[]) {
51
-	},
52
-	(int[]) {
53
-	},
54
-	(fixup_function[]) {
55
-	},
56
-	0,       /* number of functions*/
57
-	NULL,    /* Module parameter names */
58
-	NULL,    /* Module parameter types */
59
-	NULL,    /* Module parameter variable pointers */
60
-	0,       /* Number of module parameters */
61
-	0,       /* response function*/
62
-	0        /* destroy function */
63
-};
64
-
65
-
66
-static int print_res(db_res_t* _r)
67
-{
68
-	int i, j;
69
-
70
-	for(i = 0; i < RES_COL_N(_r); i++) {
71
-		printf("%s ", RES_NAMES(_r)[i]);
72
-	}
73
-	printf("\n");
74
-
75
-	for(i = 0; i < RES_ROW_N(_r); i++) {
76
-		for(j = 0; j < RES_COL_N(_r); j++) {
77
-			if (RES_ROWS(_r)[i].values[j].nul == TRUE) {
78
-				printf("NULL ");
79
-				continue;
80
-			}
81
-			switch(RES_ROWS(_r)[i].values[j].type) {
82
-			case DB_INT:
83
-				printf("%d ", RES_ROWS(_r)[i].values[j].val.int_val);
84
-				break;
85
-			case DB_DOUBLE:
86
-				printf("%f ", RES_ROWS(_r)[i].values[j].val.double_val);
87
-				break;
88
-			case DB_DATETIME:
89
-				printf("%s ", ctime(&(RES_ROWS(_r)[i].values[j].val.time_val)));
90
-				break;
91
-			case DB_STRING:
92
-				printf("%s ", RES_ROWS(_r)[i].values[j].val.string_val);
93
-				break;
94
-			case DB_STR:
95
-				printf("%.*s ", 
96
-				       RES_ROWS(_r)[i].values[j].val.str_val.len,
97
-				       RES_ROWS(_r)[i].values[j].val.str_val.s);
98
-				break;
99
-
100
-			case DB_BLOB:
101
-				printf("%.*s ",
102
-				       RES_ROWS(_r)[i].values[j].val.blob_val.len,
103
-				       RES_ROWS(_r)[i].values[j].val.blob_val.s);
104
-				break;
105
-
106
-			case DB_BITMAP:
107
-				printf("%d ", RES_ROWS(_r)[i].values[j].val.bitmap_val);
108
-				break;
109
-			}
110
-			
111
-		}
112
-		printf("\n");
113
-	}
114
-			
115
-	return TRUE;
116
-}
117
-
118
-
119
-
120
-
121
-
122
-struct module_exports* mod_register()
123
-{
124
-	     /*
125
-	      * Column names of table location
126
-	      */
127
-	db_key_t keys1[] = {"username", "contact", "q", "expire", "opaque", "flags" };
128
-	db_key_t keys2[] = {"username", "q"};
129
-	db_key_t keys3[] = {"username", "contact"};
130
-	db_key_t keys4[] = {"contact", "q"};
131
-
132
-	db_val_t vals1[] = { 
133
-		{ DB_STRING  , 0, { .string_val = "foo@bar.com" }              },
134
-		{ DB_STR     , 0, { .str_val    = { "real@foo.bar.com", 18 } } },
135
-		{ DB_DOUBLE  , 0, { .double_val = 1.2 }                        },
136
-		{ DB_DATETIME, 0, { .time_val   = 439826493 }                  },
137
-		{ DB_BLOB    , 0, { .blob_val   = { "hdslgkhas\0glksf", 17 } } },
138
-		{ DB_BITMAP  , 0, { .bitmap_val = FLAG_NAT | FLAG_INVITE }     }
139
-	};
140
-
141
-	db_val_t vals2[] = { 
142
-		{ DB_STRING  , 0, { .string_val = "foo2@bar2.com" }              },
143
-		{ DB_STR     , 0, { .str_val    = { "real2@foo.bar2.com", 18 } } },
144
-		{ DB_DOUBLE  , 0, { .double_val = 1.3 }                          },
145
-		{ DB_DATETIME, 0, { .time_val   = 12345 }                        },
146
-		{ DB_BLOB    , 0, { .blob_val   = { "\0a\0balkdfj", 10 }       } },
147
-                { DB_BITMAP  , 0, { .bitmap_val = FLAG_NAT, FLAG_NOT_INVITE }    }
148
-	};
149
-
150
-	db_val_t vals3[] = { 
151
-		{ DB_STRING  , 0, { .string_val = "foo3@bar3.com" }              },
152
-		{ DB_STR     , 0, { .str_val    = { "real3@foo.bar3.com", 18 } } },
153
-		{ DB_DOUBLE  , 0, { .double_val = 1.5 }                          },
154
-		{ DB_DATETIME, 0, { .time_val   = 123456 }                       },
155
-		{ DB_BLOB    , 0, { .blob_val   = { "halgkasdg\'", 10 }        } },
156
-                { DB_BITMAP  , 0, { .blob_val   = FLAG_NAT }                     }
157
-	};
158
-
159
-	db_val_t vals4[] = {
160
-		{ DB_STRING, 0, { .string_val = "foo2@bar2.com" } },
161
-		{ DB_DOUBLE, 0, { .double_val = 1.30 }            }
162
-	};
163
-		  
164
-	db_val_t vals5[] = {
165
-		{ DB_STRING, 0, { .string_val = "foo3@bar3.com" }      },
166
-		{ DB_STRING, 0, { .string_val = "real3@foo.bar3.com" } }
167
-	};
168
-
169
-	db_val_t vals6[] = {
170
-		{ DB_STRING, 0, { .string_val = "different@address.com" } },
171
-		{ DB_DOUBLE, 0, { .double_val = 2.5 }                     }
172
-	};
173
-
174
-	db_con_t* h;
175
-	db_res_t* res;
176
-
177
-	fprintf(stderr, "DBExample - registering...\n");
178
-
179
-	     /* The first call must be bind_dbmod
180
-	      * This call will search for functions
181
-	      * exported by a database module
182
-	      */
183
-	if (bind_dbmod()) {
184
-		fprintf(stderr, "Error while binding database module, did you forget to load a database module ?\n");
185
-		return &dbex_exports;
186
-	}
187
-
188
-	     /*
189
-	      * Create a database connection
190
-	      * DB_URL is database URL of form
191
-	      * mysql://user:password@host:port/database
192
-	      * The function returns handle, that
193
-	      * represents a database connection
194
-	      */
195
-	h = db_init(DB_URL);
196
-	if (!h) {
197
-		fprintf(stderr, "Error while initializing database connection\n");
198
-		return &dbex_exports;
199
-	}
200
-
201
-	     /* 
202
-	      * Specify a table name, that will
203
-	      * be used for manipulations
204
-	      */
205
-	if (db_use_table(h, DB_TABLE) < 0) {
206
-		fprintf(stderr, "Error while calling db_use_table\n");
207
-		return &dbex_exports;
208
-	}
209
-
210
-	     /* If you do not specify any keys and values to be
211
-	      * matched, all rows will be deleted
212
-	      */
213
-	if (db_delete(h, NULL, NULL, NULL, 0) < 0) {
214
-		fprintf(stderr, "Error while flushing table\n");
215
-		return &dbex_exports;
216
-	}
217
-
218
-	if (db_insert(h, keys1, vals1, 6) < 0) {
219
-		fprintf(stderr, "Error while inserting line 1\n");
220
-		return &dbex_exports;
221
-	}
222
-
223
-	if (db_insert(h, keys1, vals2, 6) < 0) {
224
-		fprintf(stderr, "Error while inserting line 2\n");
225
-		return &dbex_exports;
226
-	}
227
-
228
-	if (db_insert(h, keys1, vals3, 6) < 0) {
229
-		fprintf(stderr, "Error while inserting line 3\n");
230
-		return &dbex_exports;
231
-	}
232
-
233
-	     /*
234
-	      * Let's delete middle line with
235
-	      * user = foo2@bar2.com and q = 1.3
236
-	      */
237
-	if (db_delete(h, keys2, NULL, vals4, 2) < 0) {
238
-		fprintf(stderr, "Error while deleting line\n");
239
-		return &dbex_exports;
240
-	}
241
-
242
-	     /*
243
-	      * Modify last line
244
-	      */
245
-	if (db_update(h, keys3, NULL, vals5, keys4, vals6, 2, 2) < 0) {
246
-		fprintf(stderr, "Error while modifying table\n");
247
-		return &dbex_exports;
248
-	}
249
-
250
-	     /*
251
-	      * Last but not least, dump the result of db_query
252
-	      */
253
-
254
-	if (db_query(h, NULL, NULL, NULL, NULL, 0, 0, NULL, &res) < 0) {
255
-		fprintf(stderr, "Error while querying table\n");
256
-		return &dbex_exports;
257
-	}
258
-
259
-
260
-	print_res(res);
261
-
262
-	     /*
263
-	      * Free the result because we don't need it
264
-	      * anymore
265
-	      */
266
-	if (db_free_result(h, res) < 0) {
267
-		fprintf(stderr, "Error while freeing result of query\n");
268
-		return &dbex_exports;
269
-	}
270
-
271
-	     /*
272
-	      * Close existing database connection
273
-	      * and free previously allocated 
274
-	      * memory
275
-	      */
276
-	db_close(h);
277
-	return &dbex_exports;
278
-}
Browse code

- Spelling checked - READMEs updated

Jan Janak authored on 24/08/2004 08:45:09
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * $Id$
3 3
  *
4
- * Copyright (C) 2001-2003 Fhg Fokus
4
+ * Copyright (C) 2001-2003 FhG Fokus
5 5
  *
6 6
  * This file is part of ser, a free SIP server.
7 7
  *
... ...
@@ -39,7 +39,7 @@
39 39
 
40 40
 
41 41
 /*
42
- * Dabase module client example
42
+ * Database module client example
43 43
  */
44 44
 
45 45
 
Browse code

free_query changed to free_result

Jan Janak authored on 04/08/2004 14:26:24
Showing 1 changed files
... ...
@@ -263,7 +263,7 @@ struct module_exports* mod_register()
263 263
 	      * Free the result because we don't need it
264 264
 	      * anymore
265 265
 	      */
266
-	if (db_free_query(h, res) < 0) {
266
+	if (db_free_result(h, res) < 0) {
267 267
 		fprintf(stderr, "Error while freeing result of query\n");
268 268
 		return &dbex_exports;
269 269
 	}
Browse code

- sql:// changed to mysql:// in all modules

Jan Janak authored on 03/11/2003 13:03:56
Showing 1 changed files
... ...
@@ -31,7 +31,7 @@
31 31
 #include "../../db/db.h"
32 32
 
33 33
 
34
-#define DB_URL   "sql://root@localhost/ser"
34
+#define DB_URL   "mysql://root@localhost/ser"
35 35
 #define DB_TABLE "location"
36 36
 
37 37
 #define TRUE 1
... ...
@@ -188,7 +188,7 @@ struct module_exports* mod_register()
188 188
 	     /*
189 189
 	      * Create a database connection
190 190
 	      * DB_URL is database URL of form
191
-	      * sql://user:password@host:port/database
191
+	      * mysql://user:password@host:port/database
192 192
 	      * The function returns handle, that
193 193
 	      * represents a database connection
194 194
 	      */
Browse code

- DB_BITMAP data type added

Jan Janak authored on 15/09/2003 22:34:28
Showing 1 changed files
... ...
@@ -102,6 +102,10 @@ static int print_res(db_res_t* _r)
102 102
 				       RES_ROWS(_r)[i].values[j].val.blob_val.len,
103 103
 				       RES_ROWS(_r)[i].values[j].val.blob_val.s);
104 104
 				break;
105
+
106
+			case DB_BITMAP:
107
+				printf("%d ", RES_ROWS(_r)[i].values[j].val.bitmap_val);
108
+				break;
105 109
 			}
106 110
 			
107 111
 		}
... ...
@@ -120,7 +124,7 @@ struct module_exports* mod_register()
120 124
 	     /*
121 125
 	      * Column names of table location
122 126
 	      */
123
-	db_key_t keys1[] = {"username", "contact", "q", "expire", "opaque" };
127
+	db_key_t keys1[] = {"username", "contact", "q", "expire", "opaque", "flags" };
124 128
 	db_key_t keys2[] = {"username", "q"};
125 129
 	db_key_t keys3[] = {"username", "contact"};
126 130
 	db_key_t keys4[] = {"contact", "q"};
... ...
@@ -130,7 +134,8 @@ struct module_exports* mod_register()
130 134
 		{ DB_STR     , 0, { .str_val    = { "real@foo.bar.com", 18 } } },
131 135
 		{ DB_DOUBLE  , 0, { .double_val = 1.2 }                        },
132 136
 		{ DB_DATETIME, 0, { .time_val   = 439826493 }                  },
133
-		{ DB_BLOB    , 0, { .blob_val   = { "hdslgkhas\0glksf", 17 } } }
137
+		{ DB_BLOB    , 0, { .blob_val   = { "hdslgkhas\0glksf", 17 } } },
138
+		{ DB_BITMAP  , 0, { .bitmap_val = FLAG_NAT | FLAG_INVITE }     }
134 139
 	};
135 140
 
136 141
 	db_val_t vals2[] = { 
... ...
@@ -138,7 +143,8 @@ struct module_exports* mod_register()
138 143
 		{ DB_STR     , 0, { .str_val    = { "real2@foo.bar2.com", 18 } } },
139 144
 		{ DB_DOUBLE  , 0, { .double_val = 1.3 }                          },
140 145
 		{ DB_DATETIME, 0, { .time_val   = 12345 }                        },
141
-		{ DB_BLOB    , 0, { .blob_val   = { "\0a\0balkdfj", 10 }       } }
146
+		{ DB_BLOB    , 0, { .blob_val   = { "\0a\0balkdfj", 10 }       } },
147
+                { DB_BITMAP  , 0, { .bitmap_val = FLAG_NAT, FLAG_NOT_INVITE }    }
142 148
 	};
143 149
 
144 150
 	db_val_t vals3[] = { 
... ...
@@ -146,7 +152,8 @@ struct module_exports* mod_register()
146 152
 		{ DB_STR     , 0, { .str_val    = { "real3@foo.bar3.com", 18 } } },
147 153
 		{ DB_DOUBLE  , 0, { .double_val = 1.5 }                          },
148 154
 		{ DB_DATETIME, 0, { .time_val   = 123456 }                       },
149
-		{ DB_BLOB    , 0, { .blob_val   = { "halgkasdg\'", 10 }        } }
155
+		{ DB_BLOB    , 0, { .blob_val   = { "halgkasdg\'", 10 }        } },
156
+                { DB_BITMAP  , 0, { .blob_val   = FLAG_NAT }                     }
150 157
 	};
151 158
 
152 159
 	db_val_t vals4[] = {
... ...
@@ -208,17 +215,17 @@ struct module_exports* mod_register()
208 215
 		return &dbex_exports;
209 216
 	}
210 217
 
211
-	if (db_insert(h, keys1, vals1, 5) < 0) {
218
+	if (db_insert(h, keys1, vals1, 6) < 0) {
212 219
 		fprintf(stderr, "Error while inserting line 1\n");
213 220
 		return &dbex_exports;
214 221
 	}
215 222
 
216
-	if (db_insert(h, keys1, vals2, 5) < 0) {
223
+	if (db_insert(h, keys1, vals2, 6) < 0) {
217 224
 		fprintf(stderr, "Error while inserting line 2\n");
218 225
 		return &dbex_exports;
219 226
 	}
220 227
 
221
-	if (db_insert(h, keys1, vals3, 5) < 0) {
228
+	if (db_insert(h, keys1, vals3, 6) < 0) {
222 229
 		fprintf(stderr, "Error while inserting line 3\n");
223 230
 		return &dbex_exports;
224 231
 	}
Browse code

user -> username

Jan Janak authored on 10/03/2003 16:06:07
Showing 1 changed files
... ...
@@ -120,9 +120,9 @@ struct module_exports* mod_register()
120 120
 	     /*
121 121
 	      * Column names of table location
122 122
 	      */
123
-	db_key_t keys1[] = {"user", "contact", "q", "expire", "opaque" };
124
-	db_key_t keys2[] = {"user", "q"};
125
-	db_key_t keys3[] = {"user", "contact"};
123
+	db_key_t keys1[] = {"username", "contact", "q", "expire", "opaque" };
124
+	db_key_t keys2[] = {"username", "q"};
125
+	db_key_t keys3[] = {"username", "contact"};
126 126
 	db_key_t keys4[] = {"contact", "q"};
127 127
 
128 128
 	db_val_t vals1[] = { 
Browse code

db_query, db_delete and db_update now accept additional parameter - operator. New function added - db_raw_query which accepts a raw SQL query and executes it.

Jan Janak authored on 28/11/2002 16:53:03
Showing 1 changed files
... ...
@@ -203,7 +203,7 @@ struct module_exports* mod_register()
203 203
 	     /* If you do not specify any keys and values to be
204 204
 	      * matched, all rows will be deleted
205 205
 	      */
206
-	if (db_delete(h, NULL, NULL, 0) < 0) {
206
+	if (db_delete(h, NULL, NULL, NULL, 0) < 0) {
207 207
 		fprintf(stderr, "Error while flushing table\n");
208 208
 		return &dbex_exports;
209 209
 	}
... ...
@@ -227,7 +227,7 @@ struct module_exports* mod_register()
227 227
 	      * Let's delete middle line with
228 228
 	      * user = foo2@bar2.com and q = 1.3
229 229
 	      */
230
-	if (db_delete(h, keys2, vals4, 2) < 0) {
230
+	if (db_delete(h, keys2, NULL, vals4, 2) < 0) {
231 231
 		fprintf(stderr, "Error while deleting line\n");
232 232
 		return &dbex_exports;
233 233
 	}
... ...
@@ -235,7 +235,7 @@ struct module_exports* mod_register()
235 235
 	     /*
236 236
 	      * Modify last line
237 237
 	      */
238
-	if (db_update(h, keys3, vals5, keys4, vals6, 2, 2) < 0) {
238
+	if (db_update(h, keys3, NULL, vals5, keys4, vals6, 2, 2) < 0) {
239 239
 		fprintf(stderr, "Error while modifying table\n");
240 240
 		return &dbex_exports;
241 241
 	}
... ...
@@ -244,7 +244,7 @@ struct module_exports* mod_register()
244 244
 	      * Last but not least, dump the result of db_query
245 245
 	      */
246 246
 
247
-	if (db_query(h, NULL, NULL, NULL, 0, 0, NULL, &res) < 0) {
247
+	if (db_query(h, NULL, NULL, NULL, NULL, 0, 0, NULL, &res) < 0) {
248 248
 		fprintf(stderr, "Error while querying table\n");
249 249
 		return &dbex_exports;
250 250
 	}
Browse code

GPLization banner introduced to *.[hc] files

Jiri Kuthan authored on 19/09/2002 12:23:52
Showing 1 changed files
... ...
@@ -1,7 +1,31 @@
1 1
 /*
2 2
  * $Id$
3
+ *
4
+ * Copyright (C) 2001-2003 Fhg Fokus
5
+ *
6
+ * This file is part of ser, a free SIP server.
7
+ *
8
+ * ser is free software; you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation; either version 2 of the License, or
11
+ * (at your option) any later version
12
+ *
13
+ * For a license to use the ser software under conditions
14
+ * other than those described here, or to purchase support for this
15
+ * software, please contact iptel.org by e-mail at the following addresses:
16
+ *    info@iptel.org
17
+ *
18
+ * ser is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License 
24
+ * along with this program; if not, write to the Free Software 
25
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
3 26
  */
4 27
 
28
+
5 29
 #include "../../sr_module.h"
6 30
 #include <stdio.h>
7 31
 #include "../../db/db.h"
Browse code

Example extended

Jan Janak authored on 09/08/2002 18:31:31
Showing 1 changed files
... ...
@@ -96,7 +96,7 @@ struct module_exports* mod_register()
96 96
 	     /*
97 97
 	      * Column names of table location
98 98
 	      */
99
-	db_key_t keys1[] = {"user", "contact", "q", "expire" };
99
+	db_key_t keys1[] = {"user", "contact", "q", "expire", "opaque" };
100 100
 	db_key_t keys2[] = {"user", "q"};
101 101
 	db_key_t keys3[] = {"user", "contact"};
102 102
 	db_key_t keys4[] = {"contact", "q"};
... ...
@@ -105,21 +105,24 @@ struct module_exports* mod_register()
105 105
 		{ DB_STRING  , 0, { .string_val = "foo@bar.com" }              },
106 106
 		{ DB_STR     , 0, { .str_val    = { "real@foo.bar.com", 18 } } },
107 107
 		{ DB_DOUBLE  , 0, { .double_val = 1.2 }                        },
108
-		{ DB_DATETIME, 0, { .time_val   = 439826493 }                  }
108
+		{ DB_DATETIME, 0, { .time_val   = 439826493 }                  },
109
+		{ DB_BLOB    , 0, { .blob_val   = { "hdslgkhas\0glksf", 17 } } }
109 110
 	};
110 111
 
111 112
 	db_val_t vals2[] = { 
112 113
 		{ DB_STRING  , 0, { .string_val = "foo2@bar2.com" }              },
113 114
 		{ DB_STR     , 0, { .str_val    = { "real2@foo.bar2.com", 18 } } },
114 115
 		{ DB_DOUBLE  , 0, { .double_val = 1.3 }                          },
115
-		{ DB_DATETIME, 0, { .time_val   = 12345 }                        }
116
+		{ DB_DATETIME, 0, { .time_val   = 12345 }                        },
117
+		{ DB_BLOB    , 0, { .blob_val   = { "\0a\0balkdfj", 10 }       } }
116 118
 	};
117 119
 
118 120
 	db_val_t vals3[] = { 
119 121
 		{ DB_STRING  , 0, { .string_val = "foo3@bar3.com" }              },
120 122
 		{ DB_STR     , 0, { .str_val    = { "real3@foo.bar3.com", 18 } } },
121 123
 		{ DB_DOUBLE  , 0, { .double_val = 1.5 }                          },
122
-		{ DB_DATETIME, 0, { .time_val   = 123456 }                       }
124
+		{ DB_DATETIME, 0, { .time_val   = 123456 }                       },
125
+		{ DB_BLOB    , 0, { .blob_val   = { "halgkasdg\'", 10 }        } }
123 126
 	};
124 127
 
125 128
 	db_val_t vals4[] = {
... ...
@@ -181,17 +184,17 @@ struct module_exports* mod_register()
181 184
 		return &dbex_exports;
182 185
 	}
183 186
 
184
-	if (db_insert(h, keys1, vals1, 4) < 0) {
187
+	if (db_insert(h, keys1, vals1, 5) < 0) {
185 188
 		fprintf(stderr, "Error while inserting line 1\n");
186 189
 		return &dbex_exports;
187 190
 	}
188 191
 
189
-	if (db_insert(h, keys1, vals2, 4) < 0) {
192
+	if (db_insert(h, keys1, vals2, 5) < 0) {
190 193
 		fprintf(stderr, "Error while inserting line 2\n");
191 194
 		return &dbex_exports;
192 195
 	}
193 196
 
194
-	if (db_insert(h, keys1, vals3, 4) < 0) {
197
+	if (db_insert(h, keys1, vals3, 5) < 0) {
195 198
 		fprintf(stderr, "Error while inserting line 3\n");
196 199
 		return &dbex_exports;
197 200
 	}
Browse code

Return values changed, blob support added

Jan Janak authored on 08/08/2002 17:25:32
Showing 1 changed files
... ...
@@ -72,6 +72,12 @@ static int print_res(db_res_t* _r)
72 72
 				       RES_ROWS(_r)[i].values[j].val.str_val.len,
73 73
 				       RES_ROWS(_r)[i].values[j].val.str_val.s);
74 74
 				break;
75
+
76
+			case DB_BLOB:
77
+				printf("%.*s ",
78
+				       RES_ROWS(_r)[i].values[j].val.blob_val.len,
79
+				       RES_ROWS(_r)[i].values[j].val.blob_val.s);
80
+				break;
75 81
 			}
76 82
 			
77 83
 		}
... ...
@@ -162,7 +168,7 @@ struct module_exports* mod_register()
162 168
 	      * Specify a table name, that will
163 169
 	      * be used for manipulations
164 170
 	      */
165
-	if (db_use_table(h, DB_TABLE) == FALSE) {
171
+	if (db_use_table(h, DB_TABLE) < 0) {
166 172
 		fprintf(stderr, "Error while calling db_use_table\n");
167 173
 		return &dbex_exports;
168 174
 	}
... ...
@@ -170,22 +176,22 @@ struct module_exports* mod_register()
170 176
 	     /* If you do not specify any keys and values to be
171 177
 	      * matched, all rows will be deleted
172 178
 	      */
173
-	if (db_delete(h, NULL, NULL, 0) == FALSE) {
179
+	if (db_delete(h, NULL, NULL, 0) < 0) {
174 180
 		fprintf(stderr, "Error while flushing table\n");
175 181
 		return &dbex_exports;
176 182
 	}
177 183
 
178
-	if (db_insert(h, keys1, vals1, 4) == FALSE) {
184
+	if (db_insert(h, keys1, vals1, 4) < 0) {
179 185
 		fprintf(stderr, "Error while inserting line 1\n");
180 186
 		return &dbex_exports;
181 187
 	}
182 188
 
183
-	if (db_insert(h, keys1, vals2, 4) == FALSE) {
189
+	if (db_insert(h, keys1, vals2, 4) < 0) {
184 190
 		fprintf(stderr, "Error while inserting line 2\n");
185 191
 		return &dbex_exports;
186 192
 	}
187 193
 
188
-	if (db_insert(h, keys1, vals3, 4) == FALSE) {
194
+	if (db_insert(h, keys1, vals3, 4) < 0) {
189 195
 		fprintf(stderr, "Error while inserting line 3\n");
190 196
 		return &dbex_exports;
191 197
 	}
... ...
@@ -194,7 +200,7 @@ struct module_exports* mod_register()
194 200
 	      * Let's delete middle line with
195 201
 	      * user = foo2@bar2.com and q = 1.3
196 202
 	      */
197
-	if (db_delete(h, keys2, vals4, 2) == FALSE) {
203
+	if (db_delete(h, keys2, vals4, 2) < 0) {
198 204
 		fprintf(stderr, "Error while deleting line\n");
199 205
 		return &dbex_exports;
200 206
 	}
... ...
@@ -202,7 +208,7 @@ struct module_exports* mod_register()
202 208
 	     /*
203 209
 	      * Modify last line
204 210
 	      */
205
-	if (db_update(h, keys3, vals5, keys4, vals6, 2, 2) == FALSE) {
211
+	if (db_update(h, keys3, vals5, keys4, vals6, 2, 2) < 0) {
206 212
 		fprintf(stderr, "Error while modifying table\n");
207 213
 		return &dbex_exports;
208 214
 	}
... ...
@@ -211,7 +217,7 @@ struct module_exports* mod_register()
211 217
 	      * Last but not least, dump the result of db_query
212 218
 	      */
213 219
 
214
-	if (db_query(h, NULL, NULL, NULL, 0, 0, NULL, &res) == FALSE) {
220
+	if (db_query(h, NULL, NULL, NULL, 0, 0, NULL, &res) < 0) {
215 221
 		fprintf(stderr, "Error while querying table\n");
216 222
 		return &dbex_exports;
217 223
 	}
... ...
@@ -223,7 +229,7 @@ struct module_exports* mod_register()
223 229
 	      * Free the result because we don't need it
224 230
 	      * anymore
225 231
 	      */
226
-	if (db_free_query(h, res) == FALSE) {
232
+	if (db_free_query(h, res) < 0) {
227 233
 		fprintf(stderr, "Error while freeing result of query\n");
228 234
 		return &dbex_exports;
229 235
 	}
Browse code

str structure is supported now.

Jan Janak authored on 06/08/2002 11:11:45
Showing 1 changed files
... ...
@@ -66,6 +66,12 @@ static int print_res(db_res_t* _r)
66 66
 				break;
67 67
 			case DB_STRING:
68 68
 				printf("%s ", RES_ROWS(_r)[i].values[j].val.string_val);
69
+				break;
70
+			case DB_STR:
71
+				printf("%.*s ", 
72
+				       RES_ROWS(_r)[i].values[j].val.str_val.len,
73
+				       RES_ROWS(_r)[i].values[j].val.str_val.s);
74
+				break;
69 75
 			}
70 76
 			
71 77
 		}
... ...
@@ -90,24 +96,24 @@ struct module_exports* mod_register()
90 96
 	db_key_t keys4[] = {"contact", "q"};
91 97
 
92 98
 	db_val_t vals1[] = { 
93
-		{ DB_STRING  , 0, { .string_val = "foo@bar.com" }      },
94
-		{ DB_STRING  , 0, { .string_val = "real@foo.bar.com" } },
95
-		{ DB_DOUBLE  , 0, { .double_val = 1.2 }                 },
96
-		{ DB_DATETIME, 0, { .time_val = 439826493 }            }
99
+		{ DB_STRING  , 0, { .string_val = "foo@bar.com" }              },
100
+		{ DB_STR     , 0, { .str_val    = { "real@foo.bar.com", 18 } } },
101
+		{ DB_DOUBLE  , 0, { .double_val = 1.2 }                        },
102
+		{ DB_DATETIME, 0, { .time_val   = 439826493 }                  }
97 103
 	};
98 104
 
99 105
 	db_val_t vals2[] = { 
100
-		{ DB_STRING  , 0, { .string_val = "foo2@bar2.com" }      },
101
-		{ DB_STRING  , 0, { .string_val = "real2@foo.bar2.com" } },
102
-		{ DB_DOUBLE  , 0, { .double_val = 1.3 }                   },
103
-		{ DB_DATETIME, 0, { .time_val = 12345 }                  }
106
+		{ DB_STRING  , 0, { .string_val = "foo2@bar2.com" }              },
107
+		{ DB_STR     , 0, { .str_val    = { "real2@foo.bar2.com", 18 } } },
108
+		{ DB_DOUBLE  , 0, { .double_val = 1.3 }                          },
109
+		{ DB_DATETIME, 0, { .time_val   = 12345 }                        }
104 110
 	};
105 111
 
106 112
 	db_val_t vals3[] = { 
107
-		{ DB_STRING  , 0, { .string_val = "foo3@bar3.com" }      },
108
-		{ DB_STRING  , 0, { .string_val = "real3@foo.bar3.com" } },
109
-		{ DB_DOUBLE  , 0, { .double_val = 1.5 }                  },
110
-		{ DB_DATETIME, 0, { .time_val = 123456 }                 }
113
+		{ DB_STRING  , 0, { .string_val = "foo3@bar3.com" }              },
114
+		{ DB_STR     , 0, { .str_val    = { "real3@foo.bar3.com", 18 } } },
115
+		{ DB_DOUBLE  , 0, { .double_val = 1.5 }                          },
116
+		{ DB_DATETIME, 0, { .time_val   = 123456 }                       }
111 117
 	};
112 118
 
113 119
 	db_val_t vals4[] = {
Browse code

*** empty log message ***

Jan Janak authored on 09/07/2002 09:16:05
Showing 1 changed files
... ...
@@ -1,3 +1,7 @@
1
+/*
2
+ * $Id$
3
+ */
4
+
1 5
 #include "../../sr_module.h"
2 6
 #include <stdio.h>
3 7
 #include "../../db/db.h"
Browse code

database module interface moved.

Jan Janak authored on 09/07/2002 09:08:25
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,228 @@
1
+#include "../../sr_module.h"
2
+#include <stdio.h>
3
+#include "../../db/db.h"
4
+
5
+
6
+#define DB_URL   "sql://root@localhost/ser"
7
+#define DB_TABLE "location"
8
+
9
+#define TRUE 1
10
+#define FALSE 0
11
+
12
+
13
+/*
14
+ * Dabase module client example
15
+ */
16
+
17
+
18
+static struct module_exports dbex_exports= {	
19
+	"DBExample", 
20
+	(char*[]) {
21
+	},
22
+	(cmd_function[]) {
23
+	},
24
+	(int[]) {
25
+	},
26
+	(fixup_function[]) {
27
+	},
28
+	0,       /* number of functions*/
29
+	NULL,    /* Module parameter names */
30
+	NULL,    /* Module parameter types */
31
+	NULL,    /* Module parameter variable pointers */
32
+	0,       /* Number of module parameters */
33
+	0,       /* response function*/
34
+	0        /* destroy function */
35
+};
36
+
37
+
38
+static int print_res(db_res_t* _r)
39
+{
40
+	int i, j;
41
+
42
+	for(i = 0; i < RES_COL_N(_r); i++) {
43
+		printf("%s ", RES_NAMES(_r)[i]);
44
+	}
45
+	printf("\n");
46
+
47
+	for(i = 0; i < RES_ROW_N(_r); i++) {
48
+		for(j = 0; j < RES_COL_N(_r); j++) {
49
+			if (RES_ROWS(_r)[i].values[j].nul == TRUE) {
50
+				printf("NULL ");
51
+				continue;
52
+			}
53
+			switch(RES_ROWS(_r)[i].values[j].type) {
54
+			case DB_INT:
55
+				printf("%d ", RES_ROWS(_r)[i].values[j].val.int_val);
56
+				break;
57
+			case DB_DOUBLE:
58
+				printf("%f ", RES_ROWS(_r)[i].values[j].val.double_val);
59
+				break;
60
+			case DB_DATETIME:
61
+				printf("%s ", ctime(&(RES_ROWS(_r)[i].values[j].val.time_val)));
62
+				break;
63
+			case DB_STRING:
64
+				printf("%s ", RES_ROWS(_r)[i].values[j].val.string_val);
65
+			}
66
+			
67
+		}
68
+		printf("\n");
69
+	}
70
+			
71
+	return TRUE;
72
+}
73
+
74
+
75
+
76
+
77
+
78
+struct module_exports* mod_register()
79
+{
80
+	     /*
81
+	      * Column names of table location
82
+	      */
83
+	db_key_t keys1[] = {"user", "contact", "q", "expire" };
84
+	db_key_t keys2[] = {"user", "q"};
85
+	db_key_t keys3[] = {"user", "contact"};
86
+	db_key_t keys4[] = {"contact", "q"};
87
+
88
+	db_val_t vals1[] = { 
89
+		{ DB_STRING  , 0, { .string_val = "foo@bar.com" }      },
90
+		{ DB_STRING  , 0, { .string_val = "real@foo.bar.com" } },
91
+		{ DB_DOUBLE  , 0, { .double_val = 1.2 }                 },
92
+		{ DB_DATETIME, 0, { .time_val = 439826493 }            }
93
+	};
94
+
95
+	db_val_t vals2[] = { 
96
+		{ DB_STRING  , 0, { .string_val = "foo2@bar2.com" }      },
97
+		{ DB_STRING  , 0, { .string_val = "real2@foo.bar2.com" } },
98
+		{ DB_DOUBLE  , 0, { .double_val = 1.3 }                   },
99
+		{ DB_DATETIME, 0, { .time_val = 12345 }                  }
100
+	};
101
+
102
+	db_val_t vals3[] = { 
103
+		{ DB_STRING  , 0, { .string_val = "foo3@bar3.com" }      },
104
+		{ DB_STRING  , 0, { .string_val = "real3@foo.bar3.com" } },
105
+		{ DB_DOUBLE  , 0, { .double_val = 1.5 }                  },
106
+		{ DB_DATETIME, 0, { .time_val = 123456 }                 }
107
+	};
108
+
109
+	db_val_t vals4[] = {
110
+		{ DB_STRING, 0, { .string_val = "foo2@bar2.com" } },
111
+		{ DB_DOUBLE, 0, { .double_val = 1.30 }            }
112
+	};
113
+		  
114
+	db_val_t vals5[] = {
115
+		{ DB_STRING, 0, { .string_val = "foo3@bar3.com" }      },
116
+		{ DB_STRING, 0, { .string_val = "real3@foo.bar3.com" } }
117
+	};
118
+
119
+	db_val_t vals6[] = {
120
+		{ DB_STRING, 0, { .string_val = "different@address.com" } },
121
+		{ DB_DOUBLE, 0, { .double_val = 2.5 }                     }
122
+	};
123
+
124
+	db_con_t* h;
125
+	db_res_t* res;
126
+
127
+	fprintf(stderr, "DBExample - registering...\n");
128
+
129
+	     /* The first call must be bind_dbmod
130
+	      * This call will search for functions
131
+	      * exported by a database module
132
+	      */
133
+	if (bind_dbmod()) {
134
+		fprintf(stderr, "Error while binding database module, did you forget to load a database module ?\n");
135
+		return &dbex_exports;
136
+	}
137
+
138
+	     /*
139
+	      * Create a database connection
140
+	      * DB_URL is database URL of form
141
+	      * sql://user:password@host:port/database
142
+	      * The function returns handle, that
143
+	      * represents a database connection
144
+	      */
145
+	h = db_init(DB_URL);
146
+	if (!h) {
147
+		fprintf(stderr, "Error while initializing database connection\n");
148
+		return &dbex_exports;
149
+	}
150
+
151
+	     /* 
152
+	      * Specify a table name, that will
153
+	      * be used for manipulations
154
+	      */
155
+	if (db_use_table(h, DB_TABLE) == FALSE) {
156
+		fprintf(stderr, "Error while calling db_use_table\n");
157
+		return &dbex_exports;
158
+	}
159
+
160
+	     /* If you do not specify any keys and values to be
161
+	      * matched, all rows will be deleted
162
+	      */
163
+	if (db_delete(h, NULL, NULL, 0) == FALSE) {
164
+		fprintf(stderr, "Error while flushing table\n");
165
+		return &dbex_exports;
166
+	}
167
+
168
+	if (db_insert(h, keys1, vals1, 4) == FALSE) {
169
+		fprintf(stderr, "Error while inserting line 1\n");
170
+		return &dbex_exports;
171
+	}
172
+
173
+	if (db_insert(h, keys1, vals2, 4) == FALSE) {
174
+		fprintf(stderr, "Error while inserting line 2\n");
175
+		return &dbex_exports;
176
+	}
177
+
178
+	if (db_insert(h, keys1, vals3, 4) == FALSE) {
179
+		fprintf(stderr, "Error while inserting line 3\n");
180
+		return &dbex_exports;
181
+	}
182
+
183
+	     /*
184
+	      * Let's delete middle line with
185
+	      * user = foo2@bar2.com and q = 1.3
186
+	      */
187
+	if (db_delete(h, keys2, vals4, 2) == FALSE) {
188
+		fprintf(stderr, "Error while deleting line\n");
189
+		return &dbex_exports;
190
+	}
191
+
192
+	     /*
193
+	      * Modify last line
194
+	      */
195
+	if (db_update(h, keys3, vals5, keys4, vals6, 2, 2) == FALSE) {
196
+		fprintf(stderr, "Error while modifying table\n");
197
+		return &dbex_exports;
198
+	}
199
+
200
+	     /*
201
+	      * Last but not least, dump the result of db_query
202
+	      */
203
+
204
+	if (db_query(h, NULL, NULL, NULL, 0, 0, NULL, &res) == FALSE) {
205
+		fprintf(stderr, "Error while querying table\n");
206
+		return &dbex_exports;
207
+	}
208
+
209
+
210
+	print_res(res);
211
+
212
+	     /*
213
+	      * Free the result because we don't need it
214
+	      * anymore
215
+	      */
216
+	if (db_free_query(h, res) == FALSE) {
217
+		fprintf(stderr, "Error while freeing result of query\n");
218
+		return &dbex_exports;
219
+	}
220
+