[Bug] DB drivers don't work on Windows with the CMake/MSVC build (conda-forge 8.5.0): "db_open_database() not implemented"

Aperta
#8,291 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
38/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
c, cmake

Direzione di ricerca

Start with db/drivers/CMakeLists.txt, lib/db/dbmi_base/dbstubs.h, lib/db/dbmi_driver/driver.c, lib/gis/rename.c, and G_copy_file() to verify the three Windows-specific failures described in the report. Reproduce with the listed db.execute command on the MSVC build, then check database operations including a second DBF insert. Done means SQLite and DBF database operations work on Windows without protocol hangs or truncated files.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

Describe the bug

With GRASS 8.5.0 from conda-forge on Windows, nothing that needs an attribute database works. Both the sqlite and dbf drivers fail as soon as a database is opened. Raster and temporal modules are fine. The problem shows up in v.import, v.in.ogr (without -t), db.execute and v.rast.stats.

To reproduce

In a fresh project:

grass -c EPSG:4326 -e C:\tmp\repro
echo CREATE TABLE t (a integer) > C:\tmp\t.sql
grass C:\tmp\repro\PERMANENT --exec db.execute input=C:\tmp\t.sql

Output:

dbmi: db_open_database() not implemented
dbmi: db_open_database() not implemented
ERROR: Unable to open database
       <$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db>

After db.connect driver=dbf database='$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/' I get the same thing:

dbmi: db_open_database() not implemented
dbmi: db_open_database() not implemented
ERROR: Unable to open database <$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/>

Expected behavior

The table is created.

Screenshots

None; the output is text and is quoted above.

System description

  • Operating System: Windows 11 Pro for Workstations (10.0.26300)
  • GRASS version: 8.5.0, conda-forge package for win-64, build py314h1fbbb69_1 (CMake/MSVC build)

g.version -rge:

version=8.5.0
date=2026
revision=exported
build_date=2026-05-16
build_platform=x86_64
build_off_t_size=8
libgis_revision=8.5.0
libgis_date=2026-05-16T18:00:31+00:00
proj=9.7.1
gdal=3.12.3
geos=3.14.1
sqlite=3.53.1

Python and wxPython:

3.14.10 | packaged by conda-forge | (main, Oct 26 2026, 11:40:34) [MSC v.1944 64 bit (AMD64)]
4.3.2 msw (phoenix) wxWidgets 3.3.4

Additional context

Cause

I tracked this down to three problems that only affect the MSVC build. All three look like they are still on main.

  1. The function pointers end up in the wrong place.

    grass_dbmidriver.dll calls the driver through the db_driver_* pointers from lib/db/dbmi_base/dbstubs.h. The DLL exports 32 of them, initialised to the stubs in grass_dbstubs.dll. Each driver's main() calls init_dbdriver() to point them at its own functions.

    But db/drivers/CMakeLists.txt adds -DDB_DRIVER_C=1 for the drivers when building with MSVC. With that define, dbstubs.h defines the pointer variables inside the driver exe. So init_dbdriver() sets the exe's own copies, and the DLL keeps calling the stubs. The stub for open_database is the one that prints "not implemented".

    objdump agrees. sqlite.exe imports only four symbols from grass_dbmidriver.dll, and none of them are the pointers:

    $ objdump -p driver/db/sqlite.exe   (imports from grass_dbmidriver.dll)
            83b0      33  db_d_init_error
            839c      42  db_d_report_error
            83c2      45  db_driver
            8388      13  db_d_append_error
    
  2. The driver's stdin/stdout stay in text mode.

    In lib/db/dbmi_driver/driver.c, the _setmode(..., _O_BINARY) calls on stdin and stdout are inside #ifdef __MINGW32__, so they are skipped with MSVC. The client opens its end of the pipes in binary mode (dbmi_client/start.c), but the driver reads and writes in text mode. Once problem 1 was fixed, small tables worked. Any table whose protocol data contained a byte like 0x0A then hung: db.describe, db.select and v.info -c on a 6-column table from v.in.ogr all hung.

  3. G_rename_file() can't replace an existing file.

    This one hit the dbf driver, which saves a table by writing a temp file and calling G_rename_file() on it. In lib/gis/rename.c the remove(newname) is inside #ifdef __MINGW32__. With MSVC, rename() fails because the target exists, so it falls back to G_copy_file(), which copies with fopen(..., "r") / fopen(..., "w") in text mode. The second INSERT into a dbf table left a 3-byte .dbf file: the copy stopped at the first 0x1A byte, which is the day byte in the header. This is in libgis, so other callers that rename over an existing file may be affected too. I haven't checked which.

Tested fix (local rebuild of the sqlite and dbf drivers)

I rebuilt sqlite.exe and dbf.exe from the 8.5.0 sources. I used gcc (MinGW-w64, UCRT) against the conda-forge DLLs, not MSVC, with these changes:

  • the extern pointer declarations in dbstubs.h marked __declspec(dllimport), and no DB_DRIVER_C;
  • in the driver's main(), before init_dbdriver():
_setmode(_fileno(stdin), _O_BINARY);
_setmode(_fileno(stdout), _O_BINARY);
  • dbf only: remove(db.tables[t].file); before the G_rename_file() call in save_table().

With those drivers everything I tried works: db.execute, db.select, db.describe, v.in.ogr with attributes, v.db.select, v.to.db and v.rast.stats. For dbf I also needed fixes for some problems that aren't Windows-specific; I'm reporting those separately.

For the real fix I would guess:

  • drop DB_DRIVER_C for the drivers on MSVC and add a proper import/export macro to the pointer declarations in dbstubs.h;
  • change #ifdef __MINGW32__ to #ifdef _WIN32 around the _setmode calls in driver.c and the remove() in rename.c;
  • make G_copy_file() use binary mode.

I haven't tried that in the CMake build itself.

Workaround

Workaround without rebuilding anything: import vectors without a table (v.in.ogr -t), rasterize them with v.to.rast use=cat, and use r.univar / t.rast.univar zones= for zonal statistics.

I didn't find an existing issue for this here or on conda-forge/grass-feedstock.

Lingua principale
C
Stelle
1.2k
Fork
447
Merge medio
2g 10h
PR unite (30g)
86

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di OSGeo/grass

Tutte le issue di OSGeo/grass

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.