d_insert.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*!
  2. * \file db/dbmi_driver/d_insert.c
  3. *
  4. * \brief DBMI Library (driver) - insert new record
  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 Insert new record into table
  19. \return DB_OK on success
  20. \return DB_FAILED on failure
  21. */
  22. int db_d_insert(void)
  23. {
  24. dbToken token;
  25. dbCursor *cursor;
  26. int stat;
  27. /* get the arg(s) */
  28. DB_RECV_TOKEN(&token);
  29. cursor = (dbCursor *) db_find_token(token);
  30. if (cursor == NULL || !db_test_cursor_type_insert(cursor)) {
  31. db_error("** not an insert cursor **");
  32. DB_SEND_FAILURE();
  33. return DB_FAILED;
  34. }
  35. DB_RECV_TABLE_DATA(cursor->table);
  36. /* call the procedure */
  37. stat = db_driver_insert(cursor);
  38. /* send the return code */
  39. if (stat != DB_OK) {
  40. DB_SEND_FAILURE();
  41. return DB_OK;
  42. }
  43. DB_SEND_SUCCESS();
  44. /* no results */
  45. return DB_OK;
  46. }