1 /*
2  * Copyright (C) 2001-2003 FhG Fokus
3  * Copyright (C) 2006-2007 iptelorg GmbH
4  *
5  * This file is part of Kamailio, a free SIP server.
6  *
7  * Kamailio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version
11  *
12  * Kamailio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21 
22 #ifndef _DB_FLD_H
23 #define _DB_FLD_H  1
24 
25 /** \ingroup DB_API
26  * @{
27  */
28 
29 #include "db_gen.h"
30 #include "../../core/str.h"
31 #include <time.h>
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif /* __cplusplus */
36 
37 
38 enum db_fld_type {
39 	DB_NONE = 0,   /* Bumper */
40 	DB_INT,        /* 32-bit integer */
41 	DB_FLOAT,      /* 32-bit fixed-precision number */
42 	DB_DOUBLE,     /* double data type */
43 	DB_CSTR,       /* Zero-terminated string */
44 	DB_STR,        /* str structure */
45 	DB_DATETIME,   /* Date and time in number of seconds since 1-Jan-1970 */
46 	DB_BLOB,       /* Generic binary object*/
47 	DB_BITMAP      /* Bitmap of flags */
48 };
49 
50 extern char* db_fld_str[];
51 
52 enum db_fld_op {
53 	DB_EQ = 0, /* The value of the field must be equal */
54 	DB_NE,     /* The value of the filed must be not equal */
55 	DB_LT,     /* The value of the field must be less than */
56 	DB_GT,     /* The value of the field must be greater than */
57 	DB_LEQ,    /* The value of the field must be less than or equal */
58 	DB_GEQ     /* The value of the field must be greater than or equal */
59 };
60 
61 enum db_flags {
62 	DB_NULL = (1 << 0),  /**< The field is NULL, i.e. no value was provided */
63 	DB_NO_TZ = (1 << 1), /**< Inhibit time-zone shifts for timestamp fields */
64 };
65 
66 /* union of all possible types */
67 typedef union db_fld_val {
68 	int          int4;   /* integer value */
69 	float        flt;    /* float value */
70 	double       dbl;    /* double value */
71 	time_t       time;   /* unix time value */
72 	char*        cstr;   /* NULL terminated string */
73 	str          lstr;   /* String with known length */
74 	str          blob;   /* Blob data */
75 	unsigned int bitmap; /* Bitmap data type, 32 flags, should be enough */
76 	long long    int8;   /* 8-byte integer */
77 } db_fld_val_t;
78 
79 typedef struct db_fld {
80 	db_gen_t gen;  /* Generic part of the structure */
81 	char* name;
82 	enum db_fld_type type;
83 	unsigned int flags;
84 	db_fld_val_t v;
85 	enum db_fld_op op;
86 } db_fld_t;
87 
88 #define DB_FLD_LAST(fld) ((fld).name == NULL)
89 #define DB_FLD_EMPTY(fld) ((fld) == NULL || (fld)[0].name == NULL)
90 
91 struct db_fld* db_fld(size_t n);
92 void db_fld_free(struct db_fld* fld);
93 
94 int db_fld_init(struct db_fld* fld);
95 void db_fld_close(struct db_fld* fld);
96 
97 db_fld_t* db_fld_copy(db_fld_t* fld);
98 
99 #ifdef __cplusplus
100 }
101 #endif /* __cplusplus */
102 
103 /** @} */
104 
105 #endif /* _DB_FLD_H */
106