Exemplo n.º 1
0
func preparedSequence(t *testing.T, name string, stmt string) {
	// Verify a sequence of requests:

	// { "prepared": "name" }  fails with "no such name" error
	doNoSuchPrepared(t, name)

	// { "statement": "prepare name as <<N1QL statement>>" }  succeeds
	doPrepare(t, name, stmt)

	// { "prepared": "name" }  succeeds
	doJsonRequest(t, map[string]interface{}{
		"prepared": name,
	})

	prepared, _ := plan.GetPrepared(value.NewValue(name))
	if prepared == nil {
		t.Errorf("Expected to resolve prepared statement with name %v", name)
		return
	}

	// { "prepared": "name", "encoded_plan": "<<encoded plan>>" }  succeeds
	doJsonRequest(t, map[string]interface{}{
		"prepared":     name,
		"encoded_plan": prepared.EncodedPlan(),
	})

}
Exemplo n.º 2
0
func (this *builder) VisitExecute(stmt *algebra.Execute) (interface{}, error) {
	expr := stmt.Prepared()
	if (expr == nil) || expr.Type() != value.STRING && expr.Type() != value.OBJECT {
		return nil, errors.NewUnrecognizedPreparedError(errBadFormat)
	}
	return plan.GetPrepared(expr)
}
Exemplo n.º 3
0
func getPrepared(a httpRequestArgs) (*plan.Prepared, errors.Error) {
	prepared_field, err := a.getValue(PREPARED)
	if err != nil || prepared_field == nil {
		return nil, err
	}
	return plan.GetPrepared(prepared_field)
}
Exemplo n.º 4
0
func doPrepare(t *testing.T, name string, stmt string) {
	doJsonRequest(t, map[string]interface{}{
		"statement": "prepare " + name + " as " + stmt,
	})

	// Verify the name is in the prepared cache:
	prepared, err := plan.GetPrepared(value.NewValue(name))
	if err != nil {
		t.Errorf("Unexpected error looking up prepared: %v", err)
	}

	if prepared == nil {
		t.Errorf("Expected to resolve prepared statement with name %s", name)
	}
}
Exemplo n.º 5
0
func TestPrepared(t *testing.T) {
	name := "name"
	stmt1 := "SELECT 1"

	// Verify the following sequence of requests:
	// { "prepared": "name" }  fails with "no such name" error
	// { "statement": "prepare name as SELECT 1" succeeds
	// { "prepared": "name" }  succeeds
	// { "prepared": "name", "encoded_plan": "<<encoded plan>>" }  succeeds

	doNoSuchPrepared(t, name)
	doPrepare(t, name, stmt1)
	doPreparedNameOnly(t, name)
	prepared, _ := plan.GetPrepared(value.NewValue(name))
	doPreparedWithPlan(t, name, prepared.EncodedPlan())
}
Exemplo n.º 6
0
func doPrepared(endpoint *HttpEndpoint, w http.ResponseWriter, req *http.Request) (interface{}, errors.Error) {
	vars := mux.Vars(req)
	name := vars["name"]

	switch req.Method {
	case "DELETE":
		err := plan.DeletePrepared(name)
		if err != nil {
			return nil, err
		}
		return true, nil
	case "GET":
		return plan.GetPrepared(value.NewValue(name))
	default:
		return nil, nil
	}
}
Exemplo n.º 7
0
func doPrepare(t *testing.T, name string, stmt string) {
	payload := map[string]interface{}{
		"statement": "prepare " + name + " as " + stmt,
	}

	_, err := doJsonEncodedPost(payload)
	if err != nil {
		t.Errorf("Unexpected error in HTTP request: %v", err)
	}

	if query_request.State() != server.COMPLETED {
		t.Errorf("Expected request state: %v, actual: %v\n", server.COMPLETED, query_request.State())
	}

	// Verify the name is in the prepared cache:
	prepared, err := plan.GetPrepared(value.NewValue(name))
	if err != nil {
		t.Errorf("Unexpected error looking up prepared: %v", err)
	}

	if prepared == nil {
		t.Errorf("Expected to resolve prepared statement")
	}
}