//向sqlCode添加"插入数据"的语句，执行前须保证Create()、AutoInsert()已经执行
768974
func (self *MyTable) FlushInsert() error {
	if self.rowsCount == 0 {
		return nil
	}

	colCount := len(self.columnNames)
	if colCount == 0 {
		return nil
	}

	self.sqlCode = `INSERT INTO ` + self.tableName + `(`

	for _, v := range self.columnNames {
		self.sqlCode += v[0] + ","
	}

	self.sqlCode = self.sqlCode[:len(self.sqlCode)-1] + `) VALUES `

	blank := ",(" + strings.Repeat(",?", colCount)[1:] + ")"
	self.sqlCode += strings.Repeat(blank, self.rowsCount)[1:] + `;`

	defer func() {
		// 清空临时数据
		self.args = []interface{}{}
		self.rowsCount = 0
		self.size = 0
		self.sqlCode = ""
	}()

	maxConnChan <- true
	defer func() {
		<-maxConnChan
	}()

	// debug
	// println("FlushInsert():", self.sqlCode)

	_, err := db.Exec(self.sqlCode, self.args...)
	return err
}
250138
func (d *dbBase) PrepareInsert(q dbQuerier, mi *modelInfo) (stmtQuerier, string, error) {
	Q := d.ins.TableQuote()

	dbcols := make([]string, 0, len(mi.fields.dbcols))
	marks := make([]string, 0, len(mi.fields.dbcols))
	for _, fi := range mi.fields.fieldsDB {
		if fi.auto == false {
			dbcols = append(dbcols, fi.column)
			marks = append(marks, "?")
		}
	}
	qmarks := strings.Join(marks, ", ")
	sep := fmt.Sprintf("%s, %s", Q, Q)
	columns := strings.Join(dbcols, sep)

	query := fmt.Sprintf("INSERT INTO %s%s%s (%s%s%s) VALUES (%s)", Q, mi.table, Q, Q, columns, Q, qmarks)

	d.ins.ReplaceMarks(&query)

	d.ins.HasReturningID(mi, &query)

	stmt, err := q.Prepare(query)
	return stmt, query, err
}
599732
func (e *SQLError) Error() string {
	return fmt.Sprintf("ERROR %d (%s): %s", e.Code, e.State, e.Message)
}
585316
func (enc *Encoder) SQLNullInt64KeyNullEmpty(key string, v *sql.NullInt64) {
	if v != nil && v.Valid {
		enc.Int64KeyNullEmpty(key, v.Int64)
	}
}
568234
func (session *Session) SQL(query interface{}, args ...interface{}) *Session {
	session.Statement.SQL(query, args...)
	return session
}
99208
func (enc *Encoder) SQLNullFloat64NullEmpty(v *sql.NullFloat64) {
	if v != nil && v.Valid {
		enc.Float64NullEmpty(v.Float64)
	}
}
1199220
func (node *SQLVal) HexDecode() ([]byte, error) {
	dst := make([]byte, hex.DecodedLen(len([]byte(node.Val))))
	_, err := hex.Decode(dst, []byte(node.Val))
	if err != nil {
		return nil, err
	}
	return dst, err
}
45621
func (sf *ScalarFunction) HashCode(sc *stmtctx.StatementContext) []byte {
	if len(sf.hashcode) > 0 {
		return sf.hashcode
	}
	sf.hashcode = append(sf.hashcode, scalarFunctionFlag)
	sf.hashcode = codec.EncodeCompactBytes(sf.hashcode, hack.Slice(sf.FuncName.L))
	for _, arg := range sf.GetArgs() {
		sf.hashcode = append(sf.hashcode, arg.HashCode(sc)...)
	}
	return sf.hashcode
}
116977
func (b *InsertBuilder) ToCql() (stmt string, names []string) {
	cql := bytes.Buffer{}

	cql.WriteString("INSERT ")

	cql.WriteString("INTO ")
	cql.WriteString(b.table)
	cql.WriteByte(' ')

	cql.WriteByte('(')
	for i, c := range b.columns {
		cql.WriteString(c.column)
		if i < len(b.columns)-1 {
			cql.WriteByte(',')
		}
	}
	cql.WriteString(") ")

	cql.WriteString("VALUES (")
	for i, c := range b.columns {
		names = append(names, c.value.writeCql(&cql)...)
		if i < len(b.columns)-1 {
			cql.WriteByte(',')
		}
	}
	cql.WriteString(") ")

	if b.unique {
		cql.WriteString("IF NOT EXISTS ")
	}
	names = append(names, b.using.writeCql(&cql)...)

	stmt = cql.String()
	return
}
441209
func SQLEncode(cryptStr string, password string) (string, error) {
	var sc sqlCrypt

	cryptStrByte := []byte(cryptStr)
	passwdByte := []byte(password)

	sc.init(passwdByte, len(passwdByte))
	sc.encode(cryptStrByte, len(cryptStrByte))

	return string(cryptStrByte), nil
}
314534
func InsertBySql(query string, value ...interface{}) *InsertStmt {
	return &InsertStmt{
		raw: raw{
			Query: query,
			Value: value,
		},
	}
}
761983
func buildCode() string {

	var clientFields = `{{if eq .Name "client" }}	//Use TLS when Send()ing
	UseTLS bool
	HttpClient *http.Client
{{end}}`

	var fields = `{{range $index, $element := .Fields}}	{{.PrivateName}} {{.Type}}{{if not .Required}}
	{{.PrivateName}}Set bool{{end}}
{{end}}`

	var paramVal = `{{if eq .Type "string"}}h.{{.PrivateName}}{{end}}` +
		`{{if eq .Type "bool"}}bool2str(h.{{.PrivateName}}){{end}}` +
		`{{if eq .Type "int64"}}int2str(h.{{.PrivateName}}){{end}}` +
		`{{if eq .Type "float64"}}float2str(h.{{.PrivateName}}){{end}}`

	var params = `{{range $index, $element := .Fields}}{{if ne .Param ""}}{{if not .Required}}	if h.{{.PrivateName}}Set {
{{end}}		v.Add({{.ParamStr}}, ` + paramVal + `){{if not .Required}}
	}{{end}}
{{end}}{{end}}`

	var constructorDocs = `{{if ne .Name "client" }}// New{{ .StructName }} ` +
		`creates a new {{ .StructName }} Hit Type.` +
		`{{range $index, $element := .Fields}}
		{{if .Required}}{{.Docs}}{{end}}{{end}}`

	var constructorParams = `{{range $index, $element := .Fields}}{{if .Required}}` +
		`{{if ne $index 0}},{{end}}{{.PrivateName}} {{.Type}}` +
		`{{end}}{{end}}`

	var constructor = constructorDocs + `
func New{{ .StructName }}(` + constructorParams + `) *{{.StructName}}	{
	h := &{{ .StructName }}{
{{range $index, $element := .Fields}}{{if .Required}}		{{.PrivateName}}: {{.PrivateName}},
{{end}}{{end}}	}
	return h
}{{end}}
`

	var clientFuncs = `{{if eq .Name "client" }}
func (c *Client) setType(h hitType) {
	switch h.(type) {
{{range $index, $id := .HitTypeIDs}}	case *{{ exportName $id}}:
		c.hitType = "{{ $id }}"
{{end}}	}
}
{{end}}`

	var setterFuncs = `{{range $index, $element := .Fields}}{{if not .Required}}{{.Docs}}
func (h *{{$.StructName}}) {{.Name}}({{.PrivateName}} {{.Type}}) *{{$.StructName}}	{
	h.{{.PrivateName}} = {{.PrivateName}}
	h.{{.PrivateName}}Set = true
	return h
}

{{end}}{{end}}`

	return `package ga

//WARNING: This file was generated. Do not edit.

//{{.StructName}} Hit Type
type {{.StructName}} struct {
` + clientFields + fields + `}

` + constructor + clientFuncs + `

func (h *{{.StructName}}) addFields(v url.Values) error {
` + params + `	return nil
}

` + setterFuncs + `

func (h *{{.StructName}}) Copy() *{{.StructName}} {
	c := *h
	return &c
}
`
}
631733
func (vs ShapeValidations) GoCode(shape *Shape) string {
	buf := &bytes.Buffer{}
	validateShapeTmpl.Execute(buf, map[string]interface{}{
		"Shape":       shape,
		"Validations": vs,
	})
	return buf.String()
}
126275
func (s *ImportSpec) Code() string {
	if len(s.Name) > 0 {
		return fmt.Sprintf(`%s "%s"`, s.Name, s.Path)
	}
	return fmt.Sprintf(`"%s"`, s.Path)
}
977371
func (h *JSONWriter) WriteCode(w http.ResponseWriter, r *http.Request, code int, e interface{}) {
	js, err := json.Marshal(e)
	if err != nil {
		h.WriteError(w, r, errors.WithStack(err))
		return
	}

	if code == 0 {
		code = http.StatusOK
	}

	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(code)
	w.Write(js)
}
417487
func (w *writer) stringCode(str []rune) int {
	if w.counting {
		return 0
	}

	hash := string(str)
	i, ok := w.stringhash[hash]
	if !ok {
		i = len(w.stringhash)
		w.stringhash[hash] = i
		w.stringtable = append(w.stringtable, str)
	}

	return i
}
330742
func (c *Constant) HashCode(sc *stmtctx.StatementContext) []byte {
	if len(c.hashcode) > 0 {
		return c.hashcode
	}
	_, err := c.Eval(chunk.Row{})
	if err != nil {
		terror.Log(err)
	}
	c.hashcode = append(c.hashcode, constantFlag)
	c.hashcode, err = codec.EncodeValue(sc, c.hashcode, c.Value)
	if err != nil {
		terror.Log(err)
	}
	return c.hashcode
}