stub
This commit is contained in:
3
amex-2022-10-20/0_setup/go.mod
Normal file
3
amex-2022-10-20/0_setup/go.mod
Normal file
@@ -0,0 +1,3 @@
|
||||
module 0_setup
|
||||
|
||||
go 1.18
|
||||
37
amex-2022-10-20/0_setup/main.go
Normal file
37
amex-2022-10-20/0_setup/main.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"flag"
|
||||
"log"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
dbpath := flag.String("db", "./db.db", "path to db file")
|
||||
q := flag.String("q", "show tables", "query to execute")
|
||||
flag.Parse()
|
||||
|
||||
db, err := sql.Open("sqlite3", *dbpath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if strings.HasPrefix(strings.ToUpper(strings.TrimSpace(*q)), "SELECT") {
|
||||
panic("not impl")
|
||||
} else {
|
||||
stmt, err := db.Prepare(*q)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
result, err := stmt.Exec()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
affected, err := result.RowsAffected()
|
||||
log.Printf("%d: %v", affected, err)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user