浏览代码

improved error handling, fix for trac https://trac.osgeo.org/grass/ticket/461

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@40570 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz 15 年之前
父节点
当前提交
a87a5207da
共有 2 个文件被更改,包括 36 次插入5 次删除
  1. 1 1
      lib/db/dbmi_client/copy_tab.c
  2. 35 4
      lib/db/dbmi_client/select.c

+ 1 - 1
lib/db/dbmi_client/copy_tab.c

@@ -249,7 +249,7 @@ int db__copy_table(const char *from_drvname, const char *from_dbname,
 
     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);

+ 35 - 4
lib/db/dbmi_client/select.c

@@ -115,6 +115,11 @@ int db_select_int(dbDriver * driver, const char *tab, const char *col,
 
     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 @@ int db_select_value(dbDriver * driver, const char *tab, const char *key,
     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 @@ int db_select_CatValArray(dbDriver * driver, const char *tab, const char *key,
     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 @@ int db_select_CatValArray(dbDriver * driver, const char *tab, const char *key,
 
     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 @@ int db_select_CatValArray(dbDriver * driver, const char *tab, const char *key,
     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);