Browse code

- DB_BITMAP data type added

Jan Janak authored on 15/09/2003 22:34:28
Showing 3 changed files
... ...
@@ -42,7 +42,8 @@ typedef enum {
42 42
 	DB_STRING,
43 43
 	DB_STR,
44 44
 	DB_DATETIME,
45
-	DB_BLOB
45
+	DB_BLOB,
46
+	DB_BITMAP
46 47
 } db_type_t;
47 48
 
48 49
 
... ...
@@ -52,15 +53,17 @@ typedef enum {
52 53
 typedef struct {
53 54
 	db_type_t type;                /* Type of the value */
54 55
 	int nul;                       /* Means that the column in database
55
-									  has no value */
56
+					* has no value 
57
+					*/
56 58
 	union {
57
-		int          int_val;    /* integer value */
58
-		double       double_val; /* double value */
59
-		time_t       time_val;   /* unix time value */
60
-		const char*  string_val; /* NULL terminated string */
61
-		str          str_val;    /* str string value */
62
-		str          blob_val;   /* Blob data */
63
-	} val;                       /* union of all possible types */
59
+		int           int_val;    /* integer value */
60
+		double        double_val; /* double value */
61
+		time_t        time_val;   /* unix time value */
62
+		const char*   string_val; /* NULL terminated string */
63
+		str           str_val;    /* str string value */
64
+		str           blob_val;   /* Blob data */
65
+		unsigned int  bitmap_val; /* Bitmap data type, 32 flags, should be enough */ 
66
+	} val;                            /* union of all possible types */
64 67
 } db_val_t;
65 68
 
66 69
 
... ...
@@ -76,6 +79,7 @@ typedef struct {
76 79
 #define VAL_STRING(dv) ((dv)->val.string_val)
77 80
 #define VAL_STR(dv)    ((dv)->val.str_val)
78 81
 #define VAL_BLOB(dv)   ((dv)->val.blob_val)
82
+#define VAL_BITMAP(dv) ((dv)->val.bitmap_val)
79 83
 
80 84
 
81 85
 /*
... ...
@@ -82,6 +82,7 @@ information, see the next section.
82 82
        DB_STR,       /* str structure */
83 83
        DB_DATETIME   /* Date and time */
84 84
        DB_BLOB       /* Binary large object */
85
+       DB_BITMAP     /* Bitmap, one-dimensional array of flags */
85 86
    } db_type_t;
86 87
 
87 88
 1.3.3 Macros
... ...
@@ -102,6 +103,7 @@ DB_STRING   - Value in the database represents a string
102 103
 DB_STR      - Value in the database represents a string
103 104
 DB_DATETIME - Value in the database represents date and time
104 105
 DB_BLOB     - Value in the database represents binary large object
106
+DB_BITMAP   - Value in the database represents an array of flags
105 107
 
106 108
 These datatypes are automaticaly recognized, converted from internal database
107 109
 representation and stored in the variable of corresponding type.
... ...
@@ -118,6 +120,7 @@ representation and stored in the variable of corresponding type.
118 120
              const char* string_val;  /* Zero terminated string */
119 121
 	     str str_val;             /* str structure */
120 122
              str blob_val;            /* Structure describing blob */
123
+             unsigned int bitmap_val; /* Array of flags */
121 124
          } val;
122 125
     } db_val_t;
123 126
 
... ...
@@ -191,6 +194,14 @@ Example: if (VAL_TYPE(val) == DB_BLOB) {
191 194
 	     printf("%.*s", VAL_BLOB(val).len, VAL_BLOB(val).s);
192 195
          }
193 196
 
197
+1.4.3.9 VAL_BITMAP(value) Macro
198
+
199
+Use this macro if you need to access bitmap value in the db_val_t structure.
200
+
201
+Example: if (VAL_TYPE(val) == DB_BITMAP) {
202
+	    printf("%d", VAL_BITMAP(val));
203
+	 }
204
+
194 205
 1.5 Type db_row_t
195 206
 
196 207
 1.5.1 Description
... ...
@@ -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
 	}