xdrtable.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include <grass/dbmi.h>
  2. #include "macros.h"
  3. int db__send_table_definition(dbTable * table)
  4. {
  5. int i;
  6. DB_SEND_INT(table->numColumns);
  7. for (i = 0; i < table->numColumns; i++) {
  8. DB_SEND_COLUMN_DEFINITION(&table->columns[i]);
  9. }
  10. DB_SEND_STRING(&table->tableName);
  11. DB_SEND_STRING(&table->description);
  12. DB_SEND_INT(table->priv_insert);
  13. DB_SEND_INT(table->priv_delete);
  14. return DB_OK;
  15. }
  16. int db__recv_table_definition(dbTable ** table)
  17. {
  18. int i, ncols;
  19. dbTable *t;
  20. DB_RECV_INT(&ncols);
  21. *table = t = db_alloc_table(ncols);
  22. if (t == NULL)
  23. return db_get_error_code();
  24. for (i = 0; i < t->numColumns; i++) {
  25. DB_RECV_COLUMN_DEFINITION(&t->columns[i]);
  26. }
  27. DB_RECV_STRING(&t->tableName);
  28. DB_RECV_STRING(&t->description);
  29. DB_RECV_INT(&t->priv_insert);
  30. DB_RECV_INT(&t->priv_delete);
  31. return DB_OK;
  32. }
  33. int db__send_table_data(dbTable * table)
  34. {
  35. int i, ncols;
  36. ncols = table->numColumns;
  37. DB_SEND_INT(ncols);
  38. for (i = 0; i < ncols; i++) {
  39. DB_SEND_COLUMN_VALUE(db_get_table_column(table, i));
  40. }
  41. return DB_OK;
  42. }
  43. int db__recv_table_data(dbTable * table)
  44. {
  45. int i, ncols;
  46. ncols = table->numColumns;
  47. DB_RECV_INT(&i);
  48. if (i != ncols) {
  49. db_error("fetch: table has wrong number of columns");
  50. return DB_FAILED;
  51. }
  52. for (i = 0; i < ncols; i++) {
  53. DB_RECV_COLUMN_VALUE(db_get_table_column(table, i));
  54. }
  55. return DB_OK;
  56. }