c_execute.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*!
  2. * \file db/dbmi_client/c_execute.c
  3. *
  4. * \brief DBMI Library (client) - execute SQL statements
  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. /*!
  17. \brief Execute SQL statements
  18. \param driver db driver
  19. \param SQLstatement SQL statement (alter, update, ...)
  20. \return DB_OK on success
  21. \return DB_FAILED on failure
  22. */
  23. int db_execute_immediate(dbDriver * driver, dbString * SQLstatement)
  24. {
  25. int ret_code;
  26. /* start the procedure call */
  27. db__set_protocol_fds(driver->send, driver->recv);
  28. DB_START_PROCEDURE_CALL(DB_PROC_EXECUTE_IMMEDIATE);
  29. /* send the argument(s) to the procedure */
  30. DB_SEND_STRING(SQLstatement);
  31. /* get the return code for the procedure call */
  32. DB_RECV_RETURN_CODE(&ret_code);
  33. if (ret_code != DB_OK)
  34. return ret_code; /* ret_code SHOULD == DB_FAILED */
  35. /* no results */
  36. return DB_OK;
  37. }
  38. /*!
  39. \brief Begin transaction
  40. \param driver db driver
  41. \return DB_OK on success
  42. \return DB_FAILED on failure
  43. */
  44. int db_begin_transaction(dbDriver * driver)
  45. {
  46. int ret_code;
  47. /* start the procedure call */
  48. db__set_protocol_fds(driver->send, driver->recv);
  49. DB_START_PROCEDURE_CALL(DB_PROC_BEGIN_TRANSACTION);
  50. /* get the return code for the procedure call */
  51. DB_RECV_RETURN_CODE(&ret_code);
  52. if (ret_code != DB_OK)
  53. return ret_code;
  54. /* no results */
  55. return DB_OK;
  56. }
  57. /*!
  58. \brief Commit transaction
  59. \param driver db driver
  60. \return DB_OK on success
  61. \return DB_FAILED on failure
  62. */
  63. int db_commit_transaction(dbDriver * driver)
  64. {
  65. int ret_code;
  66. /* start the procedure call */
  67. db__set_protocol_fds(driver->send, driver->recv);
  68. DB_START_PROCEDURE_CALL(DB_PROC_COMMIT_TRANSACTION);
  69. /* get the return code for the procedure call */
  70. DB_RECV_RETURN_CODE(&ret_code);
  71. if (ret_code != DB_OK)
  72. return ret_code;
  73. /* no results */
  74. return DB_OK;
  75. }