// Trunc calls the stored procedure 'pg_catalog.trunc(double precision, macaddr, numeric, numeric, integer) numeric' on db.
972865
func Trunc(db XODB, v0 float64, v1 pgtypes.Macaddr, v2 float64, v3 float64, v4 int) (float64, error) {
	var err error

	// sql query
	const sqlstr = `SELECT pg_catalog.trunc($1, $2, $3, $4, $5)`

	// run query
	var ret float64
	XOLog(sqlstr, v0, v1, v2, v3, v4)
	err = db.QueryRow(sqlstr, v0, v1, v2, v3, v4).Scan(&ret)
	if err != nil {
		return 0.0, err
	}

	return ret, nil
}
932948
func TruncateString(str string, limit int) string {
	if len(str) < limit {
		return str
	}
	return str[:limit]
}
873179
func Truncate(formatter Formatter, length int) Formatter {
	return func(buffer Buffer, event *cue.Event) {
		tmp := GetBuffer()
		defer ReleaseBuffer(tmp)

		formatter(tmp, event)
		bytes := tmp.Bytes()
		if len(bytes) > length {
			bytes = bytes[:length]
		}
		buffer.Append(bytes)
	}
}
756492
func Truncate(str string, length int, ending string) string {
	var aftstr, befstr string
	if len(str) > length {
		words := strings.Fields(str)
		before, present := 0, 0
		for i := range words {
			befstr = aftstr
			before = present
			aftstr = aftstr + words[i] + " "
			present = len(aftstr)
			if present > length && i != 0 {
				if (length - before) < (present - length) {
					return Trim(befstr, " /\\.,\"'#!?&@+-") + ending
				}
				return Trim(aftstr, " /\\.,\"'#!?&@+-") + ending
			}
		}
	}

	return str
}
556376
func (c *Condition) Truncate(s string, w int, tail string) string {
	if c.StringWidth(s) <= w {
		return s
	}
	r := []rune(s)
	tw := c.StringWidth(tail)
	w -= tw
	width := 0
	i := 0
	for ; i < len(r); i++ {
		cw := c.RuneWidth(r[i])
		if width+cw > w {
			break
		}
		width += cw
	}
	return string(r[0:i]) + tail
}
242634
func DateTrunc(db XODB, v0 string, v1 time.Time, v2 string, v3 time.Time, v4 string, v5 *time.Duration) (time.Time, error) {
	var err error

	// sql query
	const sqlstr = `SELECT pg_catalog.date_trunc($1, $2, $3, $4, $5, $6)`

	// run query
	var ret time.Time
	XOLog(sqlstr, v0, v1, v2, v3, v4, v5)
	err = db.QueryRow(sqlstr, v0, v1, v2, v3, v4, v5).Scan(&ret)
	if err != nil {
		return time.Time{}, err
	}

	return ret, nil
}
417541
func (s *children) truncate(index int) {
	var toClear children
	*s, toClear = (*s)[:index], (*s)[index:]
	for len(toClear) > 0 {
		toClear = toClear[copy(toClear, nilChildren):]
	}
}
327774
func (b *Buffer) Truncate(n int) {
	switch {
	case n < 0 || n > b.Len():
		panic("leveldb/util.Buffer: truncation out of range")
	case n == 0:
		// Reuse buffer space.
		b.off = 0
	}
	b.buf = b.buf[0 : b.off+n]
}
14553
func (c Context) Truncate(input string, length int) string {
	if length < 0 && len(input)+length > 0 {
		return input[len(input)+length:]
	}
	if length >= 0 && len(input) > length {
		return input[:length]
	}
	return input
}
922322
func TruncateTables(db *sql.DB) {
	for model := range models {
		db.Exec(fmt.Sprintf("DELETE FROM %ss", string(model)))
	}
}
311531
func (b *Builder) Truncate(n int) {
	b.lastRead = opInvalid
	switch {
	case n < 0 || n > b.Len():
		// Originall this was a panic, but I hate panicing (hehe),
		// so instead let's just ignore this issue.
		// panic("bytes.Buffer: truncation out of range")
		return
	case n == 0:
		// Reuse buffer space.
		b.off = 0
	}
	b.buf = b.buf[0 : b.off+n]
}
622388
func (c *adminClient) TruncateScope(ctx context.Context, s string) error {
	return c.connector.TruncateScope(ctx, s)
}
934347
func (w *WAL) Truncate(i int) (err error) {
	w.truncateTotal.Inc()
	defer func() {
		if err != nil {
			w.truncateFail.Inc()
		}
	}()
	refs, err := listSegments(w.dir)
	if err != nil {
		return err
	}
	for _, r := range refs {
		if r.index >= i {
			break
		}
		if err = os.Remove(filepath.Join(w.dir, r.name)); err != nil {
			return err
		}
	}
	return nil
}
1091583
func (s *WorkflowExecutionCount) SetTruncated(v bool) *WorkflowExecutionCount {
	s.Truncated = &v
	return s
}
471270
func (m *mysql) TruncateAll(tx *Connection) error {
	var stmts []string
	err := tx.RawQuery(mysqlTruncate, m.Details().Database).All(&stmts)
	if err != nil {
		return err
	}
	if len(stmts) == 0 {
		return nil
	}

	var qb bytes.Buffer
	// #49: Disable foreign keys before truncation
	qb.WriteString("SET SESSION FOREIGN_KEY_CHECKS = 0; ")
	qb.WriteString(strings.Join(stmts, " "))
	// #49: Re-enable foreign keys after truncation
	qb.WriteString(" SET SESSION FOREIGN_KEY_CHECKS = 1;")

	return tx.RawQuery(qb.String()).Exec()
}
107541
func Regprocsend(db XODB, v0 pgtypes.Regproc) ([]byte, error) {
	var err error

	// sql query
	const sqlstr = `SELECT pg_catalog.regprocsend($1)`

	// run query
	var ret []byte
	XOLog(sqlstr, v0)
	err = db.QueryRow(sqlstr, v0).Scan(&ret)
	if err != nil {
		return nil, err
	}

	return ret, nil
}
1335676
func goTimeToMysqlUnixTimestamp(t time.Time, decimal int) (*types.MyDecimal, error) {
	nanoSeconds := t.UnixNano()
	if nanoSeconds < 0 || (nanoSeconds/1e3) >= (math.MaxInt32+1)*1e6 {
		return new(types.MyDecimal), nil
	}
	dec := new(types.MyDecimal)
	// Here we don't use float to prevent precision lose.
	dec.FromInt(nanoSeconds)
	err := dec.Shift(-9)
	if err != nil {
		return nil, err
	}

	// In MySQL's implementation, unix_timestamp() will truncate the result instead of rounding it.
	// Results below are from MySQL 5.7, which can prove it.
	//	mysql> select unix_timestamp(), unix_timestamp(now(0)), now(0), unix_timestamp(now(3)), now(3), now(6);
	//	+------------------+------------------------+---------------------+------------------------+-------------------------+----------------------------+
	//	| unix_timestamp() | unix_timestamp(now(0)) | now(0)              | unix_timestamp(now(3)) | now(3)                  | now(6)                     |
	//	+------------------+------------------------+---------------------+------------------------+-------------------------+----------------------------+
	//	|       1553503194 |             1553503194 | 2019-03-25 16:39:54 |         1553503194.992 | 2019-03-25 16:39:54.992 | 2019-03-25 16:39:54.992969 |
	//	+------------------+------------------------+---------------------+------------------------+-------------------------+----------------------------+
	err = dec.Round(dec, decimal, types.ModeTruncate)
	return dec, err
}