listtab.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**********************************************************
  2. * MODULE: mysql
  3. * AUTHOR(S): Radim Blazek (radim.blazek@gmail.com)
  4. * PURPOSE: MySQL database driver
  5. * COPYRIGHT: (C) 2001 by the GRASS Development Team
  6. * This program is free software under the
  7. * GNU General Public License (>=v2).
  8. * Read the file COPYING that comes with GRASS
  9. * for details.
  10. **********************************************************/
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <grass/gis.h>
  14. #include <grass/dbmi.h>
  15. #include <grass/glocale.h>
  16. #include "globals.h"
  17. #include "proto.h"
  18. int db__driver_list_tables(dbString ** tlist, int *tcount, int system)
  19. {
  20. int i;
  21. dbString *list;
  22. int nrows;
  23. MYSQL_RES *res;
  24. MYSQL_ROW row;
  25. *tlist = NULL;
  26. *tcount = 0;
  27. res = mysql_list_tables(connection, NULL);
  28. if (res == NULL) {
  29. append_error(_("Cannot get list of tables:\n"));
  30. append_error(mysql_error(connection));
  31. report_error();
  32. return DB_FAILED;
  33. }
  34. mysql_store_result(connection);
  35. nrows = (int)mysql_num_rows(res);
  36. list = db_alloc_string_array(nrows);
  37. i = 0;
  38. while ((row = mysql_fetch_row(res)) != NULL) {
  39. db_set_string(&list[i], row[0]);
  40. i++;
  41. }
  42. mysql_free_result(res);
  43. *tlist = list;
  44. *tcount = nrows;
  45. return DB_OK;
  46. }