GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
printtab.c
Go to the documentation of this file.
1 
15 #include <string.h>
16 #include <grass/dbmi.h>
17 
18 static void print_priv();
19 
26 void db_print_table_definition(FILE * fd, dbTable * table)
27 {
28  int ncols, col;
29  dbColumn *column;
30 
31  fprintf(fd, "table:%s\n", db_get_table_name(table));
32  fprintf(fd, "description:%s\n", db_get_table_description(table));
33  print_priv(fd, "insert", db_get_table_insert_priv(table));
34  print_priv(fd, "delete", db_get_table_delete_priv(table));
35 
36  ncols = db_get_table_number_of_columns(table);
37  fprintf(fd, "ncols:%d\n", ncols);
38  for (col = 0; col < ncols; col++) {
39  column = db_get_table_column(table, col);
40  fprintf(fd, "\n");
41  db_print_column_definition(fd, column);
42  }
43 }
44 
51 void db_print_column_definition(FILE * fd, dbColumn * column)
52 {
53  dbString value_string;
54 
55  fprintf(fd, "column:%s\n", db_get_column_name(column));
56  fprintf(fd, "description:%s\n", db_get_column_description(column));
57  fprintf(fd, "type:%s\n", db_sqltype_name(db_get_column_sqltype(column)));
58  fprintf(fd, "len:%d\n", db_get_column_length(column));
59  fprintf(fd, "scale:%d\n", db_get_column_scale(column));
60  fprintf(fd, "precision:%d\n", db_get_column_precision(column));
61  fprintf(fd, "default:");
63  db_init_string(&value_string);
64  db_convert_column_default_value_to_string(column, &value_string);
65  fprintf(fd, "%s", db_get_string(&value_string));
66  }
67  fprintf(fd, "\n");
68  fprintf(fd, "nullok:%s\n",
69  db_test_column_null_allowed(column) ? "yes" : "no");
70  print_priv(fd, "select", db_get_column_select_priv(column));
71  print_priv(fd, "update", db_get_column_update_priv(column));
72 }
73 
74 static void print_priv(FILE * fd, char *label, int priv)
75 {
76  fprintf(fd, "%s:", label);
77  switch (priv) {
78  case DB_GRANTED:
79  fprintf(fd, "yes");
80  break;
81  case DB_NOT_GRANTED:
82  fprintf(fd, "no");
83  break;
84  default:
85  fprintf(fd, "?");
86  break;
87  }
88  fprintf(fd, "\n");
89 }
dbColumn * db_get_table_column(dbTable *table, int n)
returns column structure for given table and column number
const char * db_sqltype_name(int sqltype)
returns sqltype description
Definition: sqltype.c:9
const char * db_get_column_description(dbColumn *column)
returns column description for given column
void db_print_table_definition(FILE *fd, dbTable *table)
Print table definition info.
Definition: printtab.c:26
const char * db_get_column_name(dbColumn *column)
returns column name for given column
tuple label
gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _(&quot;width&quot;)), pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
Definition: tools.py:1366
FILE * fd
Definition: g3dcolor.c:368
int db_get_column_update_priv(dbColumn *column)
int db_get_column_precision(dbColumn *column)
void db_print_column_definition(FILE *fd, dbColumn *column)
Print column definition info.
Definition: printtab.c:51
int db_get_column_select_priv(dbColumn *column)
int db_get_column_length(dbColumn *column)
int db_get_column_scale(dbColumn *column)
int db_get_column_sqltype(dbColumn *column)
returns column sqltype for column (the function db_sqltype_name() returns sqltype description) ...
int db_convert_column_default_value_to_string(dbColumn *column, dbString *string)
Definition: columnfmt.c:60
const char * db_get_table_description(dbTable *table)
int db_get_table_number_of_columns(dbTable *table)
int db_get_table_delete_priv(dbTable *table)
int db_test_column_has_default_value(dbColumn *column)
int db_get_table_insert_priv(dbTable *table)
char * db_get_string(dbString *x)
Definition: string.c:131
int db_test_column_null_allowed(dbColumn *column)
const char * db_get_table_name(dbTable *table)
void db_init_string(dbString *x)
Definition: string.c:11