Browse code

str structure is supported now.

Jan Janak authored on 06/08/2002 11:11:45
Showing 3 changed files
... ...
@@ -6,6 +6,7 @@
6 6
 #define DB_VAL_H
7 7
 
8 8
 #include <time.h>
9
+#include "../str.h"
9 10
 
10 11
 
11 12
 /*
... ...
@@ -15,6 +16,7 @@ typedef enum {
15 16
 	DB_INT,
16 17
         DB_DOUBLE,
17 18
 	DB_STRING,
19
+	DB_STR,
18 20
 	DB_DATETIME
19 21
 } db_type_t;
20 22
 
... ...
@@ -30,6 +32,7 @@ typedef struct {
30 32
 		double       double_val; /* double value */
31 33
 		time_t       time_val;   /* unix time value */
32 34
 		const char*  string_val; /* NULL terminated string */
35
+		str          str_val;    /* str string value */
33 36
 	} val;                           /* union of all possible types */
34 37
 } db_val_t;
35 38
 
... ...
@@ -44,6 +47,7 @@ typedef struct {
44 47
 #define VAL_DOUBLE(dv) ((dv)->val.double_val)
45 48
 #define VAL_TIME(dv)   ((dv)->val.time_val)
46 49
 #define VAL_STRING(dv) ((dv)->val.string_val)
50
+#define VAL_STR(dv)    ((dv)->val.str_val)
47 51
 
48 52
 
49 53
 /*
... ...
@@ -79,6 +79,7 @@ information, see the next section.
79 79
        DB_INT,       /* Integer number */
80 80
        DB_DOUBLE,    /* Decimal number */
81 81
        DB_STRING,    /* String */
82
+       DB_STR,       /* str structure */
82 83
        DB_DATETIME   /* Date and time */
83 84
    } db_type_t;
84 85
 
... ...
@@ -97,6 +98,7 @@ recognized and converted by the database API:
97 98
 DB_INT      - Value in the database represents an integer number
98 99
 DB_DOUBLE   - Value in the database represents a decimal number
99 100
 DB_STRING   - Value in the database represents a string
101
+DB_STR      - Value in the database represents a string
100 102
 DB_DATETIME - Value in the database represents date and time
101 103
 
102 104
 These datatypes are automaticaly recognized, converted from internal database
... ...
@@ -169,6 +171,14 @@ Example: if (VAL_TYPE(val) == DB_STRING) {
169 171
              printf("%s", VAL_STRING(val));
170 172
          }
171 173
 
174
+1.4.3.6 VAL_STR(value) Macro
175
+
176
+Use this macro if you need to access str structure in the db_val_t structure.
177
+
178
+Example: if (VAL_TYPE(val) == DB_STR) {
179
+             printf("%.*s", VAL_STR(val).len, VAL_STR(val).s);
180
+         }
181
+
172 182
 
173 183
 1.5 Type db_row_t
174 184
 
... ...
@@ -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[] = {