select.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*****************************************************************************
  2. *
  3. * MODULE: DBF driver
  4. *
  5. * AUTHOR(S): Radim Blazek
  6. *
  7. * PURPOSE: Simple driver for reading and writing dbf files
  8. *
  9. * COPYRIGHT: (C) 2000 by the GRASS Development Team
  10. *
  11. * This program is free software under the GNU General Public
  12. * License (>=v2). Read the file COPYING that comes with GRASS
  13. * for details.
  14. *
  15. *****************************************************************************/
  16. #include <grass/dbmi.h>
  17. #include <grass/shapefil.h>
  18. #include <grass/glocale.h>
  19. #include "globals.h"
  20. #include "proto.h"
  21. int db__driver_open_select_cursor(dbString * sel, dbCursor * dbc, int mode)
  22. {
  23. int ret;
  24. cursor *c;
  25. char *sql;
  26. dbTable *table;
  27. /* allocate cursor */
  28. c = alloc_cursor();
  29. if (c == NULL)
  30. return DB_FAILED;
  31. db_set_cursor_mode(dbc, mode);
  32. db_set_cursor_type_readonly(dbc);
  33. sql = db_get_string(sel);
  34. ret = execute(sql, c);
  35. if (ret == DB_FAILED) {
  36. db_d_append_error(_("Unable to open cursor."));
  37. db_d_report_error();
  38. return DB_FAILED;
  39. }
  40. describe_table(c->table, c->cols, c->ncols, &table);
  41. /* record table with dbCursor */
  42. db_set_cursor_table(dbc, table);
  43. /* set dbCursor's token for my cursor */
  44. db_set_cursor_token(dbc, c->token);
  45. return DB_OK;
  46. }