[GRASS-dev] [GRASS GIS] #2147: db.databases not working in GRASS 7

#2147: db.databases not working in GRASS 7
--------------------------+-------------------------------------------------
Reporter: cmbarton | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 7.0.0
Component: Database | Version: svn-trunk
Keywords: db.databases | Platform: Unspecified
      Cpu: OSX/Intel |
--------------------------+-------------------------------------------------
I just discovered that db.databases is not working in GRASS 7. Other db.*
modules seem to work OK.

{{{

db.databases location=nc_spm_08 driver=sqlite

dbmi: db_list_databases() not implemented
dbmi: db_list_databases() not implemented
ERROR: Unable to list databases

}}}

Not sure which exact version I have, but I built it 12 December 2013. I
don't know what version because g.version is not returning the version
number.

build_date=2013-12-12
libgis_revision=58048

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2147&gt;
GRASS GIS <http://grass.osgeo.org>

#2147: db.databases not working in GRASS 7
----------------------------------+-----------------------------------------
Reporter: cmbarton | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 7.0.0
Component: Database | Version: svn-trunk
Keywords: db.databases, sqlite | Platform: Unspecified
      Cpu: OSX/Intel |
----------------------------------+-----------------------------------------
Changes (by martinl):

  * keywords: db.databases => db.databases, sqlite

Comment:

This is strange. Function which list databases has been implemented for
SQLite driver 14 months ago (r53597). Do you have SQLite DB driver
compiled?

{{{
db.driver -p
}}}

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2147#comment:1&gt;
GRASS GIS <http://grass.osgeo.org>

#2147: db.databases not working in GRASS 7
----------------------------------+-----------------------------------------
Reporter: cmbarton | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 7.0.0
Component: Database | Version: svn-trunk
Keywords: db.databases, sqlite | Platform: Unspecified
      Cpu: OSX/Intel |
----------------------------------+-----------------------------------------

Comment(by martinl):

Replying to [comment:1 martinl]:

small typo in the last comment

{{{
db.drivers -p
}}}

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2147#comment:2&gt;
GRASS GIS <http://grass.osgeo.org>

#2147: db.databases not working in GRASS 7
----------------------------------+-----------------------------------------
Reporter: cmbarton | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 7.0.0
Component: Database | Version: svn-trunk
Keywords: db.databases, sqlite | Platform: Unspecified
      Cpu: OSX/Intel |
----------------------------------+-----------------------------------------

Comment(by cmbarton):

Replying to [comment:1 martinl]:
> This is strange. Function which list databases has been implemented for
SQLite driver 14 months ago (r53597). Do you have SQLite DB driver
compiled?
>
> {{{
> db.driver -p
> }}}

Yes. SQLite works fine and shows up in the driver list

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2147#comment:3&gt;
GRASS GIS <http://grass.osgeo.org>

#2147: db.databases not working in GRASS 7
----------------------------------+-----------------------------------------
Reporter: cmbarton | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 7.0.0
Component: Database | Version: svn-trunk
Keywords: db.databases, sqlite | Platform: All
      Cpu: OSX/Intel |
----------------------------------+-----------------------------------------
Changes (by neteler):

  * platform: Unspecified => All

Comment:

Confirmed problem on Fedora 19:

{{{
# using older copy of NC dataset location:
GRASS 7.0.svn (nc_spm_08):~ > db.drivers -p
ogr
sqlite
dbf

GRASS 7.0.svn (nc_spm_08):~ > g.gisenv set=DEBUG=1
GRASS 7.0.svn (nc_spm_08):~ > db.databases
D1/1: db_d_init_error(): DBF
dbmi: db_list_databases() not implemented
dbmi: db_list_databases() not implemented
ERROR: Unable to list databases

GRASS 7.0.svn (nc_spm_08):~ > db.connect -p
driver: dbf
database: /home/neteler/grassdata/nc_spm_08/user1/dbf/
schema:
group:

GRASS 7.0.svn (nc_spm_08):~ > db.connect -d
D1/1: Creating new default DB params with db_set_default_connection()
Default driver / database set to:
driver: sqlite
database: $GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db

GRASS 7.0.svn (nc_spm_08):~ > db.connect -p
driver: sqlite
database: /home/neteler/grassdata/nc_spm_08/user1/sqlite/sqlite.db
schema:
group:

GRASS 7.0.svn (nc_spm_08):~ > db.databases
D1/1: db_d_init_error(): SQLite
D1/1: db count = 0
No databases found
}}}

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2147#comment:4&gt;
GRASS GIS <http://grass.osgeo.org>

