Skip to content

Commit

Permalink
Merge branch 'feature/v0.9.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
John Coleman committed May 23, 2024
2 parents b0f8d7a + c292b0a commit b196a17
Show file tree
Hide file tree
Showing 69 changed files with 5,061 additions and 1,572 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ jobs:
- name: Test
env:
GOPROXY: "https://proxy.golang.org"
run: go test -v .
run: |
go test -v ./ ./internal/cache -covermode=count -coverprofile=coverage.out
go tool cover -func=coverage.out -o=coverage.out
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ build:
fmt:
go fmt ./...

test: test-mariadb test-postgres test-mssql
test: test-go test-mariadb test-postgres test-mssql

test-go:
go test ./ ./internal/cache -covermode=count -coverprofile=coverage.out
go tool cover -func=coverage.out -o=coverage.out


test-mariadb:
docker compose run --rm mariadb_test
go tool cover -html test/acceptance/mariadb/coverage.out -o test/acceptance/mariadb/coverage.html

test-postgres:
docker compose run --rm postgres_test
Expand Down
33 changes: 13 additions & 20 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"database/sql/driver"
"errors"
"fmt"
"github.com/ninthclowd/unixodbc/internal/cache"
"github.com/ninthclowd/unixodbc/internal/odbc"
Expand All @@ -18,7 +19,6 @@ var (
_ driver.Pinger = (*Connection)(nil)
_ driver.Conn = (*Connection)(nil)
_ driver.NamedValueChecker = (*Connection)(nil)
_ driver.SessionResetter = (*Connection)(nil)
_ driver.Validator = (*Connection)(nil)
)

Expand All @@ -31,7 +31,7 @@ var toODBCIsoLvl = map[sql.IsolationLevel]odbc.IsolationLevel{

type Connection struct {
connector *Connector
odbcConnection *odbc.Connection
odbcConnection odbc.Connection
openTX *TX
cachedStatements *cache.LRU[PreparedStatement]
}
Expand All @@ -45,12 +45,6 @@ func (c *Connection) IsValid() bool {
return true
}

// ResetSession implements driver.SessionResetter
func (c *Connection) ResetSession(ctx context.Context) error {
//TODO implement me
return nil
}

// CheckNamedValue implements driver.NamedValueChecker
func (c *Connection) CheckNamedValue(value *driver.NamedValue) error {
switch value.Value.(type) {
Expand Down Expand Up @@ -131,7 +125,7 @@ func (c *Connection) Prepare(query string) (driver.Stmt, error) {

// PrepareContext implements driver.ConnPrepareContext
func (c *Connection) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) {
ctx, trace := Tracer.NewTask(ctx, "Connection::PrepareContext")
ctx, trace := Tracer.NewTask(ctx, "connection::PrepareContext")
defer trace.End()
Tracer.Logf(ctx, "query", query)

Expand All @@ -152,7 +146,7 @@ func (c *Connection) PrepareContext(ctx context.Context, query string) (driver.S
return stmt, nil
}

var st *odbc.Statement
var st odbc.Statement
Tracer.WithRegion(ctx, "Create statement", func() {
st, err = c.odbcConnection.Statement()
})
Expand Down Expand Up @@ -186,10 +180,10 @@ func (c *Connection) PrepareContext(ctx context.Context, query string) (driver.S

// ExecContext implements driver.ExecerContext
func (c *Connection) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error) {
ctx, trace := Tracer.NewTask(ctx, "Connection::ExecContext")
ctx, trace := Tracer.NewTask(ctx, "connection::ExecContext")
defer trace.End()
Tracer.Logf(ctx, "query", query)
var st *odbc.Statement
var st odbc.Statement
var err error

Tracer.WithRegion(ctx, "Create statement", func() {
Expand All @@ -200,7 +194,7 @@ func (c *Connection) ExecContext(ctx context.Context, query string, args []drive
}
defer func() {
Tracer.WithRegion(ctx, "Close statement", func() {
st.Close()
_ = st.Close()
})
}()
Tracer.WithRegion(ctx, "Bind parameters", func() {
Expand All @@ -220,11 +214,11 @@ func (c *Connection) ExecContext(ctx context.Context, query string, args []drive

// QueryContext implements driver.QueryerContext
func (c *Connection) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) {
ctx, trace := Tracer.NewTask(ctx, "Connection::QueryContext")
ctx, trace := Tracer.NewTask(ctx, "connection::QueryContext")
defer trace.End()
Tracer.Logf(ctx, "query", query)

var st *odbc.Statement
var st odbc.Statement
var err error

Tracer.WithRegion(ctx, "Create statement", func() {
Expand All @@ -249,7 +243,7 @@ func (c *Connection) QueryContext(ctx context.Context, query string, args []driv
_ = st.Close()
return nil, err
}
var rs *odbc.RecordSet
var rs odbc.RecordSet
Tracer.WithRegion(ctx, "Getting recordset", func() {
rs, err = st.RecordSet()
})
Expand All @@ -263,18 +257,17 @@ func (c *Connection) QueryContext(ctx context.Context, query string, args []driv

// Ping implements driver.Pinger
func (c *Connection) Ping(ctx context.Context) error {
ctx, trace := Tracer.NewTask(ctx, "Connection::Ping")
ctx, trace := Tracer.NewTask(ctx, "connection::Ping")
defer trace.End()
if c.odbcConnection == nil {
return driver.ErrBadConn
}
switch err := c.odbcConnection.Ping(); err {
case odbc.ErrConnectionDead:
switch err := c.odbcConnection.Ping(); {
case errors.Is(err, odbc.ErrConnectionDead):
return driver.ErrBadConn
default:
return err
}
return nil
}

func toValues(args []driver.NamedValue) (values []interface{}) {
Expand Down
Loading

0 comments on commit b196a17

Please sign in to comment.