package dialect

import (
	
	
	
	
	

	
	
)

func ( []byte,  error) []byte {
	 = append(, "?!("...)
	 = append(, .Error()...)
	 = append(, ')')
	return 
}

func ( []byte) []byte {
	return append(, "NULL"...)
}

func ( []byte,  bool) []byte {
	if  {
		return append(, "TRUE"...)
	}
	return append(, "FALSE"...)
}

func ( []byte,  float32) []byte {
	return appendFloat(, float64(), 32)
}

func ( []byte,  float64) []byte {
	return appendFloat(, , 64)
}

func ( []byte,  float64,  int) []byte {
	switch {
	case math.IsNaN():
		return append(, "'NaN'"...)
	case math.IsInf(, 1):
		return append(, "'Infinity'"...)
	case math.IsInf(, -1):
		return append(, "'-Infinity'"...)
	default:
		return strconv.AppendFloat(, , 'f', -1, )
	}
}

func ( []byte,  string) []byte {
	 = append(, '\'')
	for ,  := range  {
		if  == '\000' {
			continue
		}

		if  == '\'' {
			 = append(, '\'', '\'')
			continue
		}

		if  < utf8.RuneSelf {
			 = append(, byte())
			continue
		}

		 := len()
		if cap()- < utf8.UTFMax {
			 = append(, make([]byte, utf8.UTFMax)...)
		}
		 := utf8.EncodeRune([:+utf8.UTFMax], )
		 = [:+]
	}
	 = append(, '\'')
	return 
}

func ( []byte,  []byte) []byte {
	if  == nil {
		return AppendNull()
	}

	 = append(, `'\x`...)

	 := len()
	 = append(, make([]byte, hex.EncodedLen(len()))...)
	hex.Encode([:], )

	 = append(, '\'')

	return 
}

func ( []byte,  time.Time) []byte {
	 = append(, '\'')
	 = .UTC().AppendFormat(, "2006-01-02 15:04:05.999999-07:00")
	 = append(, '\'')
	return 
}

func (,  []byte) []byte {
	 = append(, '\'')

	 := parser.New()
	for .Valid() {
		 := .Read()
		switch  {
		case '"':
			 = append(, '"')
		case '\'':
			 = append(, "''"...)
		case '\000':
			continue
		case '\\':
			if .SkipBytes([]byte("u0000")) {
				 = append(, `\\u0000`...)
			} else {
				 = append(, '\\')
				if .Valid() {
					 = append(, .Read())
				}
			}
		default:
			 = append(, )
		}
	}

	 = append(, '\'')

	return 
}

//------------------------------------------------------------------------------

func ( []byte,  string,  byte) []byte {
	return appendIdent(, internal.Bytes(), )
}

func (,  []byte,  byte) []byte {
	var  bool
:
	for ,  := range  {
		switch  {
		case '*':
			if ! {
				 = append(, '*')
				continue 
			}
		case '.':
			if  {
				 = append(, )
				 = false
			}
			 = append(, '.')
			continue 
		}

		if ! {
			 = append(, )
			 = true
		}
		if  ==  {
			 = append(, , )
		} else {
			 = append(, )
		}
	}
	if  {
		 = append(, )
	}
	return 
}