#2147: db.databases not working in GRASS 7
----------------------------------+-----------------------------------------
Reporter: cmbarton | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 7.0.0
Component: Database | Version: svn-trunk
Keywords: db.databases, sqlite | Platform: All
      Cpu: OSX/Intel |
----------------------------------+-----------------------------------------

Comment(by martinl):

Replying to [comment:4 neteler]:

{{{
> GRASS 7.0.svn (nc_spm_08):~ > db.databases
> D1/1: db_d_init_error(): DBF
> dbmi: db_list_databases() not implemented
> dbmi: db_list_databases() not implemented
> ERROR: Unable to list databases
>
> GRASS 7.0.svn (nc_spm_08):~ > db.connect -p
> driver: dbf
> database: /home/neteler/grassdata/nc_spm_08/user1/dbf/
> schema:
> group:
}}}

This is OK. DBF driver has no implemented function to list databases.

{{{
> GRASS 7.0.svn (nc_spm_08):~ > db.connect -d
> D1/1: Creating new default DB params with db_set_default_connection()
> Default driver / database set to:
> driver: sqlite
> database: $GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db
>
> GRASS 7.0.svn (nc_spm_08):~ > db.connect -p
> driver: sqlite
> database: /home/neteler/grassdata/nc_spm_08/user1/sqlite/sqlite.db
> schema:
> group:
>
> GRASS 7.0.svn (nc_spm_08):~ > db.databases
> D1/1: db_d_init_error(): SQLite
> D1/1: db count = 0
> No databases found
}}}

The command
{{{
db.connect -d
D1/1: Creating new default DB params with db_set_default_connection()
Default driver / database set to:
driver: sqlite
database: $GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db
}}}

doesn't create database, so `db.databases` doesn't list any database. You
need to run command which writes attribute data to the database.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2147#comment:5&gt;
GRASS GIS <http://grass.osgeo.org>

#2147: db.databases not working in GRASS 7
----------------------------------+-----------------------------------------
Reporter: cmbarton | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 7.0.0
Component: Database | Version: svn-trunk
Keywords: db.databases, sqlite | Platform: All
      Cpu: OSX/Intel |
----------------------------------+-----------------------------------------

Comment(by neteler):

Replying to [comment:5 martinl]:
> Replying to [comment:4 neteler]:

...

> {{{
> > GRASS 7.0.svn (nc_spm_08):~ > db.databases
> > D1/1: db_d_init_error(): SQLite
> > D1/1: db count = 0
> > No databases found
> }}}
>
> The command
> {{{
> db.connect -d
> D1/1: Creating new default DB params with db_set_default_connection()
> Default driver / database set to:
> driver: sqlite
> database: $GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db
> }}}
>
> doesn't create database, so `db.databases` doesn't list any
> database. You need to run command which writes attribute data
> to the database.

Good point.

Maybe "db.connect -d" should create the (empty) sqlite.db file to
avoid user confusion.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2147#comment:6&gt;
GRASS GIS <http://grass.osgeo.org>

#2147: db.databases not working in GRASS 7
----------------------------------+-----------------------------------------
Reporter: cmbarton | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 7.0.0
Component: Database | Version: svn-trunk
Keywords: db.databases, sqlite | Platform: All
      Cpu: OSX/Intel |
----------------------------------+-----------------------------------------

Comment(by martinl):

Replying to [comment:6 neteler]:
> Maybe "db.connect -d" should create the (empty) sqlite.db file to
> avoid user confusion.

Probably, in any case it should be discussed in the separate ticket. In
this case `db.connect` should behave similarly for all supported drivers,
ie. to create directory for DBF driver, new empty database for SQLite or
PostgreSQL drivers...

