[GRASS-SVN] r48380 - grass/trunk/scripts/v.db.join
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Sep 20 08:57:30 EDT 2011
Author: huhabla
Date: 2011-09-20 05:57:29 -0700 (Tue, 20 Sep 2011)
New Revision: 48380
Modified:
grass/trunk/scripts/v.db.join/v.db.join.py
Log:
Sqlite3 does not support the precision number. Do not call db.addcolumn
if column esists in vector map table.
Modified: grass/trunk/scripts/v.db.join/v.db.join.py
===================================================================
--- grass/trunk/scripts/v.db.join/v.db.join.py 2011-09-20 12:03:28 UTC (rev 48379)
+++ grass/trunk/scripts/v.db.join/v.db.join.py 2011-09-20 12:57:29 UTC (rev 48380)
@@ -32,7 +32,7 @@
#%end
#%option G_OPT_DB_COLUMN
-#% description: Join column in table
+#% description: Identifier column (e.g.: cat) in the vector table to be used for join
#% required : yes
#%end
@@ -45,7 +45,7 @@
#%option G_OPT_DB_COLUMN
#% key: ocolumn
-#% description: Join column in other table
+#% description: Identifier column (e.g.: id) in the other table used for join
#% required: yes
#%end
@@ -76,26 +76,35 @@
if not grass.vector_columns(map, layer).has_key(column):
grass.fatal(_("Column <%> not found in table <%s> at layer <%s>") % (column, map, layer))
- cols = grass.db_describe(otable, driver = driver, database = database)['cols']
+ all_cols_ot = grass.db_describe(otable, driver = driver, database = database)['cols']
+ all_cols_tt = grass.vector_columns(map, int(layer)).keys()
select = "SELECT $colname FROM $otable WHERE $otable.$ocolumn=$table.$column"
template = string.Template("UPDATE $table SET $colname=(%s);" % select)
- for col in cols:
+ for col in all_cols_ot:
+ # Skip the vector column which is used for join
colname = col[0]
- if len(col) > 2:
+ if colname == column:
+ continue
+ # Sqlite 3 does not support the precision number any more
+ if len(col) > 2 and driver != "sqlite":
coltype = "%s(%s)" % (col[1], col[2])
else:
coltype = "%s" % col[1]
+
colspec = "%s %s" % (colname, coltype)
- if grass.run_command('v.db.addcolumn', map = map, columns = colspec, layer = layer) != 0:
- grass.fatal(_("Error creating column <%s>.") % colname)
+ # Add only the new column to the table
+ if colname not in all_cols_tt:
+ if grass.run_command('v.db.addcolumn', map = map, columns = colspec, layer = layer) != 0:
+ grass.fatal(_("Error creating column <%s>.") % colname)
stmt = template.substitute(table = maptable, column = column,
otable = otable, ocolumn = ocolumn,
colname = colname)
+ grass.verbose("Update column <" + colname + "> of vector map <" + map + ">")
if grass.write_command('db.execute', stdin = stmt, input = '-', database = database, driver = driver) != 0:
grass.fatal(_("Error filling column <%s>.") % colname)
More information about the grass-commit
mailing list