Skip to content

Releases

v0.4.1

Choose a tag to compare

@kenshaw kenshaw released this 08 Nov 02:05

ErrVerbose of *odbc.Error now writes the layout of psql: an ERROR: <SQLSTATE>: <message> line, DETAIL lines for the native code and each further record, and a CONTEXT line for the call that failed. There is no LINE and caret, because ODBC has no field for the place of the error in the statement.

v0.4.0

Choose a tag to compare

@kenshaw kenshaw released this 08 Nov 01:41

Adds (*odbc.Error).ErrVerbose(query string) string, which writes every diagnostic record of a failed call, one per line, for \errverbose of usql. Row and column numbers are not included yet.

v0.3.0

Choose a tag to compare

@kenshaw kenshaw released this 04 Nov 10:57

This release implements more of the optional interfaces of the standard library, fixes how the path of a URL is read, and takes a newer dbimp.

Fixed

The driver cut the path of every URL at its last slash. usql odbc+sqlite://home/ken/data/northwind.db has the host home and a path, and the driver kept only northwind.db. The SQLite ODBC driver then made an empty northwind.db in the current directory. Now the path means what the driver needs (D28):

  • SQL Server takes the path as the instance and then the database, as before.
  • SQLite and DuckDB take the path as the path of the file. A host other than localhost is an error that says the path may have lost a slash, and no file is made.
  • Every other driver takes the whole path, without its first slash, as the database name.

For a file database, odbc+SQLite3://localhost/home/ken/a.db and odbc+SQLite3:///?Database=/home/ken/a.db work through dburl and usql. The README FAQ has an entry.

The connection never recorded that a transaction was open, so a statement of a transaction could name another catalog with WithDatabase. It records it now.

Added

  • RowsColumnTypeLength returns math.MaxInt64 for a type with no limit, as the contract says. psqlODBC gave 8190 for text, and SQL Server gave 0 for nvarchar(max).
  • A uint64 or uint with the high bit set, which database/sql refuses, goes to the database as its decimal text.
  • WithLastInsertID(true) makes LastInsertId work for MySQL, MariaDB and SQLite. SQL Server and PostgreSQL fail with dbimp.ErrNotSupported, because a second statement can return an older id, and OUTPUT or RETURNING reads the id correctly.
  • Ping also sends SELECT 1 for PostgreSQL, MySQL, MariaDB, SQL Server, SQLite and DuckDB, so a connection that the server ended fails at once. ResetSession ends a transaction that nobody ended.
  • docs/INTERFACES.md lists every optional interface of database/sql with its state.

Changed

The module takes dbimp v0.24.3, so a decimal reaches a destination that has Compose in parts and not as text (D26). dbimp also gives a decimal the scale of its column.

CI

The Windows job finds mysqld.exe, because the runner image has MySQL 8.4 and no longer 8.0.

v0.2.0

Choose a tag to compare

@kenshaw kenshaw released this 01 Nov 23:06

This release adds one method to *odbc.Error and nothing else. The tests of the database still pass on all three systems.

Added

*odbc.Error has a method AuthenticationRefused() bool. It is the contract that usql chose for every driver. It is true when the database refused the credential and a new password can cure it:

  • a wrong password,
  • a user that the database does not know,
  • a password that the database needs and the client did not send.

It is false for a missing permission (SQLSTATE class 42), a locked account, an expired password, and a failure of the network, of TLS or of a timeout. It looks at its own record and at the other records of the same call, so a caller that uses errors.As gets the same answer as a caller that walks the whole tree of errors. Wrapping the error with %w or errors.Join keeps the method visible, and wrapping it with %v loses it.

SQLSTATE class 28 means a refused login for MariaDB, MySQL and SQL Server. The native codes that a new password does not cure return false: 18486, 18487 and 18488 of SQL Server, and 3118 and 1862 of MySQL.

PostgreSQL through psqlODBC does not use class 28. It reports a wrong password with the state 08001, the class of a failed connection, and puts the text of the server in the message. For that state the driver reads the text authentication failed and no password supplied. The same state with Connection refused is a network failure and returns false.

The tests ask PostgreSQL, MariaDB, MySQL and SQL Server for a wrong password, an unknown user, a statement that a user without a privilege runs, and a server that is not there. D25 in docs/decisions/ has the rules, and the README FAQ has a short entry.

Not changed

Everything else is as in v0.1.2.

v0.1.2

Choose a tag to compare

@kenshaw kenshaw released this 09 Oct 22:01

