MCPcopy Create free account
hub / github.com/dolthub/doltgresql / RunQueryAttempt

Function RunQueryAttempt

integration-tests/go-sql-server-driver/testdef.go:630–679  ·  view source on GitHub ↗
(t TestingT, conn *sql.Conn, q driver.Query, ports *DynamicResources)

Source from the content-addressed store, hash-verified

628}
629
630func RunQueryAttempt(t TestingT, conn *sql.Conn, q driver.Query, ports *DynamicResources) {
631 args := make([]any, len(q.Args))
632 for i := range q.Args {
633 args[i] = q.Args[i]
634 }
635 if q.Query != "" {
636 ctx, c := context.WithTimeout(context.Background(), timeout)
637 defer c()
638 rows, err := conn.QueryContext(ctx, q.Query, args...)
639 if err == nil {
640 defer rows.Close()
641 }
642 if q.ErrorMatch != "" {
643 require.Error(t, err, "expected error running query %s", q.Query)
644 require.Regexp(t, q.ErrorMatch, err.Error())
645 return
646 }
647 require.NoError(t, err)
648
649 cols, err := rows.Columns()
650 require.NoError(t, err)
651 require.Equal(t, q.Result.Columns, cols)
652
653 rowstrings, err := RowsToStrings(len(cols), rows)
654 require.NoError(t, err)
655 if q.Result.Rows.Or != nil {
656 match := *q.Result.Rows.Or
657 for i := range match {
658 for j := range match[i] {
659 for k := range match[i][j] {
660 match[i][j][k] = ports.ApplyTemplate(match[i][j][k])
661 }
662 }
663 }
664 require.Contains(t, match, rowstrings)
665 }
666 } else if q.Exec != "" {
667 ctx, c := context.WithTimeout(context.Background(), timeout)
668 defer c()
669 exec := q.Exec
670 exec = ports.ApplyTemplate(exec)
671 _, err := conn.ExecContext(ctx, exec, args...)
672 if q.ErrorMatch == "" {
673 require.NoError(t, err, "error running query %s: %v", q.Exec, err)
674 } else {
675 require.Error(t, err)
676 require.Regexp(t, q.ErrorMatch, err.Error())
677 }
678 }
679}
680
681func RowsToStrings(cols int, rows *sql.Rows) ([][]string, error) {
682 ret := make([][]string, 0)

Callers 2

RunMethod · 0.85
RunQueryFunction · 0.85

Calls 6

RowsToStringsFunction · 0.85
ApplyTemplateMethod · 0.80
CloseMethod · 0.65
ErrorMethod · 0.45
EqualMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected