db_val.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 has no value */
  48. union {
  49. int int_val; /* integer value */
  50. double double_val; /* double value */
  51. time_t time_val; /* unix time value */
  52. const char* string_val; /* NULL terminated string */
  53. str str_val; /* str string value */
  54. str blob_val; /* Blob data */
  55. } val; /* union of all possible types */
  56. } db_val_t;
  57. /*
  58. * Useful macros for accessing attributes of db_val structure
  59. */
  60. #define VAL_TYPE(dv) ((dv)->type)
  61. #define VAL_NULL(dv) ((dv)->nul)
  62. #define VAL_INT(dv) ((dv)->val.int_val)
  63. #define VAL_DOUBLE(dv) ((dv)->val.double_val)
  64. #define VAL_TIME(dv) ((dv)->val.time_val)
  65. #define VAL_STRING(dv) ((dv)->val.string_val)
  66. #define VAL_STR(dv) ((dv)->val.str_val)
  67. #define VAL_BLOB(dv) ((dv)->val.blob_val)
  68. /*
  69. * Convert string to given type
  70. */
  71. int str2val(db_type_t _t, db_val_t* _v, const char* _s, int _l);
  72. /*
  73. * Convert given type to string
  74. */
  75. int val2str(db_val_t* _v, char* _s, int* _len);
  76. #endif /* DB_VAL_H */