Exemplo n.º 1
0
Arquivo: data.go Projeto: mysll/flynet
func GetPlaceHold(typ string, name string) string {
	name = strings.ToLower(name)
	if t := datatype.GetUserType(typ, name); t != nil {
		ret := ""
		sep := ""
		for k := range t {
			sep = ""
			if k != 0 {
				sep = ","
			}
			ret += sep + "?"
		}
		return ret
	}

	return "?"
}
Exemplo n.º 2
0
Arquivo: data.go Projeto: mysll/flynet
func GetDbInsertName(typ string, name string) string {
	name = strings.ToLower(name)
	if t := datatype.GetUserType(typ, name); t != nil {
		ret := ""
		sep := ""
		for k, v := range t {
			sep = ""
			if k != 0 {
				sep = ","
			}
			ret += fmt.Sprintf("%s`%s`", sep, v[0])
		}
		return ret
	}

	return fmt.Sprintf("`p_%s`", strings.ToLower(name))
}
Exemplo n.º 3
0
func (obj *Object) CreateRecordTable() map[string]TblField {

	records := make(map[string]TblField)
	for _, r := range obj.Records {
		if r.Save == "true" && r.Type == "" {

			tbl := TblField{}
			tbl.FieldList = make([]Field, 0, len(r.Columns)+3)

			tbl.FieldList = append(tbl.FieldList, Field{"id", "BIGINT(20) UNSIGNED", false, false})
			tbl.FieldList = append(tbl.FieldList, Field{"index", "SMALLINT(6)", false, false})
			tbl.FieldList = append(tbl.FieldList, Field{"delete", "TINYINT(1) UNSIGNED", false, false})

			for _, p := range r.Columns {
				st := GetDbType(p.Type, p.Len)
				if st != "" {
					tbl.FieldList = append(tbl.FieldList, Field{"p_" + strings.ToLower(p.Name), st, false, false})
				} else {
					usertype := datatype.GetUserType(p.Type, strings.ToLower(p.Name))
					if usertype != nil {
						for _, ut := range usertype {
							if len(ut) != 3 {
								panic("user type serial failed")
							}

							typelen, e := strconv.ParseInt(ut[2], 10, 32)
							if e != nil {
								panic("user type length error")
							}
							tbl.FieldList = append(tbl.FieldList, Field{ut[0], GetDbType(ut[1], int(typelen)), false, false})
						}
					}
				}
			}

			tbl.IndexInfo = make(map[string][]string)
			tbl.IndexInfo["INDEX id"] = []string{"id"}

			records[r.Name] = tbl
		}
	}

	return records

}
Exemplo n.º 4
0
func (obj *Object) CreateTable() TblField {
	tbl := TblField{}
	tbl.FieldList = make([]Field, 0, len(obj.Propertys)+2)
	tbl.FieldList = append(tbl.FieldList, []Field{Field{"id", "BIGINT(20) UNSIGNED", false, false},
		Field{"capacity", "SMALLINT(6)", true, false},
		Field{"configid", "CHAR(64)", true, false},
	}...)
	for _, p := range obj.Propertys {
		if p.Save == "true" {
			st := GetDbType(p.Type, p.Len)
			if st != "" {
				tbl.FieldList = append(tbl.FieldList, Field{"p_" + strings.ToLower(p.Name), st, false, false})
			} else {
				usertype := datatype.GetUserType(p.Type, strings.ToLower(p.Name))
				if usertype != nil {
					for _, ut := range usertype {
						if len(ut) != 3 {
							panic("user type serial failed")
						}

						typelen, e := strconv.ParseInt(ut[2], 10, 32)
						if e != nil {
							panic("user type length error")
						}
						tbl.FieldList = append(tbl.FieldList, Field{ut[0], GetDbType(ut[1], int(typelen)), false, false})
					}
				}
			}
		}
	}

	for _, r := range obj.Records {
		if r.Save == "true" && r.Type != "" {
			tbl.FieldList = append(tbl.FieldList, Field{"r_" + strings.ToLower(r.Name), strings.ToUpper(r.Type), false, false})
		}
	}
	tbl.FieldList = append(tbl.FieldList, Field{"childinfo", "MEDIUMTEXT", false, false})
	tbl.IndexInfo = make(map[string][]string)
	tbl.IndexInfo["PRIMARY"] = []string{"id"}

	return tbl

}