GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
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 }
void db_print_table_definition(FILE *fd, dbTable *table)
Print table definition info.
Definition: printtab.c:26
int db_get_column_length(dbColumn *)
Get column&#39;s length.
const char * db_get_column_name(dbColumn *)
Returns column name for given column.
void db_init_string(dbString *)
Initialize dbString.
Definition: string.c:25
#define DB_GRANTED
Definition: dbmi.h:128
const char * db_get_table_name(dbTable *)
Get the name of the table.
int db_get_column_select_priv(dbColumn *)
Get select privileges.
char * db_get_string(const dbString *)
Get string.
Definition: string.c:140
void db_print_column_definition(FILE *fd, dbColumn *column)
Print column definition info.
Definition: printtab.c:51
int db_test_column_has_default_value(dbColumn *)
Check if column has defined default value.
int db_get_column_precision(dbColumn *)
Get column precision.
int db_get_column_update_priv(dbColumn *)
Get update privileges.
int db_get_column_sqltype(dbColumn *)
Returns column sqltype for column.
const char * db_sqltype_name(int)
Get SQL data type description.
Definition: sqltype.c:25
int db_test_column_null_allowed(dbColumn *)
Checks if null value is allowed.
const char * db_get_table_description(dbTable *)
Get the description of the table.
int db_get_table_delete_priv(dbTable *)
Get table delete privileges.
const char * db_get_column_description(dbColumn *)
Returns column description for given column.
dbColumn * db_get_table_column(dbTable *, int)
Returns column structure for given table and column number.
#define DB_NOT_GRANTED
Definition: dbmi.h:129
int db_get_table_insert_priv(dbTable *)
Get table insert privileges.
int db_get_table_number_of_columns(dbTable *)
Return the number of columns of the table.
int db_get_column_scale(dbColumn *)
Get column scale.
int db_convert_column_default_value_to_string(dbColumn *, dbString *)
?
Definition: columnfmt.c:79