本文整理汇总了Golang中code/google/com/p/gosqlite/sqlite.Conn.Prepare方法的典型用法代码示例。如果您正苦于以下问题:Golang Conn.Prepare方法的具体用法?Golang Conn.Prepare怎么用?Golang Conn.Prepare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类code/google/com/p/gosqlite/sqlite.Conn
的用法示例。
在下文中一共展示了Conn.Prepare方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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)
}
示例2: 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
}
示例3: 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
}
示例4: 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
}