xdrvalue.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*!
  2. \file lib/db/dbmi_base/xdrvalue.c
  3. \brief DBMI Library (base) - external data representation (value)
  4. (C) 1999-2009, 2011 by the GRASS Development Team
  5. This program is free software under the GNU General Public License
  6. (>=v2). Read the file COPYING that comes with GRASS for details.
  7. \author Joel Jones (CERL/UIUC), Radim Blazek, Brad Douglas, Markus Neteler
  8. \author Doxygenized by Martin Landa <landa.martin gmail.com> (2011)
  9. */
  10. #include <grass/dbmi.h>
  11. #include <grass/glocale.h>
  12. #include "macros.h"
  13. /*!
  14. \brief Send value
  15. \param value
  16. \param Ctype
  17. \return
  18. */
  19. int db__send_value(dbValue * value, int Ctype)
  20. {
  21. DB_SEND_CHAR(value->isNull);
  22. if (value->isNull)
  23. return DB_OK;
  24. switch (Ctype) {
  25. case DB_C_TYPE_INT:
  26. DB_SEND_INT(value->i);
  27. break;
  28. case DB_C_TYPE_DOUBLE:
  29. DB_SEND_DOUBLE(value->d);
  30. break;
  31. case DB_C_TYPE_STRING:
  32. DB_SEND_STRING(&value->s);
  33. break;
  34. case DB_C_TYPE_DATETIME:
  35. DB_SEND_DATETIME(&value->t);
  36. break;
  37. default:
  38. db_error("send data: invalid C-type");
  39. return DB_FAILED;
  40. }
  41. return DB_OK;
  42. }
  43. /*!
  44. \brief Receive value
  45. \param value
  46. \param Ctype
  47. \return
  48. */
  49. int db__recv_value(dbValue * value, int Ctype)
  50. {
  51. DB_RECV_CHAR(&value->isNull);
  52. if (value->isNull)
  53. return DB_OK;
  54. switch (Ctype) {
  55. case DB_C_TYPE_INT:
  56. DB_RECV_INT(&value->i);
  57. break;
  58. case DB_C_TYPE_DOUBLE:
  59. DB_RECV_DOUBLE(&value->d);
  60. break;
  61. case DB_C_TYPE_STRING:
  62. DB_RECV_STRING(&value->s);
  63. break;
  64. case DB_C_TYPE_DATETIME:
  65. DB_RECV_DATETIME(&value->t);
  66. break;
  67. default:
  68. db_error(_("send data: invalid C-type"));
  69. return DB_FAILED;
  70. }
  71. return DB_OK;
  72. }