Skip to content

Commit

Permalink
enh: remove Exec and Query as they are deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
huskar-t committed Nov 7, 2024
1 parent 4e1e857 commit a96feb5
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 49 deletions.
30 changes: 0 additions & 30 deletions taosRestful/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ func (tc *taosConn) Prepare(query string) (driver.Stmt, error) {
return nil, &taosErrors.TaosError{Code: 0xffff, ErrStr: "restful does not support stmt"}
}

func (tc *taosConn) Exec(query string, args []driver.Value) (driver.Result, error) {
return tc.ExecContext(context.Background(), query, common.ValueArgsToNamedValueArgs(args))
}

func (tc *taosConn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (result driver.Result, err error) {
return tc.execCtx(ctx, query, args)
}
Expand All @@ -127,32 +123,6 @@ func (tc *taosConn) execCtx(ctx context.Context, query string, args []driver.Nam
return driver.RowsAffected(result.Data[0][0].(int32)), nil
}

func (tc *taosConn) Query(query string, args []driver.Value) (driver.Rows, error) {
if len(args) != 0 {
if !tc.cfg.interpolateParams {
return nil, driver.ErrSkip
}
// try client-side prepare to reduce round trip
prepared, err := common.InterpolateParams(query, common.ValueArgsToNamedValueArgs(args))
if err != nil {
return nil, err
}
query = prepared
}
result, err := tc.taosQuery(context.TODO(), query, tc.readBufferSize)
if err != nil {
return nil, err
}
if result == nil {
return nil, errors.New("wrong result")
}
// Read Result
rs := &rows{
result: result,
}
return rs, err
}

func (tc *taosConn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (rows driver.Rows, err error) {
return tc.queryCtx(ctx, query, args)
}
Expand Down
8 changes: 0 additions & 8 deletions taosSql/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ func (tc *taosConn) Prepare(query string) (driver.Stmt, error) {
return stmt, nil
}

func (tc *taosConn) Exec(query string, args []driver.Value) (driver.Result, error) {
return tc.ExecContext(context.Background(), query, common.ValueArgsToNamedValueArgs(args))
}

func (tc *taosConn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (rows driver.Result, err error) {
if tc.taos == nil {
return nil, driver.ErrBadConn
Expand Down Expand Up @@ -118,10 +114,6 @@ func (tc *taosConn) processExecResult(result *handler.AsyncResult) (driver.Resul
return driver.RowsAffected(affectRows), nil
}

func (tc *taosConn) Query(query string, args []driver.Value) (driver.Rows, error) {
return tc.QueryContext(context.Background(), query, common.ValueArgsToNamedValueArgs(args))
}

func (tc *taosConn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (rows driver.Rows, err error) {
if tc.taos == nil {
return nil, driver.ErrBadConn
Expand Down
10 changes: 0 additions & 10 deletions taosWS/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ var jsonI = jsoniter.ConfigCompatibleWithStandardLibrary

const (
WSConnect = "conn"
WSQuery = "query"
WSFetch = "fetch"
WSFetchBlock = "fetch_block"
WSFreeResult = "free_result"

STMTInit = "init"
Expand Down Expand Up @@ -490,9 +487,6 @@ func (tc *taosConn) stmtUseResult(stmtID uint64) (*rows, error) {
}
return rs, nil
}
func (tc *taosConn) Exec(query string, args []driver.Value) (driver.Result, error) {
return tc.execCtx(context.Background(), query, common.ValueArgsToNamedValueArgs(args))
}

func (tc *taosConn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (result driver.Result, err error) {
return tc.execCtx(ctx, query, args)
Expand All @@ -509,10 +503,6 @@ func (tc *taosConn) execCtx(ctx context.Context, query string, args []driver.Nam
return driver.RowsAffected(resp.AffectedRows), nil
}

func (tc *taosConn) Query(query string, args []driver.Value) (driver.Rows, error) {
return tc.QueryContext(context.Background(), query, common.ValueArgsToNamedValueArgs(args))
}

func (tc *taosConn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (rows driver.Rows, err error) {
return tc.queryCtx(ctx, query, args)
}
Expand Down
3 changes: 2 additions & 1 deletion taosWS/connection_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package taosWS

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -67,7 +68,7 @@ func TestBadConnection(t *testing.T) {
// to test bad connection, we manually close the connection
conn.Close()

_, err = conn.Query("select 1", nil)
_, err = conn.QueryContext(context.Background(), "select 1", nil)
if err == nil {
t.Fatalf("query should fail")
}
Expand Down

0 comments on commit a96feb5

Please sign in to comment.