Skip to content

Instantly share code, notes, and snippets.

@hibooboo2
Created July 28, 2017 17:06
Show Gist options
  • Save hibooboo2/7151c5f0edcae8539cbd8ea54d5e2313 to your computer and use it in GitHub Desktop.
Save hibooboo2/7151c5f0edcae8539cbd8ea54d5e2313 to your computer and use it in GitHub Desktop.
QL sample Error
package main
import (
"database/sql"
"fmt"
_ "github.com/cznic/ql/driver"
)
var tables = [...]string{`CREATE TABLE IF NOT EXISTS things (
some_name varchar(256) NOT NULL,
type int NOT NULL,
idle_timeout int NOT NULL,
config text NOT NULL,
PRIMARY KEY (some_name, type)
);`,
`CREATE TABLE IF NOT EXISTS otherthings (
name varchar(256) NOT NULL PRIMARY KEY,
config text NOT NULL
);`,
}
func main() {
db, err := sql.Open("ql", "data/ql.db")
if err != nil {
panic(err)
}
for _, v := range tables {
tx, err := db.Begin()
if err != nil {
panic(err)
}
_, err = tx.Exec(v)
if err != nil {
err2 := tx.Rollback()
if err2 != nil {
panic(fmt.Errorf("err: %s err2 %s", err, err2))
}
panic(err)
}
err = tx.Commit()
if err != nil {
panic(err)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment