|
@@ -95,6 +95,8 @@ def main():
|
|
driver = kv['driver']
|
|
driver = kv['driver']
|
|
schema = kv['schema']
|
|
schema = kv['schema']
|
|
|
|
|
|
|
|
+ database2 = database.replace('$MAP/', map_name + '/')
|
|
|
|
+
|
|
# maybe there is already a table linked to the selected layer?
|
|
# maybe there is already a table linked to the selected layer?
|
|
nuldev = open(os.devnull, 'w')
|
|
nuldev = open(os.devnull, 'w')
|
|
try:
|
|
try:
|
|
@@ -104,22 +106,21 @@ def main():
|
|
pass
|
|
pass
|
|
|
|
|
|
# maybe there is already a table with that name?
|
|
# maybe there is already a table with that name?
|
|
- tables = grass.read_command('db.tables', flags='p', database=database, driver=driver,
|
|
|
|
|
|
+ tables = grass.read_command('db.tables', flags='p', database=database2, driver=driver,
|
|
stderr=nuldev)
|
|
stderr=nuldev)
|
|
tables = decode(tables)
|
|
tables = decode(tables)
|
|
|
|
|
|
if not table in tables.splitlines():
|
|
if not table in tables.splitlines():
|
|
colnames = []
|
|
colnames = []
|
|
|
|
+ column_def = []
|
|
if columns:
|
|
if columns:
|
|
column_def = []
|
|
column_def = []
|
|
- for x in ' '.join(columns.lower().split()).split(','):
|
|
|
|
- colname = x.split()[0]
|
|
|
|
|
|
+ for x in ' '.join(columns.split()).split(','):
|
|
|
|
+ colname = x.lower().split()[0]
|
|
if colname in colnames:
|
|
if colname in colnames:
|
|
grass.fatal(_("Duplicate column name '%s' not allowed") % colname)
|
|
grass.fatal(_("Duplicate column name '%s' not allowed") % colname)
|
|
colnames.append(colname)
|
|
colnames.append(colname)
|
|
column_def.append(x)
|
|
column_def.append(x)
|
|
- else:
|
|
|
|
- column_def = []
|
|
|
|
|
|
|
|
# if not existing, create it:
|
|
# if not existing, create it:
|
|
if not key in colnames:
|
|
if not key in colnames:
|
|
@@ -131,13 +132,14 @@ def main():
|
|
sql = "CREATE TABLE %s (%s)" % (table, column_def)
|
|
sql = "CREATE TABLE %s (%s)" % (table, column_def)
|
|
try:
|
|
try:
|
|
grass.run_command('db.execute',
|
|
grass.run_command('db.execute',
|
|
- database=database, driver=driver, sql=sql)
|
|
|
|
|
|
+ database=database2, driver=driver, sql=sql)
|
|
except CalledModuleError:
|
|
except CalledModuleError:
|
|
grass.fatal(_("Unable to create table <%s>") % table)
|
|
grass.fatal(_("Unable to create table <%s>") % table)
|
|
|
|
|
|
# connect the map to the DB:
|
|
# connect the map to the DB:
|
|
if schema:
|
|
if schema:
|
|
table = '{schema}.{table}'.format(schema=schema, table=table)
|
|
table = '{schema}.{table}'.format(schema=schema, table=table)
|
|
|
|
+ grass.verbose(_("Connecting new table to vector map <%s>...") % map_name)
|
|
grass.run_command('v.db.connect', quiet=True,
|
|
grass.run_command('v.db.connect', quiet=True,
|
|
map=map_name, database=database, driver=driver,
|
|
map=map_name, database=database, driver=driver,
|
|
layer=layer, table=table, key=key)
|
|
layer=layer, table=table, key=key)
|