浏览代码

v.db.addtable: create unique index

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@72945 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz 6 年之前
父节点
当前提交
8a588ac6d6
共有 1 个文件被更改,包括 8 次插入0 次删除
  1. 8 0
      scripts/v.db.addtable/v.db.addtable.py

+ 8 - 0
scripts/v.db.addtable/v.db.addtable.py

@@ -136,6 +136,14 @@ def main():
         except CalledModuleError:
             grass.fatal(_("Unable to create table <%s>") % table)
 
+        if driver != "dbf":
+            sql = "CREATE UNIQUE INDEX IF NOT EXISTS %s_%s ON %s (%s)" % (table, key, table, key)
+            try:
+		grass.run_command('db.execute',
+				  database=database, driver=driver, sql=sql)
+	    except:
+		grass.warning(_("Unable to create index on table <%s>") % table)
+
     # connect the map to the DB:
     if schema:
         table = '{schema}.{table}'.format(schema=schema, table=table)