failed psql because i forgot the sort. RIP.

This commit is contained in:
bel
2022-10-20 08:53:08 -06:00
parent b5273549e0
commit 2321c171c2
4 changed files with 38 additions and 6 deletions

View File

@@ -15,14 +15,18 @@ func main() {
q := flag.String("q", "show tables", "query to execute")
flag.Parse()
query := strings.Trim(strings.TrimSpace(*q), ";")
if len(query) == 0 {
panic("refusing empty query")
}
query += ";"
log.Printf("%s", query)
db, err := sql.Open("sqlite3", *dbpath)
if err != nil {
panic(err)
}
query := strings.Trim(strings.TrimSpace(*q), ";") + ";"
log.Printf("%s", query)
if strings.HasPrefix(strings.ToUpper(strings.TrimSpace(query)), "SELECT") {
rows, err := db.Query(query)
if err != nil {