Created
July 28, 2017 17:06
-
-
Save hibooboo2/7151c5f0edcae8539cbd8ea54d5e2313 to your computer and use it in GitHub Desktop.
QL sample Error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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