[GRASS-dev] db function needed to check if column exists in table

Markus Neteler neteler at osgeo.org
Mon Jan 30 05:38:33 EST 2012


to my knowledge no DBMI function exists yet to check if a column exists
in (vector) table.


     db_get_column(driver, hcolumn,key, &column);
     if (!column)
         G_fatal_error(_("Missing column <%s> in table <%s>"), hcolumn, table);

Or this one (used in r50492, here modified):

      if ((col_type =
           db_column_Ctype(Driver, table, column)) == -1)
           G_fatal_error(_("Column <%s> not found in table <%s>"),
column, table);

I am not familiar enough with DBMI but do see the need to have such a function.
Rationale: the SQLite backend happily accepts nonsensical names and the test
should become a single line rather than the currently used workarounds in
v.to.rast/support.c or v.extrude/main.c or the like.


More information about the grass-dev mailing list