xdrtable.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*!
  2. \file lib/db/dbmi_base/xdrtable.c
  3. \brief DBMI Library (base) - external data representation (table)
  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 table definition
  15. \param table pointer to dbTable
  16. \return
  17. */
  18. int db__send_table_definition(dbTable * table)
  19. {
  20. int i;
  21. DB_SEND_INT(table->numColumns);
  22. for (i = 0; i < table->numColumns; i++) {
  23. DB_SEND_COLUMN_DEFINITION(&table->columns[i]);
  24. }
  25. DB_SEND_STRING(&table->tableName);
  26. DB_SEND_STRING(&table->description);
  27. DB_SEND_INT(table->priv_insert);
  28. DB_SEND_INT(table->priv_delete);
  29. return DB_OK;
  30. }
  31. /*!
  32. \brief Receive table definition
  33. \param[out] table
  34. \return
  35. */
  36. int db__recv_table_definition(dbTable ** table)
  37. {
  38. int i, ncols;
  39. dbTable *t;
  40. DB_RECV_INT(&ncols);
  41. *table = t = db_alloc_table(ncols);
  42. if (t == NULL)
  43. return db_get_error_code();
  44. for (i = 0; i < t->numColumns; i++) {
  45. DB_RECV_COLUMN_DEFINITION(&t->columns[i]);
  46. }
  47. DB_RECV_STRING(&t->tableName);
  48. DB_RECV_STRING(&t->description);
  49. DB_RECV_INT(&t->priv_insert);
  50. DB_RECV_INT(&t->priv_delete);
  51. return DB_OK;
  52. }
  53. /*!
  54. \brief Send table data
  55. \param table
  56. \return
  57. */
  58. int db__send_table_data(dbTable * table)
  59. {
  60. int i, ncols;
  61. ncols = table->numColumns;
  62. DB_SEND_INT(ncols);
  63. for (i = 0; i < ncols; i++) {
  64. DB_SEND_COLUMN_VALUE(db_get_table_column(table, i));
  65. }
  66. return DB_OK;
  67. }
  68. /*!
  69. \brief Receive table data
  70. \param table
  71. \return
  72. */
  73. int db__recv_table_data(dbTable * table)
  74. {
  75. int i, ncols;
  76. ncols = table->numColumns;
  77. DB_RECV_INT(&i);
  78. if (i != ncols) {
  79. db_error(_("fetch: table has wrong number of columns"));
  80. return DB_FAILED;
  81. }
  82. for (i = 0; i < ncols; i++) {
  83. DB_RECV_COLUMN_VALUE(db_get_table_column(table, i));
  84. }
  85. return DB_OK;
  86. }