[GRASS-SVN] r49239 - grass/trunk/vector/v.colors

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Nov 14 04:29:39 EST 2011


Author: martinl
Date: 2011-11-14 01:29:39 -0800 (Mon, 14 Nov 2011)
New Revision: 49239

Modified:
   grass/trunk/vector/v.colors/write_rgb.c
Log:
v.colors: add rgb column automatically when doesn't exists


Modified: grass/trunk/vector/v.colors/write_rgb.c
===================================================================
--- grass/trunk/vector/v.colors/write_rgb.c	2011-11-14 09:00:34 UTC (rev 49238)
+++ grass/trunk/vector/v.colors/write_rgb.c	2011-11-14 09:29:39 UTC (rev 49239)
@@ -25,11 +25,41 @@
 	G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
 		      fi->database, fi->driver);
 
+    db_init_string(&stmt);
+    
     ctype = db_column_Ctype(driver, fi->table, column_name);
-    if (ctype == -1)
-	G_fatal_error(_("Column <%s> not found in table <%s>"),
-		      column_name, fi->table);
-    if (ctype != DB_C_TYPE_STRING)
+    if (ctype == -1) {
+	sprintf(buf, "ALTER TABLE %s ADD COLUMN %s VARCHAR(11)",
+		fi->table, column_name);
+	db_set_string(&stmt, buf);
+	if (db_execute_immediate(driver, &stmt) != DB_OK)
+	    G_fatal_error(_("Unable to add column <%s> to table <%s>"),
+			  column_name, fi->table);
+
+	/*
+	  db_add_column needs to be implemented for DB drivers first...
+	  
+	  dbString table;
+	  dbColumn column;
+	  
+	  db_init_column(&column);
+	  db_set_column_name(&column, column_name);
+	  db_set_column_sqltype(&column, DB_SQL_TYPE_CHARACTER);
+	  db_set_column_null_allowed(&column);
+	  db_set_column_length(&column, 11);
+	  
+	  db_init_string(&table);
+	  db_set_string(&table, fi->table);
+	  if (db_add_column(driver, &table, &column) != DB_OK)
+	  G_fatal_error(_("Unable to add column <%s> to table <%s>"),
+	  column_name, fi->table);
+	  db_free_column(&column);
+	*/
+
+	G_important_message(_("Column <%s> added to table <%s>"),
+			     column_name, fi->table);
+    }
+    else if (ctype != DB_C_TYPE_STRING)
 	G_fatal_error(_("Data type of column <%s> must be char"), column_name);
 	
     nrec = db_select_int(driver, fi->table, fi->key, NULL, &pval);
@@ -38,7 +68,6 @@
 	return;
     }
     
-    db_init_string(&stmt);
     db_begin_transaction(driver);
     
     for (i = 0; i < nrec; i++) {



More information about the grass-commit mailing list