Browse code

Return values changed, blob support added

Jan Janak authored on 08/08/2002 17:25:32
Showing 3 changed files
... ...
@@ -17,7 +17,8 @@ typedef enum {
17 17
         DB_DOUBLE,
18 18
 	DB_STRING,
19 19
 	DB_STR,
20
-	DB_DATETIME
20
+	DB_DATETIME,
21
+	DB_BLOB
21 22
 } db_type_t;
22 23
 
23 24
 
... ...
@@ -33,6 +34,7 @@ typedef struct {
33 34
 		time_t       time_val;   /* unix time value */
34 35
 		const char*  string_val; /* NULL terminated string */
35 36
 		str          str_val;    /* str string value */
37
+		str          blob_val;   /* Blob data */
36 38
 	} val;                           /* union of all possible types */
37 39
 } db_val_t;
38 40
 
... ...
@@ -48,12 +50,13 @@ typedef struct {
48 50
 #define VAL_TIME(dv)   ((dv)->val.time_val)
49 51
 #define VAL_STRING(dv) ((dv)->val.string_val)
50 52
 #define VAL_STR(dv)    ((dv)->val.str_val)
53
+#define VAL_BLOB(dv)   ((dv)->val.blob_val)
51 54
 
52 55
 
53 56
 /*
54 57
  * Convert string to given type
55 58
  */
56
-int str2val(db_type_t _t, db_val_t* _v, const char* _s);
59
+int str2val(db_type_t _t, db_val_t* _v, const char* _s, int _l);
57 60
 
58 61
 
59 62
 /*
... ...
@@ -81,6 +81,7 @@ information, see the next section.
81 81
        DB_STRING,    /* String */
82 82
        DB_STR,       /* str structure */
83 83
        DB_DATETIME   /* Date and time */
84
+       DB_BLOB       /* Binary large object */
84 85
    } db_type_t;
85 86
 
86 87
 1.3.3 Macros
... ...
@@ -100,6 +101,7 @@ DB_DOUBLE   - Value in the database represents a decimal number
100 101
 DB_STRING   - Value in the database represents a string
101 102
 DB_STR      - Value in the database represents a string
102 103
 DB_DATETIME - Value in the database represents date and time
104
+DB_BLOB     - Value in the database represents binary large object
103 105
 
104 106
 These datatypes are automaticaly recognized, converted from internal database
105 107
 representation and stored in the variable of corresponding type.
... ...
@@ -114,6 +116,8 @@ representation and stored in the variable of corresponding type.
114 116
              double double_val;       /* Double value */
115 117
              time_t time_val;         /* Unix time_t value */
116 118
              const char* string_val;  /* Zero terminated string */
119
+	     str str_val;             /* str structure */
120
+             str blob_val;            /* Structure describing blob */
117 121
          } val;
118 122
     } db_val_t;
119 123
 
... ...
@@ -171,7 +175,7 @@ Example: if (VAL_TYPE(val) == DB_STRING) {
171 175
              printf("%s", VAL_STRING(val));
172 176
          }
173 177
 
174
-1.4.3.6 VAL_STR(value) Macro
178
+1.4.3.7 VAL_STR(value) Macro
175 179
 
176 180
 Use this macro if you need to access str structure in the db_val_t structure.
177 181
 
... ...
@@ -179,6 +183,13 @@ Example: if (VAL_TYPE(val) == DB_STR) {
179 183
              printf("%.*s", VAL_STR(val).len, VAL_STR(val).s);
180 184
          }
181 185
 
186
+1.4.3.8 VAL_BLOB(value) Macro
187
+
188
+Use this macro if you need to access blob value in the db_val_t structure.
189
+
190
+Example: if (VAL_TYPE(val) == DB_BLOB) {
191
+	     printf("%.*s", VAL_BLOB(val).len, VAL_BLOB(val).s);
192
+         }
182 193
 
183 194
 1.5 Type db_row_t
184 195
 
... ...
@@ -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
 	}