From f0406f653a7a7221e389a4977bd437f87fce11cf Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Tue, 16 Apr 2024 20:05:47 +0500 Subject: [PATCH] add explicit initialization of fields of structures in internal/xsql --- internal/xsql/conn.go | 48 ++++++++++++++++++++++++-------------- internal/xsql/connector.go | 28 +++++++++++++++------- internal/xsql/rows.go | 14 +++++------ internal/xsql/stmt.go | 6 ++--- internal/xsql/tx.go | 14 ++++++----- internal/xsql/tx_fake.go | 13 ++++++----- 6 files changed, 75 insertions(+), 48 deletions(-) diff --git a/internal/xsql/conn.go b/internal/xsql/conn.go index c5d670517..d3f66dec9 100644 --- a/internal/xsql/conn.go +++ b/internal/xsql/conn.go @@ -8,6 +8,7 @@ import ( "io" "path" "strings" + "sync" "sync/atomic" "time" @@ -115,23 +116,32 @@ func (resultNoRows) LastInsertId() (int64, error) { return 0, ErrUnsupported } func (resultNoRows) RowsAffected() (int64, error) { return 0, ErrUnsupported } var ( - _ driver.Conn = &conn{} - _ driver.ConnPrepareContext = &conn{} - _ driver.ConnBeginTx = &conn{} - _ driver.ExecerContext = &conn{} - _ driver.QueryerContext = &conn{} - _ driver.Pinger = &conn{} - _ driver.Validator = &conn{} - _ driver.NamedValueChecker = &conn{} + _ driver.Conn = new(conn) + _ driver.ConnPrepareContext = new(conn) + _ driver.ConnBeginTx = new(conn) + _ driver.ExecerContext = new(conn) + _ driver.QueryerContext = new(conn) + _ driver.Pinger = new(conn) + _ driver.Validator = new(conn) + _ driver.NamedValueChecker = new(conn) _ driver.Result = resultNoRows{} ) func newConn(ctx context.Context, c *Connector, s table.ClosableSession, opts ...connOption) *conn { cc := &conn{ - openConnCtx: ctx, - connector: c, - session: s, + openConnCtx: ctx, + connector: c, + trace: nil, + session: s, + beginTxFuncs: nil, + closed: atomic.Bool{}, + lastUsage: atomic.Int64{}, + defaultQueryMode: DefaultQueryMode, + defaultTxControl: nil, + dataOpts: nil, + scanOpts: nil, + currentTx: nil, } cc.beginTxFuncs = map[QueryMode]beginTxFunc{ DataQueryMode: cc.beginTx, @@ -334,8 +344,9 @@ func (c *conn) queryContext(ctx context.Context, query string, args []driver.Nam } return &rows{ - conn: c, - result: res, + conn: c, + result: res, + nextSet: sync.Once{}, }, nil case ScanQueryMode: normalizedQuery, parameters, err := c.normalize(query, args...) @@ -353,8 +364,9 @@ func (c *conn) queryContext(ctx context.Context, query string, args []driver.Nam } return &rows{ - conn: c, - result: res, + conn: c, + result: res, + nextSet: sync.Once{}, }, nil case ExplainQueryMode: normalizedQuery, _, err := c.normalize(query, args...) @@ -371,6 +383,7 @@ func (c *conn) queryContext(ctx context.Context, query string, args []driver.Nam sql.Named("AST", exp.AST), sql.Named("Plan", exp.Plan), }, + readAll: false, }, nil case ScriptingQueryMode: normalizedQuery, parameters, err := c.normalize(query, args...) @@ -386,8 +399,9 @@ func (c *conn) queryContext(ctx context.Context, query string, args []driver.Nam } return &rows{ - conn: c, - result: res, + conn: c, + result: res, + nextSet: sync.Once{}, }, nil default: return nil, fmt.Errorf("unsupported query mode '%s' on conn query", m) diff --git a/internal/xsql/connector.go b/internal/xsql/connector.go index 8009f66d1..88b95d40a 100644 --- a/internal/xsql/connector.go +++ b/internal/xsql/connector.go @@ -197,13 +197,23 @@ type ydbDriver interface { func Open(parent ydbDriver, opts ...ConnectorOption) (_ *Connector, err error) { c := &Connector{ - parent: parent, - clock: clockwork.NewRealClock(), - conns: make(map[*conn]struct{}), - defaultTxControl: table.DefaultTxControl(), - defaultQueryMode: DefaultQueryMode, - pathNormalizer: bind.TablePathPrefix(parent.Name()), - trace: &trace.DatabaseSQL{}, + parent: parent, + clock: clockwork.NewRealClock(), + Bindings: bind.Bindings{}, + fakeTxModes: nil, + onClose: nil, + conns: make(map[*conn]struct{}), + connsMtx: sync.RWMutex{}, + idleStopper: nil, + defaultTxControl: table.DefaultTxControl(), + defaultQueryMode: DefaultQueryMode, + defaultDataQueryOpts: nil, + defaultScanQueryOpts: nil, + disableServerBalancer: false, + idleThreshold: time.Duration(0), + pathNormalizer: bind.TablePathPrefix(parent.Name()), + trace: nil, + traceRetry: nil, } for _, opt := range opts { if opt != nil { @@ -253,8 +263,8 @@ type Connector struct { } var ( - _ driver.Connector = &Connector{} - _ io.Closer = &Connector{} + _ driver.Connector = nil + _ io.Closer = nil ) func (c *Connector) idleCloser() (idleStopper func()) { diff --git a/internal/xsql/rows.go b/internal/xsql/rows.go index a9bb1572e..d4f9d3cb5 100644 --- a/internal/xsql/rows.go +++ b/internal/xsql/rows.go @@ -17,13 +17,13 @@ import ( ) var ( - _ driver.Rows = &rows{} - _ driver.RowsNextResultSet = &rows{} - _ driver.RowsColumnTypeDatabaseTypeName = &rows{} - _ driver.RowsColumnTypeNullable = &rows{} - _ driver.Rows = &single{} + _ driver.Rows = &rows{conn: nil, result: nil, nextSet: sync.Once{}} + _ driver.RowsNextResultSet = &rows{conn: nil, result: nil, nextSet: sync.Once{}} + _ driver.RowsColumnTypeDatabaseTypeName = &rows{conn: nil, result: nil, nextSet: sync.Once{}} + _ driver.RowsColumnTypeNullable = &rows{conn: nil, result: nil, nextSet: sync.Once{}} + _ driver.Rows = &single{values: nil, readAll: false} - _ scanner.Scanner = &valuer{} + _ scanner.Scanner = &valuer{v: nil} ignoreColumnPrefixName = "__discard_column_" ) @@ -122,7 +122,7 @@ func (r *rows) Next(dst []driver.Value) error { } values := make([]indexed.RequiredOrOptional, len(dst)) for i := range dst { - values[i] = &valuer{} + values[i] = &valuer{v: nil} } if err = r.result.Scan(values...); err != nil { return badconn.Map(xerrors.WithStackTrace(err)) diff --git a/internal/xsql/stmt.go b/internal/xsql/stmt.go index 75b571acd..a0dab1378 100644 --- a/internal/xsql/stmt.go +++ b/internal/xsql/stmt.go @@ -24,9 +24,9 @@ type stmt struct { } var ( - _ driver.Stmt = &stmt{} - _ driver.StmtQueryContext = &stmt{} - _ driver.StmtExecContext = &stmt{} + _ driver.Stmt = &stmt{conn: nil, processor: nil, query: "", stmtCtx: nil, trace: nil} + _ driver.StmtQueryContext = &stmt{conn: nil, processor: nil, query: "", stmtCtx: nil, trace: nil} + _ driver.StmtExecContext = &stmt{conn: nil, processor: nil, query: "", stmtCtx: nil, trace: nil} ) func (s *stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (_ driver.Rows, finalErr error) { diff --git a/internal/xsql/tx.go b/internal/xsql/tx.go index d67813437..9a3573951 100644 --- a/internal/xsql/tx.go +++ b/internal/xsql/tx.go @@ -4,6 +4,7 @@ import ( "context" "database/sql/driver" "fmt" + "sync" "github.com/ydb-platform/ydb-go-sdk/v3/internal/stack" "github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors" @@ -20,10 +21,10 @@ type tx struct { } var ( - _ driver.Tx = &tx{} - _ driver.ExecerContext = &tx{} - _ driver.QueryerContext = &tx{} - _ table.TransactionIdentifier = &tx{} + _ driver.Tx = &tx{conn: nil, txCtx: nil, tx: nil} + _ driver.ExecerContext = &tx{conn: nil, txCtx: nil, tx: nil} + _ driver.QueryerContext = &tx{conn: nil, txCtx: nil, tx: nil} + _ table.TransactionIdentifier = &tx{conn: nil, txCtx: nil, tx: nil} ) func (c *conn) beginTx(ctx context.Context, txOptions driver.TxOptions) (currentTx, error) { @@ -153,8 +154,9 @@ func (tx *tx) QueryContext(ctx context.Context, query string, args []driver.Name } return &rows{ - conn: tx.conn, - result: res, + conn: tx.conn, + result: res, + nextSet: sync.Once{}, }, nil } diff --git a/internal/xsql/tx_fake.go b/internal/xsql/tx_fake.go index 459aba718..85369e3e8 100644 --- a/internal/xsql/tx_fake.go +++ b/internal/xsql/tx_fake.go @@ -39,16 +39,17 @@ func (tx *txFake) PrepareContext(ctx context.Context, query string) (_ driver.St } var ( - _ driver.Tx = &txFake{} - _ driver.ExecerContext = &txFake{} - _ driver.QueryerContext = &txFake{} - _ table.TransactionIdentifier = &txFake{} + _ driver.Tx = &txFake{beginCtx: nil, conn: nil, ctx: nil} + _ driver.ExecerContext = &txFake{beginCtx: nil, conn: nil, ctx: nil} + _ driver.QueryerContext = &txFake{beginCtx: nil, conn: nil, ctx: nil} + _ table.TransactionIdentifier = &txFake{beginCtx: nil, conn: nil, ctx: nil} ) func (c *conn) beginTxFake(ctx context.Context, txOptions driver.TxOptions) (currentTx, error) { return &txFake{ - conn: c, - ctx: ctx, + beginCtx: nil, + conn: c, + ctx: ctx, }, nil }