github.com/dolthub/go-mysql-server@v0.18.0/enginetest/sqllogictest/utils/utils.go (about) 1 package utils 2 3 import ( 4 "bufio" 5 "strings" 6 7 _ "github.com/go-sql-driver/mysql" 8 ) 9 10 const SEP = "----" 11 12 func ReadStmt(scanner *bufio.Scanner) string { 13 var stmt string 14 once := true 15 for { 16 if !scanner.Scan() { 17 panic("unexpected EOF") 18 } 19 part := scanner.Text() 20 if len(part) == 0 { 21 break 22 } 23 if once { 24 once = false 25 stmt += part 26 } else { 27 stmt += "\n" + part 28 } 29 } 30 return stmt 31 } 32 33 // ReadQuery reads queries, stopping at separator 34 func ReadQuery(scanner *bufio.Scanner) string { 35 var query string 36 once := true 37 for { 38 if !scanner.Scan() { 39 panic("unexpected EOF") 40 } 41 part := scanner.Text() 42 if len(part) == 0 { 43 panic("unexpected blank line") 44 } 45 if part == SEP { 46 break 47 } 48 if once { 49 once = false 50 query += part 51 } else { 52 query += "\n" + part 53 } 54 } 55 return query 56 } 57 58 // ReadResults reads and flattens results, stopping at blank line 59 func ReadResults(scanner *bufio.Scanner) []string { 60 rows := make([]string, 0) 61 for { 62 if !scanner.Scan() { 63 break 64 } 65 row := scanner.Text() 66 if len(row) == 0 { 67 break 68 } 69 rowVals := strings.Fields(row) 70 rows = append(rows, rowVals...) 71 } 72 return rows 73 }