Exemple #1
0
func (r *sQLiteRepository) Update(db Database) error {
	res, err := r.Connection().Exec("update databases set code=?,connectionstring=?,enabled=?,engine=? where id=?",
		db.Code, db.ConnectionString, tern.Op(db.Enabled, 1, 0), db.Engine, db.ID)
	if err != nil {
		return nil
	}
	if a, err := res.RowsAffected(); err != nil {
		return nil
	} else if a == 0 {
		return ErrNotFound
	}
	return nil
}
Exemple #2
0
func (t *Table) writeRecord(data map[string]interface{}, buf *bufio.Writer) (int, error) {
	var cntwrite int

	cntCols := tern.Op(t.columnsvisible == nil, 0, t.columnsvisible.Len()).(int)
	if n, err := buf.WriteString(Borders[t.border][BKVerticalBorder]); err == nil {
		cntwrite += n
	} else {
		return -1, err
	}

	for num, c := range t.columnsvisible {
		val, mok := data[c.Name]
		if !mok || val == nil {
			val = ""
		}

		mask, ok := t.masks[c]
		if !ok {
			mask = t.GetMaskFormat(c)
			t.masks[c] = mask
		}

		caption := fmt.Sprintf(mask, val)
		if n, err := buf.WriteString(trimEnds(caption, t.getWidth(c))); err == nil {
			cntwrite += n
		} else {
			return -1, err
		}
		var (
			n   int
			err error
		)
		if num < cntCols-1 {
			n, err = buf.WriteString(Borders[t.border][BKVertical])
		} else {
			n, err = buf.WriteString(Borders[t.border][BKVerticalBorder])
		}
		if err == nil {
			cntwrite += n
		} else {
			return -1, err
		}
	}
	if n, err := buf.WriteString(eol.EOL); err == nil {
		cntwrite += n
	} else {
		return -1, err
	}
	return cntwrite, nil
}
Exemple #3
0
func (t *Table) writeRecordHorBorder(buf *bufio.Writer) (int, error) {
	var cntwrite int
	cntCols := tern.Op(t.columnsvisible == nil, 0, t.columnsvisible.Len()).(int)

	if n, err := buf.WriteString(Borders[t.border][BKLeftToRight]); err == nil {
		cntwrite += n
	} else {
		return -1, err
	}

	for num, c := range t.columnsvisible {
		if n, err := buf.WriteString(strings.Repeat(Borders[t.border][BKHorizontal], t.getWidth(c))); err == nil {
			cntwrite += n
		} else {
			return -1, err
		}

		var (
			n   int
			err error
		)
		if num < cntCols-1 {
			n, err = buf.WriteString(Borders[t.border][BKBottomCross])
		} else {
			n, err = buf.WriteString(Borders[t.border][BKRightToLeft])
		}
		if err == nil {
			cntwrite += n
		} else {
			return -1, err
		}

	}

	if n, err := buf.WriteString(eol.EOL); err == nil {
		cntwrite += n
	} else {
		return -1, err
	}
	return cntwrite, nil
}