コード例 #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(),
	})

}
コード例 #2
0
ファイル: build_execute.go プロジェクト: pkdevboxy/query
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)
}
コード例 #3
0
ファイル: service_request.go プロジェクト: jmptrader/query
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)
}
コード例 #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)
	}
}
コード例 #5
0
ファイル: service_request_test.go プロジェクト: mschoch/query
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())
}
コード例 #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
	}
}
コード例 #7
0
ファイル: service_request_test.go プロジェクト: mschoch/query
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")
	}
}