MCPcopy Create free account
hub / github.com/sql-machine-learning/sqlflow / isQuery

Function isQuery

go/executor/sql_stmt.go:35–59  ·  view source on GitHub ↗

TODO(weiguo): isQuery is a hacky way to decide which API to call: https://golang.org/pkg/database/sql/#DB.Exec . We will need to extend our parser to be a full SQL parser in the future.

(slct string)

Source from the content-addressed store, hash-verified

33// https://golang.org/pkg/database/sql/#DB.Exec .
34// We will need to extend our parser to be a full SQL parser in the future.
35func isQuery(slct string) bool {
36 s := strings.ToUpper(strings.TrimSpace(slct))
37 has := strings.Contains
38 // remove comment lines
39 if strings.HasPrefix(s, "-- ") {
40 lines := strings.Split(s, "\n")
41 noCommentLines := []string{}
42 for _, l := range lines {
43 if !strings.HasPrefix(l, "-- ") {
44 noCommentLines = append(noCommentLines, l)
45 }
46 }
47 s = strings.Join(noCommentLines, "\n")
48 }
49 if strings.HasPrefix(s, "SELECT") && !has(s, "INTO") {
50 return true
51 }
52 if strings.HasPrefix(s, "SHOW") && (has(s, "CREATE") || has(s, "DATABASES") || has(s, "TABLES")) {
53 return true
54 }
55 if strings.HasPrefix(s, "DESC") || strings.HasPrefix(s, "EXPLAIN") {
56 return true
57 }
58 return false
59}
60
61// query runs slct and writes the retrieved rows into pipe wr.
62func runQuery(wr *pipe.Writer, slct string, db *database.DB) error {

Callers 2

runNormalStmtFunction · 0.85
TestIsQueryFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestIsQueryFunction · 0.68