コード例 #1
0
func (p *NullPoint) Scan(vr *pgx.ValueReader) error {
	if vr.Type().DataTypeName != "point" {
		return pgx.SerializationError(fmt.Sprintf("NullPoint.Scan cannot decode %s (OID %d)", vr.Type().DataTypeName, vr.Type().DataType))
	}

	if vr.Len() == -1 {
		p.X, p.Y, p.Valid = 0, 0, false
		return nil
	}

	switch vr.Type().FormatCode {
	case pgx.TextFormatCode:
		s := vr.ReadString(vr.Len())
		match := pointRegexp.FindStringSubmatch(s)
		if match == nil {
			return pgx.SerializationError(fmt.Sprintf("Received invalid point: %v", s))
		}

		var err error
		p.X, err = strconv.ParseFloat(match[1], 64)
		if err != nil {
			return pgx.SerializationError(fmt.Sprintf("Received invalid point: %v", s))
		}
		p.Y, err = strconv.ParseFloat(match[2], 64)
		if err != nil {
			return pgx.SerializationError(fmt.Sprintf("Received invalid point: %v", s))
		}
	case pgx.BinaryFormatCode:
		return errors.New("binary format not implemented")
	default:
		return fmt.Errorf("unknown format %v", vr.Type().FormatCode)
	}

	p.Valid = true
	return vr.Err()
}
コード例 #2
0
func (*shortScanner) Scan(r *pgx.ValueReader) error {
	r.ReadByte()
	return nil
}