MCPcopy Create free account
hub / github.com/donatj/sqlread / execQuery

Function execQuery

cmd/sqlread/query.go:17–72  ·  view source on GitHub ↗
(tree sqlread.SummaryTree, qry sqlread.Query, buff io.ReaderAt, w DataWriter)

Source from the content-addressed store, hash-verified

15}
16
17func execQuery(tree sqlread.SummaryTree, qry sqlread.Query, buff io.ReaderAt, w DataWriter) error {
18 tbl, tok := tree[qry.Table]
19 if !tok {
20 return fmt.Errorf("table `%s` not found", qry.Table)
21 }
22 colind := []int{}
23 for _, col := range qry.Columns {
24 found := false
25 for tci, tcol := range tbl.Cols {
26 if col == "*" || col == tcol.Name {
27 found = true
28 colind = append(colind, tci)
29 }
30 }
31
32 if !found {
33 return fmt.Errorf("column `%s` not found", col)
34 }
35 }
36 for _, loc := range tbl.DataLocs {
37 start := loc.Start.Pos
38 end := loc.End.Pos
39
40 sl, sli := sqlread.LexSection(buff, start, end-start+1)
41 go func() {
42 sl.Run(sqlread.StartState)
43 }()
44
45 sp := sqlread.NewInsertDetailParser()
46
47 spr := sqlread.Parse(sli)
48 go func() {
49 err := spr.Run(sp.ParseStart)
50 if err != nil {
51 log.Fatal(err)
52 }
53 }()
54
55 for {
56 row, ok := <-sp.Out
57 if !ok {
58 w.Flush()
59 break
60 }
61
62 out := make([]string, len(colind))
63 for i, ci := range colind {
64 out[i] = row[ci]
65 }
66
67 w.Write(out)
68 }
69 }
70
71 return nil
72}
73
74func showColumns(tree sqlread.SummaryTree, sctbl string, w DataWriter) error {

Callers 1

interactiveFunction · 0.85

Calls 6

LexSectionFunction · 0.92
NewInsertDetailParserFunction · 0.92
ParseFunction · 0.92
WriteMethod · 0.80
FlushMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected