本文整理汇总了Golang中code/google/com/p/gosqlite/sqlite.Conn.Exec方法的典型用法代码示例。如果您正苦于以下问题:Golang Conn.Exec方法的具体用法?Golang Conn.Exec怎么用?Golang Conn.Exec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类code/google/com/p/gosqlite/sqlite.Conn
的用法示例。
在下文中一共展示了Conn.Exec方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: hack_create_tables
// HACK to execute a script file. Python3 has a helper executescript(..).
// Don't know the way to do it in the C API. Maybe sqlite3_complete(..) helps
// by extending the current substring until the following semicolon, until
// it says the query is complete (you can also have semicolons in strings).
// Execute and repeat. Maybe.
// No support in gosqlite, but for now our create-tables script is simple
// and we can execute substrings up to each semicolon.
func hack_create_tables(conn *sqlite.Conn) error {
bytes, err := ioutil.ReadFile(createTablesFile)
if err != nil {
return err
}
chars := []rune(strings.TrimSpace(string(bytes)))
for i := 0; i < len(chars); {
j := i
for ; j < len(chars)-1; j++ {
if chars[j] == ';' {
break
}
}
// now 'j' is either the first semicolon or the very last rune
query := chars[i : j+1]
err = conn.Exec(string(query))
if err != nil {
return err
}
i = j + 1
}
return nil
}
示例2: updateVisit
func updateVisit(db *sqlite.Conn, req *request, rsp *browseRsp, ok bool) error {
success := 1
if !ok {
success = 0
}
err := db.Exec(`
UPDATE visit SET success=?1, cookies=?2, resources=?3, screenshot=?4, stdout=?5, stderr=?6
WHERE url=?7`,
success, rsp.cookies, rsp.resources, rsp.screenshot, rsp.stdout, rsp.stderr, req.url)
return err
}
示例3: setup
// exits program on failure
func setup(db *sqlite.Conn) error {
statements := []string{
"create table if not exists tool (node_id int, name text, status int)",
"create table if not exists permission (node_id int, timestamp datetime default (CURRENT_TIMESTAMP), card_id text, granter_card_id text, is_maintainer boolean default 0)",
"create unique index if not exists permission_node_card on permission (node_id, card_id)",
"create table if not exists tool_usage (node_id int, timestamp datetime default (CURRENT_TIMESTAMP), status int, card_id text)",
"create table if not exists case_alert (node_id int, timestamp datetime default (CURRENT_TIMESTAMP), status int)",
}
for _, stmt := range statements {
err := db.Exec(stmt)
if err != nil {
log("error executing:", stmt)
return err
}
}
return nil
}