c_list_tabs.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*!
  2. * \file db/dbmi_client/c_list_tabs.c
  3. *
  4. * \brief DBMI Library (client) - list tables
  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 <stdlib.h>
  15. #include <string.h>
  16. #include <grass/dbmi.h>
  17. #include "macros.h"
  18. static int cmp_dbstr(const void *pa, const void *pb)
  19. {
  20. const char *a = db_get_string((dbString *) pa);
  21. const char *b = db_get_string((dbString *) pb);
  22. return strcmp(a, b);
  23. }
  24. /*!
  25. \brief List available tables for given connection
  26. \param driver db driver
  27. \param[out] names list of table names
  28. \param[out] count number of items in the list
  29. \param system ?
  30. \return DB_OK on success
  31. \return DB_FAILED on failure
  32. */
  33. int db_list_tables(dbDriver * driver, dbString ** names, int *count, int system)
  34. {
  35. int ret_code;
  36. /* start the procedure call */
  37. db__set_protocol_fds(driver->send, driver->recv);
  38. DB_START_PROCEDURE_CALL(DB_PROC_LIST_TABLES);
  39. /* arguments */
  40. DB_SEND_INT(system);
  41. /* get the return code for the procedure call */
  42. DB_RECV_RETURN_CODE(&ret_code);
  43. if (ret_code != DB_OK)
  44. return ret_code; /* ret_code SHOULD == DB_FAILED */
  45. /* results */
  46. DB_RECV_STRING_ARRAY(names, count);
  47. qsort(*names, *count, sizeof(dbString), cmp_dbstr);
  48. return DB_OK;
  49. }