Opened 6 years ago

Closed 3 years ago

#2147 closed defect (fixed)

db.databases not working in GRASS 7

Reported by: cmbarton Owned by: grass-dev@…
Priority: normal Milestone: 7.0.5
Component: Database Version: svn-trunk
Keywords: db.databases, sqlite Cc:
CPU: OSX/Intel Platform: All

Description

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

Attachments (1)

listdb.c (4.3 KB) - added by cmbarton 6 years ago.

Download all attachments as: .zip

Change History (14)

comment:1 Changed 6 years ago by martinl

Keywords: sqlite added

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

comment:2 in reply to:  1 Changed 6 years ago by martinl

Replying to martinl:

small typo in the last comment

db.drivers -p

comment:3 in reply to:  1 ; Changed 6 years ago by cmbarton

Replying to 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

comment:4 Changed 6 years ago by neteler

Platform: UnspecifiedAll

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

comment:5 in reply to:  4 ; Changed 6 years ago by martinl

Replying to 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.

comment:6 in reply to:  5 ; Changed 6 years ago by neteler

Replying to martinl:

Replying to 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.

comment:7 in reply to:  6 Changed 6 years ago by martinl

Replying to 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

comment:8 in reply to:  3 ; Changed 6 years ago by martinl

Replying to 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.

Changed 6 years ago by cmbarton

Attachment: listdb.c added

comment:9 in reply to:  8 Changed 6 years ago by cmbarton

Replying to martinl:

Replying to 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:

comment:10 Changed 5 years ago 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.

comment:11 Changed 5 years ago 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.

comment:12 Changed 3 years ago by martinl

Milestone: 7.0.07.0.5

comment:13 Changed 3 years ago by martinl

Resolution: fixed
Status: newclosed

Tested with 7.0.5:

db.databases location=/opt/grassdata/piemonte/PERMANENT/sqlite/ driver=sqlite
/opt/grassdata/piemonte/PERMANENT/sqlite//sqlite.db

Closing.

Note: See TracTickets for help on using tickets.