示例#1
0
文件: backend.go 项目: aarzilli/pooch
func (tl *Tasklist) GetStatistic(tag string) *Statistic {
	var stmt *sqlite.Stmt
	var err error
	if tag == "" {
		stmt, err = tl.conn.Prepare("SELECT priority, count(priority) FROM tasks GROUP BY priority")
	} else {
		stmt, err = tl.conn.Prepare("SELECT priority, count(priority) FROM tasks WHERE id IN (SELECT id FROM columns WHERE name = ?) GROUP BY priority")
	}
	Must(err)
	defer stmt.Finalize()
	if tag == "" {
		Must(stmt.Exec())
	} else {
		Must(stmt.Exec(tag))
	}

	name := "#" + tag
	link := name
	if tag == "" {
		name = "Any"
		link = ""
	}

	r := &Statistic{name, link, 0, 0, 0, 0, 0, 0, 0}

	for stmt.Next() {
		var priority, count int

		stmt.Scan(&priority, &count)

		switch Priority(priority) {
		case STICKY:
			r.Sticky += count
		case NOTES:
			r.Notes += count
		case NOW:
			r.Now += count
		case LATER:
			r.Later += count
		case DONE:
			r.Done += count
		case TIMED:
			r.Timed += count
		default:
			r.Total += count
		}
	}

	r.Total += r.Sticky + r.Notes + r.Now + r.Later + r.Done + r.Timed

	return r
}
示例#2
0
文件: backend.go 项目: aarzilli/pooch
func (tl *Tasklist) GetListEx(stmt *sqlite.Stmt, code string, incsub bool) ([]*Entry, error) {
	var err error

	if code != "" {
		tl.luaState.CheckStack(1)
		tl.luaState.PushNil()
		tl.luaState.SetGlobal(SEARCHFUNCTION)
		tl.luaState.DoString(fmt.Sprintf("function %s()\n%s\nend", SEARCHFUNCTION, code))
		tl.luaState.GetGlobal(SEARCHFUNCTION)
		if tl.luaState.IsNil(-1) {
			tl.LogError("Syntax error in search function definition")
			code = ""
			err = &LuaIntError{"Syntax error in search function definition"}
		}
		tl.luaState.Pop(1)
	}

	v := []*Entry{}
	for stmt.Next() {
		entry, scanerr := StatementScan(stmt, true)
		Must(scanerr)

		if code != "" {
			if cerr := tl.CallLuaFunction(SEARCHFUNCTION, entry); cerr != nil {
				err = cerr
			}

			if tl.luaFlags.remove {
				tl.Remove(entry.Id())
			}

			if tl.luaFlags.persist {
				if !tl.luaFlags.remove && tl.luaFlags.cursorEdited {
					tl.Update(entry, false)
				}
				if tl.luaFlags.cursorCloned {
					newentry := GetEntryFromLua(tl.luaState, CURSOR, "%internal%")
					tl.Add(newentry)
				}
			}

			if tl.luaFlags.filterOut {
				continue
			}
		}

		if !incsub {
			skip := false
			for k, _ := range entry.Columns() {
				if strings.HasPrefix(k, "sub/") {
					skip = true
					break
				}
			}
			if skip {
				continue
			}
		}

		v = append(v, entry)
	}
	return v, err
}