Ejemplo 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
}
Ejemplo 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
}
Ejemplo n.º 3
0
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
}