[GRASS-dev] [GRASS-SVN] r73995 - grass/trunk/scripts/v.db.addtable

Huidae Cho grass4u at gmail.com
Sat Jan 26 05:50:02 PST 2019


Markus,

If there is a linked table, v.db.addtable stops in line 106. If not, this
script doesn't create a unique index and calls v.db.connect. v.db.connect
adds a db link in line 317 and creates a unique index (db_create_index2) in
line 334 if linking was successful. SQLite didn't complain when both
modules created the same unique index, but PostgreSQL failed in
v.db.connect (2nd time creating the same unique index). Not sure which code
was added first/later. I think it's more of how we design both modules.
v.db.connect will fail if we try to link a table with a unique index. Isn't
v.db.connect supposed to "just" connect a table to a layer (without
creating any database objects like index)? Which module should be
responsible for creating unique indices?

Before this commit:
1. v.db.addtable creates unique index
2. v.db.connect tries to create unique index again ==> fatal error

After this commit:
1. v.db.addtable doesn't create unique index
2. v.db.connect creates unique index

Probably, it should be:
1. v.db.addtable should create unique index
2. v.db.connect shouldn't try to create unique index? Just "connect"...

Regards,
Huidae

On Sat, Jan 26, 2019 at 7:39 AM Markus Neteler <neteler at osgeo.org> wrote:

> Hi,
>
> On Tue, Jan 22, 2019 at 3:51 AM <svn_grass at osgeo.org> wrote:
> >
> > Author: hcho
> > Date: 2019-01-21 18:51:33 -0800 (Mon, 21 Jan 2019)
> > New Revision: 73995
> >
> > Modified:
> >    grass/trunk/scripts/v.db.addtable/v.db.addtable.py
> > Log:
> > v.db.addtable: Do not create unique index from this script; v.db.connect
> will try to create it again causing some drivers to fail (PostgreSQL)
> >
> > Modified: grass/trunk/scripts/v.db.addtable/v.db.addtable.py
> > ===================================================================
> > --- grass/trunk/scripts/v.db.addtable/v.db.addtable.py  2019-01-21
> 22:37:59 UTC (rev 73994)
> > +++ grass/trunk/scripts/v.db.addtable/v.db.addtable.py  2019-01-22
> 02:51:33 UTC (rev 73995)
> > @@ -139,16 +139,6 @@
> >          except CalledModuleError:
> >              grass.fatal(_("Unable to create table <%s>") % table)
> >
> > -        # create index, see db/driver/*/index.c
> > -        if driver != "dbf":
> > -            sql = "CREATE UNIQUE INDEX %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)
> > -                pass
> > -
> >      # connect the map to the DB:
> >      if schema:
> >          table = '{schema}.{table}'.format(schema=schema, table=table)
>
> just a conceptual question:
> ... are we sure that this index creation removal never leads to a
> table without index?
>
> Markus
>


-- 
Huidae Cho, Ph.D., GISP, PE (MD), CFM, M.ASCE
Open Source GIS Developer, GRASS GIS Development Team
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20190126/50aefba0/attachment.html>


More information about the grass-dev mailing list