printtab.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*!
  2. * \file db/dbmi_client/printtab.c
  3. *
  4. * \brief DBMI Library (client) - print table description info
  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 <string.h>
  15. #include <grass/dbmi.h>
  16. static void print_priv(FILE * fd, char *label, int priv);
  17. /*!
  18. \brief Print table definition info
  19. \param fd file descriptor
  20. \param table table info
  21. */
  22. void db_print_table_definition(FILE * fd, dbTable * table)
  23. {
  24. int ncols, col;
  25. dbColumn *column;
  26. fprintf(fd, "table:%s\n", db_get_table_name(table));
  27. fprintf(fd, "description:%s\n", db_get_table_description(table));
  28. print_priv(fd, "insert", db_get_table_insert_priv(table));
  29. print_priv(fd, "delete", db_get_table_delete_priv(table));
  30. ncols = db_get_table_number_of_columns(table);
  31. fprintf(fd, "ncols:%d\n", ncols);
  32. for (col = 0; col < ncols; col++) {
  33. column = db_get_table_column(table, col);
  34. fprintf(fd, "\n");
  35. db_print_column_definition(fd, column);
  36. }
  37. }
  38. /*!
  39. \brief Print column definition info
  40. \param fd file descriptor
  41. \param column column info
  42. */
  43. void db_print_column_definition(FILE * fd, dbColumn * column)
  44. {
  45. dbString value_string;
  46. fprintf(fd, "column:%s\n", db_get_column_name(column));
  47. fprintf(fd, "description:%s\n", db_get_column_description(column));
  48. fprintf(fd, "type:%s\n", db_sqltype_name(db_get_column_sqltype(column)));
  49. fprintf(fd, "len:%d\n", db_get_column_length(column));
  50. fprintf(fd, "scale:%d\n", db_get_column_scale(column));
  51. fprintf(fd, "precision:%d\n", db_get_column_precision(column));
  52. fprintf(fd, "default:");
  53. if (db_test_column_has_default_value(column)) {
  54. db_init_string(&value_string);
  55. db_convert_column_default_value_to_string(column, &value_string);
  56. fprintf(fd, "%s", db_get_string(&value_string));
  57. }
  58. fprintf(fd, "\n");
  59. fprintf(fd, "nullok:%s\n",
  60. db_test_column_null_allowed(column) ? "yes" : "no");
  61. print_priv(fd, "select", db_get_column_select_priv(column));
  62. print_priv(fd, "update", db_get_column_update_priv(column));
  63. }
  64. static void print_priv(FILE * fd, char *label, int priv)
  65. {
  66. fprintf(fd, "%s:", label);
  67. switch (priv) {
  68. case DB_GRANTED:
  69. fprintf(fd, "yes");
  70. break;
  71. case DB_NOT_GRANTED:
  72. fprintf(fd, "no");
  73. break;
  74. default:
  75. fprintf(fd, "?");
  76. break;
  77. }
  78. fprintf(fd, "\n");
  79. }