GRASS GIS 7 Programmer's Manual  7.5.svn(2017)-r71933
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
printtab.c
Go to the documentation of this file.
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 
15 #include <string.h>
16 #include <grass/dbmi.h>
17 
18 static void print_priv(FILE * fd, char *label, int priv);
19 
20 /*!
21  \brief Print table definition info
22 
23  \param fd file descriptor
24  \param table table info
25 */
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 
45 /*!
46  \brief Print column definition info
47 
48  \param fd file descriptor
49  \param column column info
50 */
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 }
const char * db_sqltype_name(int sqltype)
Get SQL data type description.
Definition: sqltype.c:25
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.
#define DB_GRANTED
Definition: dbmi.h:128
int db_get_column_update_priv(dbColumn *column)
Get update privilages.
int db_get_column_precision(dbColumn *column)
Get column precision.
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)
Get select privilages.
int db_get_column_length(dbColumn *column)
Get column&#39;s length.
char * db_get_string(const dbString *x)
Get string.
Definition: string.c:140
fd
Definition: d/range.c:69
int db_get_column_scale(dbColumn *column)
Get column scale.
int db_get_column_sqltype(dbColumn *column)
Returns column sqltype for column.
int db_convert_column_default_value_to_string(dbColumn *column, dbString *string)
?
Definition: columnfmt.c:79
const char * db_get_table_description(dbTable *table)
Get the description of the table.
int db_get_table_number_of_columns(dbTable *table)
Return the number of columns of the table.
int db_get_table_delete_priv(dbTable *table)
Get table delete privileges.
int db_test_column_has_default_value(dbColumn *column)
Check if column has defined default value.
int db_get_table_insert_priv(dbTable *table)
Get table insert privileges.
#define DB_NOT_GRANTED
Definition: dbmi.h:129
int db_test_column_null_allowed(dbColumn *column)
Checks if null value is allowed.
const char * db_get_table_name(dbTable *table)
Get the name of the table.
dbColumn * db_get_table_column(dbTable *table, int idx)
Returns column structure for given table and column number.
void db_init_string(dbString *x)
Initialize dbString.
Definition: string.c:25