• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang sqlite.Conn类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中code/google/com/p/gosqlite/sqlite.Conn的典型用法代码示例。如果您正苦于以下问题:Golang Conn类的具体用法?Golang Conn怎么用?Golang Conn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Conn类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:vaibhav2800,项目名称:forge,代码行数:34,代码来源:db.go


示例2: create_tables_if_missing

func create_tables_if_missing(conn *sqlite.Conn) error {
	stmt, err := conn.Prepare("SELECT name FROM sqlite_master " +
		"WHERE name = 'accounts';")
	if err != nil {
		return err
	}
	defer func() {
		err := stmt.Finalize()
		if err != nil {
			log.Println(err)
		}
	}()

	err = stmt.Exec()
	if err != nil {
		return err
	}

	found := false
	for stmt.Next() {
		found = true
	}

	if found {
		return nil
	}
	return hack_create_tables(conn)
}
开发者ID:vaibhav2800,项目名称:forge,代码行数:28,代码来源:db.go


示例3: ChkbkEntries

// ChkbookEntries returns a Stream that emits all the entries in a
// checkbook ordered by most recent to least recent. conn is the sqlite
// connection; acctId is the id of the account for which to print entries.
// If acctId does not match a valid account, ChkbookEntries will return an
// error and nil for the Stream. If caller does not exhaust returned
// Stream, it must call Close on it to free up resources.
func ChkbkEntries(conn *sqlite.Conn, acctId int) (functional.Stream, error) {
	stmt, err := conn.Prepare("select balance from balances where acct_id = ?")
	if err != nil {
		return nil, err
	}
	if err = stmt.Exec(acctId); err != nil {
		stmt.Finalize()
		return nil, err
	}
	if !stmt.Next() {
		stmt.Finalize()
		return nil, errors.New("No balance")
	}
	var bal int64
	if err = stmt.Scan(&bal); err != nil {
		stmt.Finalize()
		return nil, err
	}
	stmt.Finalize()
	stmt, err = conn.Prepare("select date, name, amount from entries where acct_id = ? order by date desc")
	if err != nil {
		return nil, err
	}
	if err = stmt.Exec(acctId); err != nil {
		stmt.Finalize()
		return nil, err
	}
	rowStream := functional.ReadRows(CloserStmt{stmt})
	return functional.Filter(&BalanceFilterer{bal}, rowStream), nil
}
开发者ID:keep94,项目名称:gofunctional2,代码行数:36,代码来源:checkbook.go


示例4: 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
}
开发者ID:kellegous,项目名称:c1kies,代码行数:12,代码来源:browse.go


示例5: 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
}
开发者ID:asokoloski,项目名称:tacserv,代码行数:19,代码来源:setup.go


示例6: visitsNeeded

func visitsNeeded(db *sqlite.Conn) ([]*request, error) {
	var reqs []*request
	s, err := db.Prepare("SELECT url, rank FROM visit WHERE NOT success=1")
	if err != nil {
		return nil, err
	}

	if err := s.Exec(); err != nil {
		return nil, err
	}

	var url string
	var rank int
	for s.Next() {
		if err := s.Scan(&url, &rank); err != nil {
			return nil, err
		}

		reqs = append(reqs, &request{url: url, rank: rank})
	}

	return reqs, nil
}
开发者ID:kellegous,项目名称:c1kies,代码行数:23,代码来源:browse.go


示例7: ChkbkEntries

// ChkbookEntries returns a Generator that emits all the entries in a
// checkbook ordered by most recent to least recent. conn is the sqlite
// connection; acctId is the id of the account for which to print entries.
// If acctId does not match a valid account, ChkbookEntries will return an
// error and nil for the Generator. If caller does not exhaust returned
// Generator, it must call Close on it to free up resources.
func ChkbkEntries(conn *sqlite.Conn, acctId int) (functional.Generator, error) {
	stmt, err := conn.Prepare("select balance from balances where acct_id = ?")
	if err != nil {
		return nil, err
	}
	if err = stmt.Exec(acctId); err != nil {
		stmt.Finalize()
		return nil, err
	}
	if !stmt.Next() {
		stmt.Finalize()
		return nil, errors.New("No balance")
	}
	var bal int64
	if err = stmt.Scan(&bal); err != nil {
		stmt.Finalize()
		return nil, err
	}
	stmt.Finalize()
	stmt, err = conn.Prepare("select date, name, amount from entries where acct_id = ? order by date desc")
	if err != nil {
		return nil, err
	}
	if err = stmt.Exec(acctId); err != nil {
		stmt.Finalize()
		return nil, err
	}
	return functional.NewGenerator(func(emitter functional.Emitter) {
		rowStream := functional.ReadRows(stmt)
		for ptr := emitter.EmitPtr(); ptr != nil && rowStream.Next(ptr); ptr = emitter.EmitPtr() {
			entry := ptr.(*Entry)
			entry.Balance = bal
			bal += entry.Amount
		}
		stmt.Finalize()
	}), nil
}
开发者ID:keep94,项目名称:gofunctional,代码行数:43,代码来源:checkbook.go



注:本文中的code/google/com/p/gosqlite/sqlite.Conn类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang vtsrv.Req类代码示例发布时间:2022-05-24
下一篇:
Golang sessions.Session类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap