d_openupdate.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*!
  2. * \file db/dbmi_driver/d_openupdate.c
  3. *
  4. * \brief DBMI Library (driver) - open update cursor
  5. *
  6. * (C) 1999-2008 by the GRASS Development Team
  7. *
  8. * This program is free software under the GNU General Public
  9. * License (>=v2). Read the file COPYING that comes with GRASS
  10. * for details.
  11. *
  12. * \author Joel Jones (CERL/UIUC), Radim Blazek
  13. */
  14. #include <stdlib.h>
  15. #include <grass/dbmi.h>
  16. #include "macros.h"
  17. #include "dbstubs.h"
  18. /*!
  19. \brief Open update cursor
  20. \return DB_OK on success
  21. \return DB_FAILED on failure
  22. */
  23. int db_d_open_update_cursor(void)
  24. {
  25. dbCursor *cursor;
  26. int stat;
  27. dbToken token;
  28. dbString select;
  29. dbString table_name;
  30. int mode;
  31. /* get the arg(s) */
  32. db_init_string(&table_name);
  33. db_init_string(&select);
  34. DB_RECV_STRING(&table_name);
  35. DB_RECV_STRING(&select);
  36. DB_RECV_INT(&mode);
  37. /* create a cursor */
  38. cursor = (dbCursor *) db_malloc(sizeof(dbCursor));
  39. if (cursor == NULL)
  40. return db_get_error_code();
  41. token = db_new_token((dbAddress) cursor);
  42. if (token < 0)
  43. return db_get_error_code();
  44. db_init_cursor(cursor);
  45. /* call the procedure */
  46. stat = db_driver_open_update_cursor(&table_name, &select, cursor, mode);
  47. db_free_string(&table_name);
  48. db_free_string(&select);
  49. /* send the return code */
  50. if (stat != DB_OK) {
  51. DB_SEND_FAILURE();
  52. return DB_OK;
  53. }
  54. DB_SEND_SUCCESS();
  55. /* mark this as an update cursor */
  56. db_set_cursor_type_update(cursor);
  57. /* add this cursor to the cursors managed by the driver state */
  58. db__add_cursor_to_driver_state(cursor);
  59. /* results */
  60. DB_SEND_TOKEN(&token);
  61. DB_SEND_INT(cursor->type);
  62. DB_SEND_INT(cursor->mode);
  63. DB_SEND_TABLE_DEFINITION(cursor->table);
  64. return DB_OK;
  65. }