execute.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /****************************************************************************
  2. *
  3. * MODULE: execute
  4. * AUTHOR(S): Radim Blazek <radim.blazek gmail.com> (original contributor)
  5. * Bernhard Reiter <bernhard intevation.de>, Brad Douglas <rez touchofmadness.com>, Huidae Cho <grass4u gmail.com>, Glynn Clements <glynn gclements.plus.com>, Markus Neteler <neteler itc.it>
  6. * PURPOSE: ODBC driver
  7. * COPYRIGHT: (C) 2000-2007 by the GRASS Development Team
  8. *
  9. * This program is free software under the GNU General Public
  10. * License (>=v2). Read the file COPYING that comes with GRASS
  11. * for details.
  12. *
  13. *****************************************************************************/
  14. #include <grass/dbmi.h>
  15. #include <stdio.h>
  16. #include <grass/gis.h>
  17. #include "odbc.h"
  18. #include "globals.h"
  19. #include "proto.h"
  20. int db__driver_execute_immediate(dbString * sql)
  21. {
  22. char *s, msg[OD_MSG];
  23. cursor *c;
  24. SQLRETURN ret;
  25. SQLINTEGER err;
  26. s = db_get_string(sql);
  27. /* allocate cursor */
  28. c = alloc_cursor();
  29. if (c == NULL)
  30. return DB_FAILED;
  31. ret = SQLExecDirect(c->stmt, s, SQL_NTS);
  32. if ((ret != SQL_SUCCESS) && (ret != SQL_SUCCESS_WITH_INFO)) {
  33. SQLGetDiagRec(SQL_HANDLE_STMT, c->stmt, 1, NULL, &err, msg,
  34. sizeof(msg), NULL);
  35. db_d_append_error("SQLExecDirect():\n%s\n%s (%d)\n", s, msg,
  36. (int)err);
  37. db_d_report_error();
  38. return DB_FAILED;
  39. }
  40. free_cursor(c);
  41. return DB_OK;
  42. }