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

Markus Metz markus.metz.giswork at googlemail.com
Mon Jan 30 05:57:42 EST 2012


On Mon, Jan 30, 2012 at 11:38 AM, Markus Neteler <neteler at osgeo.org> wrote:
> Hi
>
> to my knowledge no DBMI function exists yet to check if a column exists
> in (vector) table.
>
> Suggestions:
>
>     db_get_column(driver, hcolumn,key, &column);
>     if (!column)
>         G_fatal_error(_("Missing column <%s> in table <%s>"), hcolumn, table);
>

int db_get_column(dbDriver * Driver, const char *tname, const char *cname,
		  dbColumn ** Column);

exists in lib/db/dbmi_client/cloumn.c. This function sets *Column to
NULL and returns DB_Failed if the column does not exist.

Try v.extrude in trunk r50546 for an example.

Markus M


> 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.
>
> Markus
> _______________________________________________
> grass-dev mailing list
> grass-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-dev


More information about the grass-dev mailing list