示例#1
0
文件: dbexec.go 项目: chogaths/robin
func fillStruct(row mysql.Row, sample reflect.Value, rowIndex int) {

	rowSize := len(row)
	// 遍历输入的结构体, 将每个类型的值缓冲地址存到scanparam中
	for i := 0; i < sample.NumField(); i++ {

		v := sample.Field(i)

		if i >= rowSize {
			log.Printf("out of row size, %d, rowsize: %d", i, rowSize)
			continue
		}

		//log.Println(i, rowIndex, row.Str(rowIndex))

		switch v.Kind() {
		case reflect.Int32, reflect.Uint32, reflect.Int64:
			v.SetInt(row.ForceInt64(rowIndex))
		case reflect.String:
			v.SetString(row.Str(rowIndex))
		case reflect.Struct:
			fillStruct(row, v, rowIndex)
		default:
			log.Printf("dbfw.makeScanParam unsupport type: %s", v.Type())
		}

		rowIndex++

	}
}