Commit 1a69c15b authored by gwenn's avatar gwenn

Shell can load the database specified in the command line.

parent 96ee8900
...@@ -133,7 +133,11 @@ func main() { ...@@ -133,7 +133,11 @@ func main() {
err = loadHistory(state, historyFileName) err = loadHistory(state, historyFileName)
check(err) check(err)
db, err := sqlite.Open(":memory:") // TODO command-line flag dbFilename := ":memory:"
if len(os.Args) > 1 {
dbFilename = os.Args[1]
}
db, err := sqlite.Open(dbFilename) // TODO command-line flag
check(err) check(err)
defer db.Close() defer db.Close()
...@@ -175,13 +179,14 @@ func main() { ...@@ -175,13 +179,14 @@ func main() {
for len(cmd) > 0 { for len(cmd) > 0 {
s, err := db.Prepare(cmd) s, err := db.Prepare(cmd)
if trace(err) { if trace(err) {
break break // TODO bail_on_error
} else if s.Empty() { } else if s.Empty() {
cmd = s.Tail() cmd = s.Tail()
continue continue
} }
columnCount := s.ColumnCount() columnCount := s.ColumnCount()
if columnCount > 0 { if columnCount > 0 {
// FIXME headers are displayed only if DataCount() > 0
headers := s.ColumnNames() // TODO .header(s) ON|OFF Turn display of headers on or off headers := s.ColumnNames() // TODO .header(s) ON|OFF Turn display of headers on or off
for _, header := range headers { for _, header := range headers {
io.WriteString(tw, header) io.WriteString(tw, header)
...@@ -204,10 +209,10 @@ func main() { ...@@ -204,10 +209,10 @@ func main() {
} }
if trace(err) { if trace(err) {
s.Finalize() s.Finalize()
break break // TODO bail_on_error
} }
if trace(s.Finalize()) { if trace(s.Finalize()) {
break break // TODO bail_on_error
} }
cmd = s.Tail() cmd = s.Tail()
} // exec } // exec
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment