github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/tests/integration/database_sql_positional_args_test.go (about)

     1  //go:build integration
     2  // +build integration
     3  
     4  package integration
     5  
     6  import (
     7  	"context"
     8  	"database/sql"
     9  	"testing"
    10  	"time"
    11  
    12  	"github.com/ydb-platform/ydb-go-sdk/v3"
    13  	"github.com/ydb-platform/ydb-go-sdk/v3/retry"
    14  )
    15  
    16  func TestDatabaseSqlPositionalArgs(t *testing.T) {
    17  	scope := newScope(t)
    18  	db := scope.SQLDriverWithFolder(
    19  		ydb.WithTablePathPrefix(scope.Folder()),
    20  		ydb.WithAutoDeclare(),
    21  		ydb.WithPositionalArgs(),
    22  	)
    23  	dt := time.Date(2023, 3, 1, 16, 34, 18, 0, time.UTC)
    24  
    25  	var row *sql.Row
    26  	err := retry.Retry(scope.Ctx, func(ctx context.Context) (err error) {
    27  		row = db.QueryRowContext(ctx, `
    28  			SELECT 
    29  				? AS vInt,
    30  				? AS vText,
    31  				? AS vDouble,
    32  				? AS vDateTime 
    33  			`, 1, "2", 3.0, dt,
    34  		)
    35  		return row.Err()
    36  	})
    37  	scope.Require.NoError(err)
    38  
    39  	var resInt int
    40  	var resText string
    41  	var resDouble float64
    42  	var resDateTime time.Time
    43  	scope.Require.NoError(row.Scan(&resInt, &resText, &resDouble, &resDateTime))
    44  
    45  	scope.Require.Equal(1, resInt)
    46  	scope.Require.Equal("2", resText)
    47  	scope.Require.Equal(3.0, resDouble)
    48  	scope.Require.Equal(dt, resDateTime.UTC())
    49  }