db_fld.h 3.3 KB

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