Commits on Source 4

  • cznic's avatar
    sqlite: add NewConnector, a driver.Connector for sql.OpenDB · 2c7e3eb3
    cznic authored
    database/sql offers no way to reach a registered driver: sql.Drivers returns
    names only and there is no sql.Driver(name). The single route from the
    "sqlite" name back to the driver value is (*sql.DB).Driver(), which is why
    callers who need it resort to
    
    	db, _ := sql.Open("sqlite", "")
    	drv := db.Driver()
    	db.Close()
    
    That opens nothing - it works only because sql.Open does not connect and
    *Driver does not implement driver.DriverContext. Both are properties this
    package could change without noticing it had broken anyone.
    
    Callers want the driver in order to interpose on the physical connections
    database/sql opens: tracing, metrics, connection-scoped setup. Handing out
    the driver alone would not be enough, because the only way to get a wrapper
    into a *sql.DB through sql.Open is sql.Register, which is process-global,
    panics on a name it has already seen and cannot be undone - so a library has
    to invent a unique name per configuration. TestConnectio...
    2c7e3eb3
  • cznic's avatar
    sqlite: document that a constructed Driver is not the registered one · e7a39d2d
    cznic authored
    Driver has been exported since 65f6d7e4 (2017), where "Make sqlite public"
    renamed the unexported sqlite type as part of publishing the package. The
    struct then held a connection counter and a mutex, so constructing one cost
    nothing and lost nothing. a9227519 (2022) moved the function and collation
    registries onto it and introduced the package-level instance, which is when
    a constructed Driver started silently lacking things; 14082cad (2023) added
    (*Driver).RegisterConnectionHook, which is only meaningful on an instance the
    caller builds, and so made the export load-bearing.
    
    The result is a type that is legitimately constructible for the private-hook
    pattern yet carries none of what the package-level Register* functions
    install. This documents that on the type and on the method, including the
    consequence easiest to miss: a registered function replaces a SQLite built-in
    of the same name, so a constructed Driver can evaluate upper(x) or date(x)
    differently from a connection opened through sql.Open.
    
    The half-global virtual table module behavior is documented as it stands
    rather than changed. registerModules reads the package-level driver, so
    modules do reach a constructed Driver while functions and collations do not.
    Making that consistent breaks somebody in either direction - inheriting
    silently changes query results for anyone whose registration shadows a
    built-in, isolating turns a working CREATE VIRTUAL TABLE into "no such
    module" - so it wants an issue of its own rather than a doc commit.
    
    No behavior changes.
    
    Co-Authored-By: default avatarClaude Opus 5 (1M context) <noreply@anthropic.com>
    e7a39d2d
  • cznic's avatar
    sqlite: validate the connector dsn with getVFSName, not a bare ParseQuery · 581eb450
    cznic authored
    NewConnector parsed the query string itself to reject a malformed dsn early.
    getVFSName is what newConn calls for the same purpose, and it does strictly
    more: the same url.ParseQuery, plus a check for conflicting vfs parameters.
    Calling it instead drops an import, removes the repeated parse, and keeps what
    NewConnector rejects aligned with what opening a connection rejects by
    construction rather than by matching two call sites by hand.
    
    The eager contract widens accordingly: "file:x?vfs=a&vfs=b" is now reported by
    NewConnector rather than by the first Connect. It was already an error either
    way, so no dsn changes from accepted to rejected. Everything a connection must
    exist to check - unknown parameters, out-of-range values - is still reported by
    Connect, as documented.
    
    v1.56.0 is not tagged, so no release shipped the narrower behavior.
    
    Co-Authored-By: default avatarClaude Opus 5 (1M context) <noreply@anthropic.com>
    581eb450
  • cznic's avatar
    lib, vec: re-vendor, bump libc to v1.74.4, sweep the docs · cc920f9b
    cznic authored
    Re-vendor the transpiled sources from ../libsqlite3 and ../libsqlite_vec.
    SQLite stays at 3.53.3; what changes is that the amalgamation now carries
    libsqlite3's sqlite_superjournal.patch, fixing an upstream 3.53.3
    data-corruption bug in journal rollback. After a crash during the commit of a
    multi-database (ATTACH) transaction the super-journal name and its checksum
    can be left zeroed while the name length and the trailing magic survive; the
    checksum is a plain byte sum, so an all-zero name still validates,
    readSuperJournal() hands back a non-NULL pointer to an empty string, and
    pager_playback() deletes the hot journal without replaying it. All 19 targets
    carry the patch; master had it on none.
    
    Verified by expanding both the old and the new trees and diffing per target:
    17 of 19 targets differ by exactly that one line. linux/s390x additionally
    picks up modernc.org/cc/v4 v4.29.1's MSB-first big-endian bit-field
    allocation, it being this module's only big-endian target. linux/riscv64 was
    regenerated on GCC 11.4.0 rather than 13.3.0, which only moves the COMPILER=
    entry PRAGMA compile_options reports and drops some unexported predefined
    macro constants; no SQLite code generation differs.
    
    go.mod goes to the current releases throughout. modernc.org/libc lands on
    v1.74.4 rather than the v1.74.3 ../libsqlite3 pins, that version being
    retracted upstream for a freeaddrinfo lock leak that deadlocks name
    resolution.
    
    Documentation:
    
      - openbsd/amd64 and openbsd/arm64 join the supported platforms table. Both
        have been in builder.json's test matrix since January and are cross-built
        by make build_all_targets, but were never listed.
      - Document the vfs DSN query parameter on Driver.Open.
      - Rewrite "Debug and development versions". It described a GO_GENERATE
        environment variable that is no longer read anywhere and ccgo/v3; drop
        with it the //go:generate naming generator.go, deleted from this repo back
        at SQLite 3.45.1, which made go generate ./... fail.
      - Add the package doc comments vec and vfs were missing.
      - Correct two stale claims in CLAUDE.md.
    
    make build_all_targets and make test are green (249 pass, 0 fail, 2 skip), as
    are ./vfs/..., ./pcache/... and ./vtab/....
    
    Co-Authored-By: default avatarClaude Opus 5 (1M context) <noreply@anthropic.com>
    cc920f9b
Loading
Loading