Esempio n. 1
0
func StatementScan(stmt *sqlite.Stmt, hasCols bool) (*Entry, error) {
	var priority_num int
	var trigger_str, id, title, text, sort, columns string
	var scanerr error
	if hasCols {
		scanerr = stmt.Scan(&id, &title, &text, &priority_num, &trigger_str, &sort, &columns)
	} else {
		scanerr = stmt.Scan(&id, &title, &text, &priority_num, &trigger_str, &sort)
	}
	triggerAt, _ := ParseDateTime(trigger_str, 0)
	priority := Priority(priority_num)

	if scanerr != nil {
		return nil, scanerr
	}

	Logf(DEBUG, "Reading columns: %v [%s]\n", hasCols, columns)

	cols := make(Columns)
	if hasCols {
		pieces := strings.Split(columns, "\u001f")
		for i := 0; i+1 < len(pieces); i += 2 {
			Logf(DEBUG, "   col: [%s] [%s]\n", pieces[0], pieces[1])
			cols[pieces[i]] = pieces[i+1]
		}
	}

	Logf(DEBUG, "Columns are: %v\n", cols)

	return MakeEntry(id, title, text, priority, triggerAt, sort, cols), nil
}
Esempio n. 2
0
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
}