github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/tests/integration/table_scan_error_test.go (about) 1 //go:build integration 2 // +build integration 3 4 package integration 5 6 import ( 7 "context" 8 "fmt" 9 "os" 10 "testing" 11 12 "github.com/stretchr/testify/require" 13 14 "github.com/ydb-platform/ydb-go-sdk/v3" 15 "github.com/ydb-platform/ydb-go-sdk/v3/table" 16 "github.com/ydb-platform/ydb-go-sdk/v3/table/result/named" 17 ) 18 19 // https://github.com/ydb-platform/ydb-go-sdk/issues/415 20 func TestIssue415ScanError(t *testing.T) { 21 ctx, cancel := context.WithCancel(context.Background()) 22 defer cancel() 23 24 db, err := ydb.Open(ctx, 25 os.Getenv("YDB_CONNECTION_STRING"), 26 ydb.WithAccessTokenCredentials(os.Getenv("YDB_ACCESS_TOKEN_CREDENTIALS")), 27 ) 28 require.NoError(t, err) 29 err = db.Table().DoTx(ctx, func(ctx context.Context, tx table.TransactionActor) (err error) { 30 res, err := tx.Execute(ctx, `SELECT 1 as abc, 2 as def;`, nil) 31 if err != nil { 32 return err 33 } 34 err = res.NextResultSetErr(ctx) 35 if err != nil { 36 return err 37 } 38 if !res.NextRow() { 39 if err = res.Err(); err != nil { 40 return err 41 } 42 return fmt.Errorf("unexpected empty result set") 43 } 44 var abc, def int32 45 err = res.ScanNamed( 46 named.Required("abc", &abc), 47 named.Required("ghi", &def), 48 ) 49 if err != nil { 50 return err 51 } 52 t.Log(abc, def) 53 return res.Err() 54 }, table.WithTxSettings(table.TxSettings(table.WithSnapshotReadOnly()))) 55 require.Error(t, err) 56 require.ErrorContains(t, err, "not found column 'ghi'") 57 } 58 59 // https://github.com/ydb-platform/ydb-go-sdk/issues/847 60 func TestIssue847ScanError(t *testing.T) { 61 ctx, cancel := context.WithCancel(context.Background()) 62 defer cancel() 63 64 db, err := ydb.Open(ctx, 65 os.Getenv("YDB_CONNECTION_STRING"), 66 ydb.WithAccessTokenCredentials(os.Getenv("YDB_ACCESS_TOKEN_CREDENTIALS")), 67 ) 68 require.NoError(t, err) 69 err = db.Table().Do(ctx, func(ctx context.Context, s table.Session) (err error) { 70 res, err := s.StreamExecuteScanQuery(ctx, `SELICT 1;`, nil) 71 if err != nil { 72 return err 73 } 74 return res.Err() 75 }, table.WithTxSettings(table.TxSettings(table.WithSnapshotReadOnly()))) 76 require.Error(t, err) 77 require.ErrorContains(t, err, "Unexpected token 'SELICT'") 78 }