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

Function interactive

cmd/sqlread/main.go:80–149  ·  view source on GitHub ↗
(tree sqlread.SummaryTree, buff io.ReaderAt)

Source from the content-addressed store, hash-verified

78}
79
80func interactive(tree sqlread.SummaryTree, buff io.ReaderAt) {
81 w := csv.NewWriter(os.Stdout)
82 sw := NewReadlineWrap()
83
84 intp := sqlread.Intp{}
85 for {
86 stdinlex, stdli := sqlread.Lex(sw)
87 go func() {
88 stdinlex.Run(intp.StartIntpState)
89 }()
90
91 qp := sqlread.NewQueryParser()
92
93 p := sqlread.Parse(stdli)
94 err := p.Run(qp.ParseStart)
95 if err != nil {
96 log.Println("query error: ", err)
97 sw.Flush()
98 continue
99 }
100
101 for _, qry := range qp.Tree.Queries {
102 w2 := w
103 path := ""
104
105 if qry.Outfile != nil && *qry.Outfile != "" {
106 path = filepath.Clean(*qry.Outfile)
107 outfile, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0644)
108 if err != nil {
109 log.Println(err)
110 continue
111 }
112
113 w2 = csv.NewWriter(outfile)
114 }
115 if err := execQuery(tree, qry, buff, w2); err != nil {
116 log.Println(err)
117 } else if path != "" {
118 log.Printf("written to `%s`", path)
119 }
120 }
121
122 for i := uint(0); i < qp.Tree.ShowTables; i++ {
123 showTables(tree, w)
124 }
125
126 for _, sctbl := range qp.Tree.ShowColumns {
127 if err := showColumns(tree, sctbl, w); err != nil {
128 log.Println(err)
129 }
130 }
131
132 for _, sctbl := range qp.Tree.ShowCreateTables {
133 if err := showCreateTable(tree, sctbl, buff, w); err != nil {
134 log.Println(err)
135 }
136 }
137

Callers 1

mainFunction · 0.85

Calls 10

FlushMethod · 0.95
LexFunction · 0.92
NewQueryParserFunction · 0.92
ParseFunction · 0.92
NewReadlineWrapFunction · 0.85
execQueryFunction · 0.85
showTablesFunction · 0.85
showColumnsFunction · 0.85
showCreateTableFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected