瀏覽代碼

v.db.addtable: Check for duplicate column names

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@70634 15284696-431f-4ddb-bdfa-cd5b030d7da7
Huidae Cho 8 年之前
父節點
當前提交
630eed1b9b
共有 1 個文件被更改,包括 10 次插入4 次删除
  1. 10 4
      scripts/v.db.addtable/v.db.addtable.py

+ 10 - 4
scripts/v.db.addtable/v.db.addtable.py

@@ -106,15 +106,21 @@ def main():
                                 stderr=nuldev)
 
     if not table in tables.splitlines():
+        colnames = []
         if columns:
-            column_def = [x.strip().lower() for x in columns.strip().split(',')]
+            column_def = []
+            for x in ' '.join(columns.lower().split()).split(','):
+                colname = x.split()[0]
+                if colname in colnames:
+                    grass.fatal(_("Duplicate column name '%s' not allowed") % colname)
+                colnames.append(colname)
+                column_def.append(x)
         else:
             column_def = []
 
         # if not existing, create it:
-        column_def_key = "%s integer" % key
-        if column_def_key not in column_def:
-            column_def.insert(0, column_def_key)
+        if not key in colnames:
+            column_def.insert(0, "%s integer" % key)
         column_def = ','.join(column_def)
 
         grass.verbose(_("Creating table with columns (%s)...") % column_def)