[GRASS-SVN] r53967 - grass/trunk/scripts/v.db.reconnect.all
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Nov 22 00:51:35 PST 2012
Author: martinl
Date: 2012-11-22 00:51:34 -0800 (Thu, 22 Nov 2012)
New Revision: 53967
Modified:
grass/trunk/scripts/v.db.reconnect.all/v.db.reconnect.all.html
grass/trunk/scripts/v.db.reconnect.all/v.db.reconnect.all.py
Log:
v.db.reconnect.all -c: tries also to create index on key column
Modified: grass/trunk/scripts/v.db.reconnect.all/v.db.reconnect.all.html
===================================================================
--- grass/trunk/scripts/v.db.reconnect.all/v.db.reconnect.all.html 2012-11-22 06:27:50 UTC (rev 53966)
+++ grass/trunk/scripts/v.db.reconnect.all/v.db.reconnect.all.html 2012-11-22 08:51:34 UTC (rev 53967)
@@ -7,7 +7,9 @@
<p>
Optionally attribute tables in <b>new_database</b> can be created if
-not exist by <b>-c</b> flag.
+not exist by <b>-c</b> flag. In this case <em>v.db.reconnect.all</em>
+also tries to create index on key column (usually "cat"
+column).
<h2>NOTES</h2>
Modified: grass/trunk/scripts/v.db.reconnect.all/v.db.reconnect.all.py
===================================================================
--- grass/trunk/scripts/v.db.reconnect.all/v.db.reconnect.all.py 2012-11-22 06:27:50 UTC (rev 53966)
+++ grass/trunk/scripts/v.db.reconnect.all/v.db.reconnect.all.py 2012-11-22 08:51:34 UTC (rev 53967)
@@ -107,7 +107,15 @@
driver = driver, database = database,
table = table, stderr = nuldev):
grass.fatal(_("Unable to drop table <%s>") % table)
-
+
+# create index on key column
+def create_index(driver, database, table, index_name, key):
+ grass.info(_("Creating index <%s>...") % index_name)
+ if 0 != grass.run_command('db.execute', quiet = True,
+ driver = driver, database = database,
+ sql = "create index %s on %s(%s)" % (index_name, table, key)):
+ grass.warning(_("Unable to create index <%s>") % index_name)
+
def main():
old_database = substitute_db(options['old_database'])
if options['new_driver']:
@@ -163,6 +171,10 @@
copy_tab(driver, database, schema_table,
new_driver, new_database, new_schema_table)
+ # try to build index on key column
+ create_index(new_driver, new_database, new_schema_table,
+ table + '_' + key, key)
+
# reconnect tables
if 0 != grass.run_command('v.db.connect', flags = 'o', quiet = True, map = vect,
layer = layer, driver = new_driver, database = new_database,
@@ -176,7 +188,10 @@
else:
grass.warning(_("Layer <%d> will not be reconnected, "
"database or schema do not match.") % layer)
-
+
+ grass.info(_("It's recommended to change default DB connection settings. "
+ "See 'db.connect' for details."))
+
return 0
if __name__ == "__main__":
More information about the grass-commit
mailing list