示例#1
0
文件: db.go 项目: ymonk/torrent
func (me *dbPieceCompletion) Set(p metainfo.Piece, b bool) (err error) {
	if b {
		_, err = me.db.Exec(`insert into completed (infohash, "index") values (?, ?)`, p.Info.Hash().HexString(), p.Index())
	} else {
		_, err = me.db.Exec(`delete from completed where infohash=? and "index"=?`, p.Info.Hash().HexString(), p.Index())
	}
	return
}
示例#2
0
文件: db.go 项目: ymonk/torrent
func (me *dbPieceCompletion) Get(p metainfo.Piece) (ret bool, err error) {
	row := me.db.QueryRow(`select exists(select * from completed where infohash=? and "index"=?)`, p.Info.Hash().HexString(), p.Index())
	err = row.Scan(&ret)
	return
}