Repository navigation
Releases
v0.4.1
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
v0.3.0
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
localhostis 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
RowsColumnTypeLengthreturnsmath.MaxInt64for a type with no limit, as the contract says.psqlODBCgave 8190 fortext, and SQL Server gave 0 fornvarchar(max).- A
uint64oruintwith the high bit set, whichdatabase/sqlrefuses, goes to the database as its decimal text. WithLastInsertID(true)makesLastInsertIdwork for MySQL, MariaDB and SQLite. SQL Server and PostgreSQL fail withdbimp.ErrNotSupported, because a second statement can return an older id, andOUTPUTorRETURNINGreads the id correctly.Pingalso sendsSELECT 1for PostgreSQL, MySQL, MariaDB, SQL Server, SQLite and DuckDB, so a connection that the server ended fails at once.ResetSessionends a transaction that nobody ended.docs/INTERFACES.mdlists every optional interface ofdatabase/sqlwith 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
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
This release changes documents only. The code is the same as v0.1.1.
- The README and
AGENTS.mdnow 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.mdlists 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.mdsays 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
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-sqlite3and the DuckDB bindings and uses the SQLite ODBC driver. The DuckDB bindings link with-rdynamic, so the program exports thesqlite3_*functions ofgo-sqlite3, and the SQLite ODBC driver binds to them while it also uses the SQLite of the system. The first query then faults. Buildgo-sqlite3with the taglibsqlite3, leave one of the two libraries out, or build withCGO_ENABLED=0.odbccannot prevent it. - The SQLite ODBC driver answers a
VALUESstatement withSQL_NO_DATA, so the driver manager refuses to describe its columns withHY010.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
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.0You 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
dbimpkinds. A decimal is a*apd.Decimal, a date is adbimp.Date, and a timestamp with no zone is adbimp.LocalDateTime. - It finds the size of
SQLWCHARwhen it loads the driver manager, so UTF-16 and UTF-32 managers both work. - Statements take the same options as the other
dbimpdrivers:WithTimeout,WithDatabase,WithReadonly,WithParameter,WithMaxRows,WithNoScanandWithFetchSize. An option that a database driver cannot honor fails withdbimp.ErrNotSupported. WithFetchSizereads 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.ConnwithGetInfo*,Tables,ColumnsandPrimaryKeys,Config.OnWarning,Config.TraceFile, and error classes such asodbc.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 withdbimp.ErrNotSupported, because three of the six databases accept the ODBC read only mode and still write.- PostgreSQL
timestamptzloses its zone, becausepsqlODBCreports 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.
iODBCworks, but the database drivers of Homebrew are built forunixODBCand 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.