Martin

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2147#comment:7&gt;
GRASS GIS <http://grass.osgeo.org>

#2147: db.databases not working in GRASS 7
----------------------------------+-----------------------------------------
Reporter: cmbarton | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 7.0.0
Component: Database | Version: svn-trunk
Keywords: db.databases, sqlite | Platform: All
      Cpu: OSX/Intel |
----------------------------------+-----------------------------------------

Comment(by martinl):

Replying to [comment:3 cmbarton]:
> Yes. SQLite works fine and shows up in the driver list

It's strange, as I already mentioned, function to list databases has been
implemented for SQLite driver 14 months ago. Please could you check
source:grass/trunk/db/drivers/sqlite/listdb.c in your local source code
tree.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2147#comment:8&gt;
GRASS GIS <http://grass.osgeo.org>

#2147: db.databases not working in GRASS 7
----------------------------------+-----------------------------------------
Reporter: cmbarton | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 7.0.0
Component: Database | Version: svn-trunk
Keywords: db.databases, sqlite | Platform: All
      Cpu: OSX/Intel |
----------------------------------+-----------------------------------------

Comment(by cmbarton):

Replying to [comment:8 martinl]:
> Replying to [comment:3 cmbarton]:
> > Yes. SQLite works fine and shows up in the driver list
>
> It's strange, as I already mentioned, function to list databases has
been implemented for SQLite driver 14 months ago. Please could you check
source:grass/trunk/db/drivers/sqlite/listdb.c in your local source code
tree.

It is attached:

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2147#comment:9&gt;
GRASS GIS <http://grass.osgeo.org>

#2147: db.databases not working in GRASS 7
----------------------------------+-----------------------------------------
Reporter: cmbarton | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 7.0.0
Component: Database | Version: svn-trunk
Keywords: db.databases, sqlite | Platform: All
      Cpu: OSX/Intel |
----------------------------------+-----------------------------------------

Comment(by wenzeslaus):

Is something mentioned here still an issue?

If unclear state of source code is the remaining issue (as suggested by
last comments), please, check the file again. The best think to do is
probably
{{{
cd db/drivers/sqlite
svn status
}}}

However, `svn revert db/drivers/sqlite/listdb.c` and `svn up` and also
`svn diff` and `svn info` can be useful too.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2147#comment:10&gt;
GRASS GIS <http://grass.osgeo.org>

#2147: db.databases not working in GRASS 7
----------------------------------+-----------------------------------------
Reporter: cmbarton | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 7.0.0
Component: Database | Version: svn-trunk
Keywords: db.databases, sqlite | Platform: All
      Cpu: OSX/Intel |
----------------------------------+-----------------------------------------

Comment(by cmbarton):

I just checked and the behavior is the same as I originally reported. I've
run this from a mapset in my nc_spm_08 location that has a functioning
SQLITE database. That is, this mapset has vectors connected to an SQLITE
database that is working correctly. Yet I still get:

{{{

db.databases location=nc_spm_08nc_spm_08
dbmi: db_list_databases() not implemented
dbmi: db_list_databases() not implemented
ERROR: Unable to list databases. Try to define correct connection settings
        by db.login.

}}}

The manual defines "location" as follows:

"Default location for SQLite driver is the full path for the current
mapset. For PostgreSQL driver it's empty connection string. "

This is NOT standard usage of the word "location" in GRASS. Nonetheless,
it doesn't seem to work when I put in the proper pathname either.

{{{

db.databases location=$GISDBASE/$LOCATION_NAME/$MAPSET
dbmi: db_list_databases() not implemented
dbmi: db_list_databases() not implemented
ERROR: Unable to list databases. Try to define correct connection settings
        by db.login.

}}}

Same thing happens if I specify the path to the SQLite database itself:

{{{

db.databases location=$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db
dbmi: db_list_databases() not implemented
dbmi: db_list_databases() not implemented
ERROR: Unable to list databases. Try to define correct connection settings
        by db.login.

}}}

Maybe the command is no longer relevant. If it doesn't work, maybe it
should be dropped from the distribution.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2147#comment:11&gt;
GRASS GIS <http://grass.osgeo.org>