db_val.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2001-2003 Fhg Fokus
  5. *
  6. * This file is part of ser, a free SIP server.
  7. *
  8. * ser is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version
  12. *
  13. * For a license to use the ser software under conditions
  14. * other than those described here, or to purchase support for this
  15. * software, please contact iptel.org by e-mail at the following addresses:
  16. * [email protected]
  17. *
  18. * ser is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  26. */
  27. #ifndef DB_VAL_H
  28. #define DB_VAL_H
  29. #include <time.h>
  30. #include "../str.h"
  31. /*
  32. * Accepted column types
  33. */
  34. typedef enum {
  35. DB_INT,
  36. DB_DOUBLE,
  37. DB_STRING,
  38. DB_STR,
  39. DB_DATETIME,
  40. DB_BLOB
  41. } db_type_t;
  42. /*
  43. * Column value structure
  44. */
  45. typedef struct {
  46. db_type_t type; /* Type of the value */
  47. int nul; /* Means that the column in database
  48. has no value */
  49. union {
  50. int int_val; /* integer value */
  51. double double_val; /* double value */
  52. time_t time_val; /* unix time value */
  53. const char* string_val; /* NULL terminated string */
  54. str str_val; /* str string value */
  55. str blob_val; /* Blob data */
  56. } val; /* union of all possible types */
  57. } db_val_t;
  58. /*
  59. * Useful macros for accessing attributes of db_val structure
  60. */
  61. #define VAL_TYPE(dv) ((dv)->type)
  62. #define VAL_NULL(dv) ((dv)->nul)
  63. #define VAL_INT(dv) ((dv)->val.int_val)
  64. #define VAL_DOUBLE(dv) ((dv)->val.double_val)
  65. #define VAL_TIME(dv) ((dv)->val.time_val)
  66. #define VAL_STRING(dv) ((dv)->val.string_val)
  67. #define VAL_STR(dv) ((dv)->val.str_val)
  68. #define VAL_BLOB(dv) ((dv)->val.blob_val)
  69. /*
  70. * Convert string to given type
  71. */
  72. int str2val(db_type_t _t, db_val_t* _v, const char* _s, int _l);
  73. /*
  74. * Convert given type to string
  75. */
  76. int val2str(db_val_t* _v, char* _s, int* _len);
  77. #endif /* DB_VAL_H */