d_openinsert.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*!
  2. * \file db/dbmi_driver/d_openinsert.c
  3. *
  4. * \brief DBMI Library (driver) - open insert 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 <grass/dbmi.h>
  15. #include "macros.h"
  16. #include "dbstubs.h"
  17. /*!
  18. \brief Open insert cursor
  19. \return DB_OK on success
  20. \return DB_FAILED on failure
  21. */
  22. int db_d_open_insert_cursor(void)
  23. {
  24. dbCursor *cursor;
  25. dbTable *table;
  26. int stat;
  27. dbToken token;
  28. /* get the arg(s) */
  29. DB_RECV_TABLE_DEFINITION(&table);
  30. /* create a cursor */
  31. cursor = (dbCursor *) db_malloc(sizeof(dbCursor));
  32. if (cursor == NULL)
  33. return db_get_error_code();
  34. token = db_new_token((dbAddress) cursor);
  35. if (token < 0)
  36. return db_get_error_code();
  37. db_init_cursor(cursor);
  38. db_set_cursor_table(cursor, table);
  39. /* call the procedure */
  40. stat = db_driver_open_insert_cursor(cursor);
  41. /* send the return code */
  42. if (stat != DB_OK) {
  43. DB_SEND_FAILURE();
  44. return DB_OK;
  45. }
  46. DB_SEND_SUCCESS();
  47. /* mark this as an insert cursor */
  48. db_set_cursor_type_insert(cursor);
  49. /* add this cursor to the cursors managed by the driver state */
  50. db__add_cursor_to_driver_state(cursor);
  51. /* results */
  52. DB_SEND_TOKEN(&token);
  53. DB_SEND_INT(cursor->type);
  54. DB_SEND_INT(cursor->mode);
  55. return DB_OK;
  56. }