[Bug] DB drivers don't work on Windows with the CMake/MSVC build (conda-forge 8.5.0): "db_open_database() not implemented"
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
- Ambito
- build-system, database
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
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.
-
The function pointers end up in the wrong place.
grass_dbmidriver.dllcalls the driver through thedb_driver_*pointers fromlib/db/dbmi_base/dbstubs.h. The DLL exports 32 of them, initialised to the stubs ingrass_dbstubs.dll. Each driver'smain()callsinit_dbdriver()to point them at its own functions.But
db/drivers/CMakeLists.txtadds-DDB_DRIVER_C=1for the drivers when building with MSVC. With that define, dbstubs.h defines the pointer variables inside the driver exe. Soinit_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.exeimports only four symbols fromgrass_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 -
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. -
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. Inlib/gis/rename.ctheremove(newname)is inside#ifdef __MINGW32__. With MSVC,rename()fails because the target exists, so it falls back toG_copy_file(), which copies withfopen(..., "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
externpointer declarations in dbstubs.h marked__declspec(dllimport), and noDB_DRIVER_C; - in the driver's
main(), beforeinit_dbdriver():
_setmode(_fileno(stdin), _O_BINARY);
_setmode(_fileno(stdout), _O_BINARY);
- dbf only:
remove(db.tables[t].file);before theG_rename_file()call insave_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_Cfor the drivers on MSVC and add a proper import/export macro to the pointer declarations in dbstubs.h; - change
#ifdef __MINGW32__to#ifdef _WIN32around the_setmodecalls in driver.c and theremove()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
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di OSGeo/grass
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
[Bug] v.db.addtable expands $MAP only when it is a directoryForse già presa @alteralto l’ha presa 35 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
[Bug] grass.pygrass: Cats.delete(0) deletes all layer categories instead of category 0Forse già presa @Mohit-Ak l’ha presa 40 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
[Bug] macOS: Startup crashes with StopIteration when ~/Documents is not readable (macOS privacy protection)Forse già presa @NIne-WIngEd l’ha presa 46 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
OSGeo/grass#8027 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug] Specify the test project nameForse già presa @Om23131212 l’ha presa 39 giorni fa. Apertabug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 65/100
OSGeo/grass#7860 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Issue simili
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 68/100
Revivedx/SavageWindRecomp#1358 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 84/100
ossc-db/pg_hint_plan#255 ·
-
Status: Opened
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
bug needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
awslabs/aws-c-common#1319 ·
-
editor/integration
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
DeusData/codebase-memory-mcp#3130 ·
I maintainer di solito rispondono entro 1 giorno