listtab.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. db_d_append_error("%s\%s",
  30. _("Unable get list of tables:"),
  31. mysql_error(connection));
  32. db_d_report_error();
  33. return DB_FAILED;
  34. }
  35. mysql_store_result(connection);
  36. nrows = (int)mysql_num_rows(res);
  37. list = db_alloc_string_array(nrows);
  38. i = 0;
  39. while ((row = mysql_fetch_row(res)) != NULL) {
  40. db_set_string(&list[i], row[0]);
  41. i++;
  42. }
  43. mysql_free_result(res);
  44. *tlist = list;
  45. *tcount = nrows;
  46. return DB_OK;
  47. }