go-sqlite3 icon indicating copy to clipboard operation
go-sqlite3 copied to clipboard

Add getters to sqlite3.Error

Open abemedia opened this issue 9 months ago • 0 comments

I'm working on a library which works with many different SQL drivers and maps to common errors for things like unique constraints etc. I'd like to avoid having to import go-sqlite3 as it requires cgo so I was wondering whether you'd be open to adding getters for the error which can be used in a more dynamic environment e.g.

// Error implement sqlite error code.
type Error struct {
	Code         ErrNo         /* The error code returned by SQLite */
	ExtendedCode ErrNoExtended /* The extended error code returned by SQLite */
	SystemErrno  syscall.Errno /* The system errno returned by the OS through SQLite, if applicable */
	err          string        /* The error string returned by sqlite3_errmsg(),
	this usually contains more specific details. */
}


func (err Error) GetExtendedCode() int {
	return int(err.ExtendedCode)
}

That way libraries that need to support go-sqlite3 can do so without relying on the package by simply using an interface.

abemedia avatar Mar 10 '25 03:03 abemedia