This release changes documents only. The code is the same as v0.1.1.

  • The README and AGENTS.md now say that CI tests the driver on Linux, macOS and Windows against PostgreSQL, MariaDB, MySQL, SQL Server, SQLite and DuckDB. They said before that the driver had not run on macOS or Windows and that DuckDB was not tested.
  • docs/PROGRESS.md lists the first two releases and the variables that CI uses to name each server and each ODBC driver.
  • D2, D3 and D13 no longer say that only Linux has run.
  • AGENTS.md says to run every check before a commit and to stop at the first one that fails.
  • The sentences of the README FAQ are shorter.

This release was tagged before CI ran on it, because the container registry was down and the container tests could not start. The checks that need no container passed on the developer machine, and CI passed on v0.1.1, which has the same code.

v0.1.1

Choose a tag to compare

@kenshaw kenshaw released this 07 Oct 08:29

This release fixes one bug and documents a crash that is not a fault of odbc.

Fixed

A statement that returns no result set, such as CREATE TABLE, sent through QueryContext, failed on the first Next with fetching: return code -1 with no diagnostic. The driver fetched from a statement that has no result. It now returns no rows, and Err and Close report no error. A client that sends every statement through QueryContext, as usql can, met this. TestQueryWithoutResult covers all six tested databases.

Documented

  • The README has a FAQ entry for a crash of a program that links both go-sqlite3 and the DuckDB bindings and uses the SQLite ODBC driver. The DuckDB bindings link with -rdynamic, so the program exports the sqlite3_* functions of go-sqlite3, and the SQLite ODBC driver binds to them while it also uses the SQLite of the system. The first query then faults. Build go-sqlite3 with the tag libsqlite3, leave one of the two libraries out, or build with CGO_ENABLED=0. odbc cannot prevent it.
  • The SQLite ODBC driver answers a VALUES statement with SQL_NO_DATA, so the driver manager refuses to describe its columns with HY010. select * from (values (1)) works. The backlog records it as a known limit.

Everything else in v0.1.0 is unchanged, and CI passed on all three systems for this release.

v0.1.0

Choose a tag to compare

@kenshaw kenshaw released this 07 Oct 02:34

This is the first release of odbc, a database/sql driver for ODBC written in pure Go. It loads the ODBC driver manager of the system at run time with purego. It needs no cgo and no C compiler. One code base serves Linux, macOS and Windows.

Install

go get github.com/xo/odbc@v0.1.0

You need an ODBC driver manager and the ODBC driver of your database on the machine. The README explains the data source name and has an FAQ.

What it does

  • It connects with a URL such as odbc+PostgreSQL+Unicode://user:pass@host/db, or with an ODBC connection string.
  • It supports prepared and direct statements, bound parameters, transactions with isolation levels, and cancellation through the context.
  • Values have the Go types of the dbimp kinds. A decimal is a *apd.Decimal, a date is a dbimp.Date, and a timestamp with no zone is a dbimp.LocalDateTime.
  • It finds the size of SQLWCHAR when it loads the driver manager, so UTF-16 and UTF-32 managers both work.
  • Statements take the same options as the other dbimp drivers: WithTimeout, WithDatabase, WithReadonly, WithParameter, WithMaxRows, WithNoScan and WithFetchSize. An option that a database driver cannot honor fails with dbimp.ErrNotSupported.
  • WithFetchSize reads rows in blocks. It was two to four times faster in the tests, and it never returns a value that was cut short.
  • A program can ask the driver about the database: odbc.Drivers, odbc.DataSources, odbc.Conn with GetInfo*, Tables, Columns and PrimaryKeys, Config.OnWarning, Config.TraceFile, and error classes such as odbc.ErrIntegrity.

What is tested

The tests run the dbmeta fixtures and queries and a round trip of each kind of value. CI runs them on every push and every night.

System Databases
Linux PostgreSQL, MariaDB, MySQL, SQL Server, SQLite, DuckDB
macOS PostgreSQL, MariaDB, SQLite, DuckDB
Windows PostgreSQL, MySQL, SQLite, DuckDB

MariaDB Connector/ODBC serves both MariaDB and MySQL. SQL Server is tested on Linux only.

Known limits

  • WithReadonly(true) always fails with dbimp.ErrNotSupported, because three of the six databases accept the ODBC read only mode and still write.
  • PostgreSQL timestamptz loses its zone, because psqlODBC reports it as a timestamp with no zone.
  • Non-ASCII text in an SQL literal is wrong with the SQLite ODBC driver on macOS and in a container with no locale. An argument is fine.
  • iODBC works, but the database drivers of Homebrew are built for unixODBC and read its text wrongly.
  • MariaDB Connector/ODBC before 3.2 lists no primary key of a MySQL 8 table.

The decisions behind all of this are in docs/decisions/, and docs/BACKLOG.md lists the work that is left.

⌂ 换网址