[GRASS-SVN] r40570 - grass/trunk/lib/db/dbmi_client
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Jan 20 04:11:10 EST 2010
Author: mmetz
Date: 2010-01-20 04:11:08 -0500 (Wed, 20 Jan 2010)
New Revision: 40570
Modified:
grass/trunk/lib/db/dbmi_client/copy_tab.c
grass/trunk/lib/db/dbmi_client/select.c
Log:
improved error handling, fix for trac #461
Modified: grass/trunk/lib/db/dbmi_client/copy_tab.c
===================================================================
--- grass/trunk/lib/db/dbmi_client/copy_tab.c 2010-01-20 09:02:57 UTC (rev 40569)
+++ grass/trunk/lib/db/dbmi_client/copy_tab.c 2010-01-20 09:11:08 UTC (rev 40570)
@@ -249,7 +249,7 @@
if (db_create_table(to_driver, out_table) != DB_OK) {
G_warning(_("Unable to create table <%s>"),
- out_table);
+ to_tblname);
db_close_database_shutdown_driver(to_driver);
if (from_driver != to_driver) {
db_close_database_shutdown_driver(from_driver);
Modified: grass/trunk/lib/db/dbmi_client/select.c
===================================================================
--- grass/trunk/lib/db/dbmi_client/select.c 2010-01-20 09:02:57 UTC (rev 40569)
+++ grass/trunk/lib/db/dbmi_client/select.c 2010-01-20 09:11:08 UTC (rev 40570)
@@ -115,6 +115,11 @@
G_debug(3, "db_select_int()");
+ if (col == NULL || strlen(col) == 0) {
+ G_warning(_("Missing column name"));
+ return -1;
+ }
+
/* allocate */
alloc = 1000;
val = (int *)G_malloc(alloc * sizeof(int));
@@ -206,6 +211,16 @@
dbValue *value;
dbTable *table;
+ if (key == NULL || strlen(key) == 0) {
+ G_warning(_("Missing key column name"));
+ return -1;
+ }
+
+ if (col == NULL || strlen(col) == 0) {
+ G_warning(_("Missing column name"));
+ return -1;
+ }
+
G_zero(val, sizeof(dbValue));
sprintf(buf, "SELECT %s FROM %s WHERE %s = %d\n", col, tab, key, id);
db_init_string(&stmt);
@@ -260,8 +275,17 @@
dbValue *value;
dbTable *table;
- G_debug(3, "db_select_db_select_CatValArray ()");
+ G_debug(3, "db_select_CatValArray ()");
+ if (key == NULL || strlen(key) == 0) {
+ G_warning(_("Missing key column name"));
+ return -1;
+ }
+
+ if (col == NULL || strlen(col) == 0) {
+ G_warning(_("Missing column name"));
+ return -1;
+ }
db_init_string(&stmt);
sprintf(buf, "SELECT %s, %s FROM %s", key, col, tab);
@@ -279,8 +303,12 @@
nrows = db_get_num_rows(&cursor);
G_debug(3, " %d rows selected", nrows);
- if (nrows < 0)
- G_fatal_error(_("Unable select records from table <%s>"), tab);
+ if (nrows < 0) {
+ G_warning(_("Unable select records from table <%s>"), tab);
+ db_close_cursor(&cursor);
+ db_free_string(&stmt);
+ return -1;
+ }
db_CatValArray_alloc(cvarr, nrows);
@@ -292,7 +320,10 @@
G_debug(3, " key type = %d", type);
if (type != DB_C_TYPE_INT) {
- G_fatal_error("Key column type is not integer");
+ G_warning(_("Key column type is not integer"));
+ db_close_cursor(&cursor);
+ db_free_string(&stmt);
+ return -1;
}
column = db_get_table_column(table, 1);
More information about the grass-commit
mailing list