mdbgo

module
v0.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 31, 2026 License: MIT

README

mdbgo

A read-only database/sql driver for Microsoft Access databases (.mdb and .accdb) written in Go. No Microsoft software, ODBC drivers, or OLE DB providers required.

mdbgo provides two drivers — a pure Go implementation and a CGo-based implementation backed by mdbtools.

Driver Name Backend C compiler Speed Memory
Pure Go "gomdb" driver/gomdb No Faster ~45 KB/op
CGo "cmdb" driver/cmdb zig cc Fast ~2 KB/op

Both drivers are feature-equivalent and produce identical results — verified across 32,549 rows over 5 databases with 0 value differences.

Note: Both drivers are read-only — querying existing Access databases only, no writes.

Features

  • Standard database/sql interface
  • Full sqlx compatibility (StructScan, Select, Get, Named queries)
  • Reads MDB (Jet 3/4) and ACCDB files
  • No dependency on Microsoft Access, ACE/Jet OLE DB, or ODBC
  • SQL queries: SELECT, WHERE, ORDER BY, LIMIT, LIST TABLES, DESCRIBE TABLE
  • Parameterized queries with ? placeholders
  • All 15 Access column types with sql.Null* support
  • Full column metadata (ColumnTypeDatabaseTypeName, ColumnTypeLength, ColumnTypeScanType)
  • Unicode support (CJK, Arabic, etc.)
  • Binary data and OLE object reading
  • DateTime handling with time.Time
  • LIKE pattern matching with Chinese/Unicode text

Installation

go get github.com/Felamande/mdbgo
Pure Go driver — "gomdb"

No C toolchain needed:

CGO_ENABLED=0 go build
CGo driver — "cmdb"

Requires a C compiler. zig cc recommended:

CC="zig cc" CGO_ENABLED=1 go build

No external C libraries needed — mdbtools is compiled in-tree.

Usage

import (
    "database/sql"
    _ "github.com/Felamande/mdbgo/driver/gomdb"  // pure Go
    // _ "github.com/Felamande/mdbgo/driver/cmdb" // or CGo
)

db, _ := sql.Open("gomdb", "path/to/database.mdb") // or "cmdb"

// Query with parameters
rows, _ := db.Query("SELECT ID, Name, Birthday FROM Users WHERE Age > ?", 18)

// sqlx struct scanning
type User struct {
    ID       int64     `db:"ID"`
    Name     string    `db:"Name"`
    Birthday time.Time `db:"Birthday"`
}
var users []User
sqlxDB.Select(&users, "SELECT * FROM Users")
Listing tables
rows, _ := db.Query("LIST TABLES")
Describing a table
rows, _ := db.Query("DESCRIBE TABLE MyTable")

Type Mapping

Access Type Go Type DatabaseTypeName()
Boolean bool "Boolean"
Byte int64 "Byte"
Integer int64 "Integer"
Long Integer int64 "Long Integer"
Currency float64 "Currency"
Single float64 "Single"
Double float64 "Double"
DateTime time.Time "DateTime"
Text string "Text"
Memo string "Memo/Hyperlink"
Binary []byte "Binary"
OLE Object []byte "OLE"
Replication ID string "Replication ID"
Numeric string "Numeric"
Complex int64

Limitations

  • Read-only — no INSERT, UPDATE, DELETE, or DDL operations
  • No transactionsBegin() not supported
  • Client-side parameter interpolation? placeholders are escaped and interpolated into the SQL string
  • BIT/Boolean NULL — Access BIT fields cannot store NULL; NULL coerces to FALSE
  • TEXT length — Unicode TEXT(n) columns report byte length (2×n)
  • No IN (...) syntax — use multiple OR conditions instead
  • Jet SQL only — advanced ACCDB SQL features may not be supported

Architecture

┌──────────────────────────────────────────────┐
│  Go application / sqlx                       │
├──────────────────────────────────────────────┤
│  driver/gomdb/gomdb.go    driver/cmdb/cmdb.go
│  (pure Go, zero CGo)        (CGo + mdbtools) │
├──────────────────────────────────────────────┤
│  internal/gomdb/           internal/cmdb/   │
│  19 .go files               C source + cgo   │
└──────────────────────────────────────────────┘

Both backends parse Access database files directly — the pure Go driver is a ground-up port of mdbtools with no C dependencies, while the CGo driver wraps the original C library.

Project layout

mdbgo/
├── driver/
│   ├── cmdb/                 # CGo driver — registers "cmdb"
│   │   └── cmdb.go
│   └── gomdb/               # Pure Go driver — registers "gomdb"
│       └── gomdb.go
├── internal/
│   ├── cmdb/                 # CGo backend (bridge + mdbtools C source)
│   └── gomdb/               # Pure Go backend (MDB parser, SQL engine)
├── testdata/                 # .mdb test databases
└── temp/                     # Comparison harnesses

Requirements

  • Go 1.26+
  • CGo driver: C compiler (gcc, clang, or zig cc)
  • Pure Go driver: no additional requirements

License

Go code: MIT License

This project embeds mdbtools under the LGPL-2.0-or-later. See internal/cmdb/mdbtools/COPYING.LIB.

Directories

Path Synopsis
driver
cmdb
Package cmdb provides a CGo-based database/sql driver for Microsoft Access (.mdb) files.
Package cmdb provides a CGo-based database/sql driver for Microsoft Access (.mdb) files.
gomdb
Package gomdb provides a pure Go database/sql driver for Microsoft Access (.mdb) files.
Package gomdb provides a pure Go database/sql driver for Microsoft Access (.mdb) files.
internal
gomdb
Package gomdb is a pure Go implementation of an MDB (Microsoft Access) file reader.
Package gomdb is a pure Go implementation of an MDB (Microsoft Access) file reader.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL