printtab.c

Go to the documentation of this file.
00001 #include <string.h>
00002 #include <grass/dbmi.h>
00003 
00004 static void print_priv();
00005 
00012 void
00013 db_print_table_definition (FILE *fd, dbTable *table)
00014 
00015 {
00016     int ncols, col;
00017     dbColumn *column;
00018 
00019     fprintf (fd, "table:%s\n", db_get_table_name(table));
00020     fprintf (fd, "description:%s\n", db_get_table_description(table));
00021     print_priv (fd, "insert", db_get_table_insert_priv(table));
00022     print_priv (fd, "delete", db_get_table_delete_priv(table));
00023 
00024     ncols = db_get_table_number_of_columns(table);
00025     fprintf (fd, "ncols:%d\n", ncols);
00026     for (col = 0; col < ncols; col++)
00027     {
00028         column = db_get_table_column (table, col);
00029         fprintf (fd, "\n");
00030         db_print_column_definition (fd, column);
00031     }
00032 }
00033 
00034 void
00035 db_print_column_definition (FILE *fd, dbColumn *column)
00036 
00037 {
00038     dbString value_string;
00039 
00040     fprintf (fd, "column:%s\n", db_get_column_name(column));
00041     fprintf (fd, "description:%s\n", db_get_column_description(column));
00042     fprintf (fd, "type:%s\n", db_sqltype_name(db_get_column_sqltype(column)));
00043     fprintf (fd, "len:%d\n", db_get_column_length(column));
00044     fprintf (fd, "scale:%d\n", db_get_column_scale(column));
00045     fprintf (fd, "precision:%d\n", db_get_column_precision(column));
00046     fprintf (fd, "default:");
00047     if (db_test_column_has_default_value(column))
00048     {
00049       db_init_string(&value_string);
00050       db_convert_column_default_value_to_string (column, &value_string);
00051       fprintf (fd, "%s", db_get_string(&value_string));
00052     }
00053     fprintf (fd, "\n");
00054     fprintf (fd, "nullok:%s\n", db_test_column_null_allowed(column) ? "yes" : "no");
00055     print_priv (fd, "select", db_get_column_select_priv(column));
00056     print_priv (fd, "update", db_get_column_update_priv(column));
00057 }
00058 
00059 static void
00060 print_priv  (FILE *fd, char *label, int priv)
00061 
00062 {
00063     fprintf (fd, "%s:", label);
00064     switch (priv)
00065     {
00066     case DB_GRANTED:     fprintf (fd, "yes"); break;
00067     case DB_NOT_GRANTED: fprintf (fd, "no"); break;
00068     default:             fprintf (fd, "?"); break;
00069     }
00070     fprintf (fd, "\n");
00071 }

Generated on Sun Apr 6 17:31:38 2008 for GRASS by  doxygen 1.5.5