Example #1
0
func AddPrepared(prepared *Prepared) errors.Error {
	if cache.peek(prepared) {
		return errors.NewPreparedNameError(
			fmt.Sprintf("duplicate name: %s", prepared.Name()))
	}
	cache.add(prepared)
	return nil
}
Example #2
0
func (this *builder) VisitPrepare(stmt *algebra.Prepare) (interface{}, error) {
	pl, err := BuildPrepared(stmt.Statement(), this.datastore, this.systemstore, this.namespace, false)
	if err != nil {
		return nil, err
	}

	if stmt.Name() == "" {
		uuid, err := util.UUID()
		if err != nil {
			return nil, errors.NewPreparedNameError(err.Error())
		}
		pl.SetName(uuid)
	} else {
		pl.SetName(stmt.Name())
	}

	pl.SetText(stmt.Text())

	json_bytes, err := pl.MarshalJSON()
	if err != nil {
		return nil, err
	}

	var b bytes.Buffer
	w := gzip.NewWriter(&b)
	w.Write(json_bytes)
	w.Close()
	str := base64.StdEncoding.EncodeToString(b.Bytes())
	pl.SetEncodedPlan(str)
	val := value.NewValue(json_bytes)
	err = val.SetField("encoded_plan", value.NewValue(str))
	if err != nil {
		return nil, err
	}

	err = plan.AddPrepared(pl)
	if err != nil {
		return nil, err
	}

	return plan.NewPrepare(val), nil
}