• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang parser.Parse函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/cockroachdb/cockroach/sql/parser.Parse函数的典型用法代码示例。如果您正苦于以下问题:Golang Parse函数的具体用法?Golang Parse怎么用?Golang Parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Parse函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: exec

// Send forwards the call for further processing.
func (s *Server) exec(call sqlwire.Call) {
	req := call.Args
	resp := call.Reply
	stmt, err := parser.Parse(req.Sql)
	if err != nil {
		resp.SetGoError(err)
		return
	}
	switch p := stmt.(type) {
	case *parser.CreateDatabase:
		s.CreateDatabase(p, req.Params, resp)
	case *parser.CreateTable:
		s.CreateTable(p, req.Params, resp)
	case *parser.Delete:
		s.Delete(p, req.Params, resp)
	case *parser.Insert:
		s.Insert(p, req.Params, resp)
	case *parser.Select:
		s.Select(p, req.Params, resp)
	case *parser.ShowColumns:
		s.ShowColumns(p, req.Params, resp)
	case *parser.ShowDatabases:
		s.ShowDatabases(p, req.Params, resp)
	case *parser.ShowIndex:
		s.ShowIndex(p, req.Params, resp)
	case *parser.ShowTables:
		s.ShowTables(p, req.Params, resp)
	case *parser.Update:
		s.Update(p, req.Params, resp)
	case *parser.Use:
		s.Use(p, req.Params, resp)
	default:
		resp.SetGoError(fmt.Errorf("unknown statement type: %T", stmt))
	}
}
开发者ID:Gardenya,项目名称:cockroach,代码行数:36,代码来源:server.go


示例2: Exec

func (c *conn) Exec(query string, args []driver.Value) (driver.Result, error) {
	stmt, err := parser.Parse(query)
	if err != nil {
		return nil, err
	}
	return c.exec(stmt, args)
}
开发者ID:Jaekyun,项目名称:cockroach,代码行数:7,代码来源:conn.go


示例3: Prepare

func (c *conn) Prepare(query string) (driver.Stmt, error) {
	s, err := parser.Parse(query)
	if err != nil {
		return nil, err
	}
	return &stmt{conn: c, stmt: s}, nil
}
开发者ID:Jaekyun,项目名称:cockroach,代码行数:7,代码来源:conn.go


示例4: Query

func (c *conn) Query(query string, args []driver.Value) (driver.Rows, error) {
	stmt, err := parser.Parse(query)
	if err != nil {
		return nil, err
	}
	return c.query(stmt, args)
}
开发者ID:Jaekyun,项目名称:cockroach,代码行数:7,代码来源:conn.go


示例5: exec

// exec executes the request. Any error encountered is returned; it is
// the caller's responsibility to update the response.
func (s *Server) exec(req driver.Request) (driver.Response, error) {
	var resp driver.Response

	// Pick up current session state.
	planner := planner{db: s.db}
	if req.Session != nil {
		// TODO(tschottdorf) will have to validate the Session information (for
		// instance, whether access to the stored database is permitted).
		if err := gogoproto.Unmarshal(req.Session, &planner.session); err != nil {
			return resp, err
		}
	}
	stmts, err := parser.Parse(req.Sql)
	if err != nil {
		return resp, err
	}
	for _, stmt := range stmts {
		// Bind all the placeholder variables in the stmt to actual values.
		if err := parser.FillArgs(stmt, parameters(req.Params)); err != nil {
			return resp, err
		}
		var plan planNode
		if plan, err = planner.makePlan(stmt); err != nil {
			return resp, err
		}

		result := driver.Result{
			Columns: plan.Columns(),
		}
		for plan.Next() {
			values := plan.Values()
			row := driver.Result_Row{}
			row.Values = make([]driver.Datum, 0, len(values))
			for _, val := range values {
				switch vt := val.(type) {
				case parser.DBool:
					row.Values = append(row.Values, driver.Datum{BoolVal: (*bool)(&vt)})
				case parser.DInt:
					row.Values = append(row.Values, driver.Datum{IntVal: (*int64)(&vt)})
				case parser.DFloat:
					row.Values = append(row.Values, driver.Datum{FloatVal: (*float64)(&vt)})
				case parser.DString:
					row.Values = append(row.Values, driver.Datum{StringVal: (*string)(&vt)})
				case parser.DNull:
					row.Values = append(row.Values, driver.Datum{})
				default:
					return resp, util.Errorf("unsupported datum: %T", val)
				}
			}
			result.Rows = append(result.Rows, row)
		}
		resp.Results = append(resp.Results, result)
	}

	// Update session state.
	resp.Session, err = gogoproto.Marshal(&planner.session)
	return resp, err
}
开发者ID:arypurnomoz,项目名称:cockroach,代码行数:60,代码来源:server.go


示例6: fuzzSingle

func fuzzSingle(stmt parser.Statement) (interestingness int) {
	var lastExpr parser.Expr
	rcvr := func() {
		if r := recover(); r != nil {
			if !expected(fmt.Sprintf("%v", r)) {
				fmt.Printf("Stmt: %s\n%s", stmt, spew.Sdump(stmt))
				if lastExpr != nil {
					fmt.Printf("Expr: %s", spew.Sdump(lastExpr))
				}
				panic(r)
			}
			// Anything that has expected errors in it is fine, but not as
			// interesting as things that go through.
			interestingness = 1
		}
	}
	defer rcvr()

	data0 := stmt.String()
	// TODO(tschottdorf): again, this is since we're ignoring stuff in the
	// grammar instead of erroring out on unsupported language. See:
	// https://github.com/cockroachdb/cockroach/issues/1949
	if strings.Contains(data0, "%!s(<nil>)") {
		return 0
	}
	stmt1, err := parser.Parse(data0)
	if err != nil {
		fmt.Printf("AST: %s", spew.Sdump(stmt))
		fmt.Printf("data0: %q\n", data0)
		panic(err)
	}
	interestingness = 2

	data1 := stmt1.String()
	// TODO(tschottdorf): due to the ignoring issue again.
	// if !reflect.DeepEqual(stmt, stmt1) {
	if data1 != data0 {
		fmt.Printf("data0: %q\n", data0)
		fmt.Printf("AST: %s", spew.Sdump(stmt))
		fmt.Printf("data1: %q\n", data1)
		fmt.Printf("AST: %s", spew.Sdump(stmt1))
		panic("not equal")
	}

	var v visitorFunc = func(e parser.Expr) parser.Expr {
		lastExpr = e
		if _, err := parser.EvalExpr(e); err != nil {
			panic(err)
		}
		return e
	}
	parser.WalkStmt(v, stmt)
	return
}
开发者ID:cockroachdb,项目名称:go-fuzz,代码行数:54,代码来源:main.go


示例7: exec

// Send forwards the call for further processing.
func (s *Server) exec(call sqlwire.Call) {
	req := call.Args
	resp := call.Reply
	// Pick up current session state.
	var session Session
	if req.Session != nil {
		if err := gogoproto.Unmarshal(req.Session, &session); err != nil {
			resp.SetGoError(err)
			return
		}
	}
	stmt, err := parser.Parse(req.Sql)
	if err != nil {
		resp.SetGoError(err)
		return
	}
	switch p := stmt.(type) {
	case *parser.CreateDatabase:
		s.CreateDatabase(&session, p, req.Params, resp)
	case *parser.CreateTable:
		s.CreateTable(&session, p, req.Params, resp)
	case *parser.Delete:
		s.Delete(&session, p, req.Params, resp)
	case *parser.Insert:
		s.Insert(&session, p, req.Params, resp)
	case *parser.Select:
		s.Select(&session, p, req.Params, resp)
	case *parser.ShowColumns:
		s.ShowColumns(&session, p, req.Params, resp)
	case *parser.ShowDatabases:
		s.ShowDatabases(&session, p, req.Params, resp)
	case *parser.ShowIndex:
		s.ShowIndex(&session, p, req.Params, resp)
	case *parser.ShowTables:
		s.ShowTables(&session, p, req.Params, resp)
	case *parser.Update:
		s.Update(&session, p, req.Params, resp)
	case *parser.Use:
		s.Use(&session, p, req.Params, resp)
	default:
		resp.SetGoError(fmt.Errorf("unknown statement type: %T", stmt))
	}
	// Update session state.
	if resp.Error != nil {
		return
	}
	payload, err := gogoproto.Marshal(&session)
	if err != nil {
		resp.SetGoError(util.Errorf("unable to marshal %+v to protobuf: %s", session, err))
		return
	}
	resp.Session = payload
}
开发者ID:greener98103,项目名称:cockroach,代码行数:54,代码来源:server.go


示例8: exec

// Send forwards the call for further processing.
func (s *Server) exec(call sqlwire.Call) error {
	req := call.Args
	resp := call.Reply
	// Pick up current session state.
	var session Session
	if req.Session != nil {
		// TODO(tschottdorf) will have to validate the Session information (for
		// instance, whether access to the stored database is permitted).
		if err := gogoproto.Unmarshal(req.Session, &session); err != nil {
			return err
		}
	}
	stmts, err := parser.Parse(req.Sql)
	if err != nil {
		return err
	}
	for _, stmt := range stmts {
		switch p := stmt.(type) {
		case *parser.CreateDatabase:
			err = s.CreateDatabase(&session, p, req.Params, resp)
		case *parser.CreateTable:
			err = s.CreateTable(&session, p, req.Params, resp)
		case *parser.Delete:
			err = s.Delete(&session, p, req.Params, resp)
		case *parser.Insert:
			err = s.Insert(&session, p, req.Params, resp)
		case *parser.Select:
			err = s.Select(&session, p, req.Params, resp)
		case *parser.Set:
			err = s.Set(&session, p, req.Params, resp)
		case *parser.ShowColumns:
			err = s.ShowColumns(&session, p, req.Params, resp)
		case *parser.ShowDatabases:
			err = s.ShowDatabases(&session, p, req.Params, resp)
		case *parser.ShowIndex:
			err = s.ShowIndex(&session, p, req.Params, resp)
		case *parser.ShowTables:
			err = s.ShowTables(&session, p, req.Params, resp)
		case *parser.Update:
			err = s.Update(&session, p, req.Params, resp)
		default:
			err = fmt.Errorf("unknown statement type: %T", stmt)
		}
		if err != nil {
			return err
		}
	}

	// Update session state.
	resp.Session, err = gogoproto.Marshal(&session)
	return err
}
开发者ID:zmoon111,项目名称:cockroach,代码行数:53,代码来源:server.go


示例9: Fuzz

// Fuzz is the entry point for go-fuzz. Run it via
//	  go-fuzz-build github.com/cockroachdb/go-fuzz/examples/parser && \
//    go-fuzz -bin=./parser-fuzz.zip -workdir=.
func Fuzz(data []byte) (interestingness int) {
	sql := string(data)
	stmts, err := parser.Parse(sql)
	if err != nil || stmts == nil {
		if stmts != nil {
			panic("stmt is not nil on error")
		}
		return
	}
	for _, stmt := range stmts {
		interestingness = fuzzSingle(stmt)
	}
	return
}
开发者ID:sjn1978,项目名称:go-fuzz,代码行数:17,代码来源:main.go


示例10: TestPrimaryKeyUnspecified

func TestPrimaryKeyUnspecified(t *testing.T) {
	defer leaktest.AfterTest(t)
	stmt, err := parser.Parse("CREATE TABLE test (a INT, b INT, CONSTRAINT c UNIQUE (b))")
	if err != nil {
		t.Fatal(err)
	}
	desc, err := makeTableDesc(stmt[0].(*parser.CreateTable))
	if err != nil {
		t.Fatal(err)
	}
	if err := desc.AllocateIDs(); err != structured.ErrMissingPrimaryKey {
		t.Fatal(err)
	}
}
开发者ID:ErikGrimes,项目名称:cockroach,代码行数:14,代码来源:table_test.go


示例11: exec

// Send forwards the call for further processing.
func (s *Server) exec(call sqlwire.Call) error {
	req := call.Args
	resp := call.Reply
	// Pick up current session state.
	var session Session
	if req.Session != nil {
		if err := gogoproto.Unmarshal(req.Session, &session); err != nil {
			return err
		}
	}
	stmt, err := parser.Parse(req.Sql)
	if err != nil {
		return err
	}
	switch p := stmt.(type) {
	case *parser.CreateDatabase:
		err = s.CreateDatabase(&session, p, req.Params, resp)
	case *parser.CreateTable:
		err = s.CreateTable(&session, p, req.Params, resp)
	case *parser.Delete:
		err = s.Delete(&session, p, req.Params, resp)
	case *parser.Insert:
		err = s.Insert(&session, p, req.Params, resp)
	case *parser.Select:
		err = s.Select(&session, p, req.Params, resp)
	case *parser.ShowColumns:
		err = s.ShowColumns(&session, p, req.Params, resp)
	case *parser.ShowDatabases:
		err = s.ShowDatabases(&session, p, req.Params, resp)
	case *parser.ShowIndex:
		err = s.ShowIndex(&session, p, req.Params, resp)
	case *parser.ShowTables:
		err = s.ShowTables(&session, p, req.Params, resp)
	case *parser.Update:
		err = s.Update(&session, p, req.Params, resp)
	case *parser.Use:
		s.Use(&session, p, req.Params, resp)
	default:
		err = fmt.Errorf("unknown statement type: %T", stmt)
	}
	if err != nil {
		return err
	}

	// Update session state.
	resp.Session, err = gogoproto.Marshal(&session)
	return err
}
开发者ID:backend2use,项目名称:cockroachdb,代码行数:49,代码来源:server.go


示例12: execStmts

// exec executes the request. Any error encountered is returned; it is
// the caller's responsibility to update the response.
func (s server) execStmts(sql string, params parameters, planMaker *planner) driver.Response {
	var resp driver.Response
	stmts, err := parser.Parse(sql, parser.Syntax(planMaker.session.Syntax))
	if err != nil {
		// A parse error occured: we can't determine if there were multiple
		// statements or only one, so just pretend there was one.
		resp.Results = append(resp.Results, rollbackTxnAndReturnResultWithError(planMaker, err))
		return resp
	}
	for _, stmt := range stmts {
		result, err := s.execStmt(stmt, params, planMaker)
		if err != nil {
			result = rollbackTxnAndReturnResultWithError(planMaker, err)
		}
		resp.Results = append(resp.Results, result)
	}
	return resp
}
开发者ID:slavau,项目名称:cockroach,代码行数:20,代码来源:server.go


示例13: TestPrimaryKeyUnspecified

func TestPrimaryKeyUnspecified(t *testing.T) {
	defer leaktest.AfterTest(t)
	stmt, err := parser.Parse("CREATE TABLE foo.test (a INT, b INT, CONSTRAINT c UNIQUE (b))")
	if err != nil {
		t.Fatal(err)
	}
	create := stmt[0].(*parser.CreateTable)
	if err := create.Table.NormalizeTableName(""); err != nil {
		t.Fatal(err)
	}
	desc, err := makeTableDesc(create)
	if err != nil {
		t.Fatal(err)
	}
	if err := desc.AllocateIDs(); err != ErrMissingPrimaryKey {
		t.Fatal(err)
	}
}
开发者ID:nkhuyu,项目名称:cockroach,代码行数:18,代码来源:table_test.go


示例14: TestMakeDatabaseDesc

func TestMakeDatabaseDesc(t *testing.T) {
	defer leaktest.AfterTest(t)

	stmt, err := parser.Parse("CREATE DATABASE test")
	if err != nil {
		t.Fatal(err)
	}
	desc := makeDatabaseDesc(stmt[0].(*parser.CreateDatabase))
	if desc.Name != "test" {
		t.Fatalf("expected Name == test, got %s", desc.Name)
	}
	// ID is not set yet.
	if desc.ID != 0 {
		t.Fatalf("expected ID == 0, got %d", desc.ID)
	}
	if len(desc.GetPrivileges().Users) != 1 {
		t.Fatalf("wrong number of privilege users, expected 1, got: %d", len(desc.GetPrivileges().Users))
	}
}
开发者ID:nkhuyu,项目名称:cockroach,代码行数:19,代码来源:database_test.go


示例15: init

func init() {
	const sql = `
CREATE TABLE system.namespace (
  "parentID" INT,
  "name"     CHAR,
  "id"       INT,
  PRIMARY KEY (parentID, name)
);

CREATE TABLE system.descriptor (
  "id"   INT PRIMARY KEY,
  "desc" BLOB
);
`
	stmts, err := parser.Parse(sql)
	if err != nil {
		log.Fatal(err)
	}

	NamespaceTable, err = makeTableDesc(stmts[0].(*parser.CreateTable))
	if err != nil {
		log.Fatal(err)
	}
	NamespaceTable.Privileges = SystemDB.Privileges
	NamespaceTable.ID = namespaceTableID
	if err := NamespaceTable.AllocateIDs(); err != nil {
		log.Fatal(err)
	}

	DescriptorTable, err = makeTableDesc(stmts[1].(*parser.CreateTable))
	if err != nil {
		log.Fatal(err)
	}
	DescriptorTable.Privileges = SystemDB.Privileges
	DescriptorTable.ID = descriptorTableID
	if err := DescriptorTable.AllocateIDs(); err != nil {
		log.Fatal(err)
	}
}
开发者ID:shitfSign,项目名称:cockroach,代码行数:39,代码来源:structured.go


示例16: TestMakeDatabaseDesc

func TestMakeDatabaseDesc(t *testing.T) {
	defer leaktest.AfterTest(t)

	stmt, err := parser.Parse("CREATE DATABASE test")
	if err != nil {
		t.Fatal(err)
	}
	desc := makeDatabaseDesc(stmt[0].(*parser.CreateDatabase))
	if desc.Name != "test" {
		t.Fatalf("expected Name == test, got %s", desc.Name)
	}
	// ID is not set yet.
	if desc.ID != 0 {
		t.Fatalf("expected ID == 0, got %d", desc.ID)
	}
	if len(desc.Read) != 1 || desc.Read[0] != security.RootUser {
		t.Fatalf("expected read == [root], got: %v", desc.Read)
	}
	if len(desc.Write) != 1 || desc.Write[0] != security.RootUser {
		t.Fatalf("expected write == [root], got: %v", desc.Write)
	}
}
开发者ID:routhcr,项目名称:cockroach,代码行数:22,代码来源:database_test.go


示例17: TestEvalExprError

func TestEvalExprError(t *testing.T) {
	testData := []struct {
		expr     string
		expected string
	}{
		{`'a' + 0`, `parsing \"a\": invalid syntax`},
		{`'0a' + 0`, `parsing \"0a\": invalid syntax`},
		{`a`, `column \"a\" not found`},
		// TODO(pmattis): Check for overflow.
		// {`~0 + 1`, `0`, nil},
	}
	for i, d := range testData {
		q, err := parser.Parse("SELECT " + d.expr)
		if err != nil {
			t.Fatalf("%d: %v: %s", i, err, d.expr)
		}
		expr := q.(*parser.Select).Exprs[0].(*parser.NonStarExpr).Expr
		if _, err := EvalExpr(expr, mapEnv{}); !testutils.IsError(err, d.expected) {
			t.Errorf("%d: expected %s, but found %v", i, d.expected, err)
		}
	}
}
开发者ID:Gardenya,项目名称:cockroach,代码行数:22,代码来源:expr_test.go


示例18: send

// Send forwards the call for further processing.
func (s *Server) send(call sqlwire.Call) {
	req := call.Args
	resp := call.Reply
	stmt, err := parser.Parse(req.Sql)
	if err != nil {
		echo(req.Sql, resp)
		return
	}
	switch p := stmt.(type) {
	case *parser.ShowColumns:
		s.ShowColumns(p, req.Params, resp)
	case *parser.ShowDatabases:
		s.ShowDatabases(p, req.Params, resp)
	case *parser.ShowIndex:
		s.ShowIndex(p, req.Params, resp)
	case *parser.ShowTables:
		s.ShowTables(p, req.Params, resp)
	case *parser.Use:
		s.Use(p, req.Params, resp)
	default:
		echo(req.Sql, resp)
	}
}
开发者ID:simonzhangsm,项目名称:cockroach,代码行数:24,代码来源:server.go


示例19: execStmts

// exec executes the request. Any error encountered is returned; it is
// the caller's responsibility to update the response.
func (e *Executor) execStmts(sql string, params parameters, planMaker *planner) driver.Response {
	var resp driver.Response
	stmts, err := parser.Parse(sql, parser.Syntax(planMaker.session.Syntax))
	if err != nil {
		// A parse error occurred: we can't determine if there were multiple
		// statements or only one, so just pretend there was one.
		resp.Results = append(resp.Results, makeResultFromError(planMaker, err))
		return resp
	}
	for _, stmt := range stmts {
		result, err := e.execStmt(stmt, params, planMaker)
		if err != nil {
			result = makeResultFromError(planMaker, err)
		}
		resp.Results = append(resp.Results, result)
		// TODO(pmattis): Is this the correct time to be releasing leases acquired
		// during execution of the statement?
		//
		// TODO(pmattis): Need to record the leases used by a transaction within
		// the transaction state and restore it when the transaction is restored.
		planMaker.releaseLeases(e.db)
	}
	return resp
}
开发者ID:jbowens,项目名称:cockroach,代码行数:26,代码来源:executor.go


示例20: TestEvalExpr


//.........这里部分代码省略.........
		{`4 / 5`, `0.8`, nil},
		// Grouping
		{`1 + 2 + (3 * 4)`, `15`, nil},
		// Unary operators.
		{`-3`, `-3`, nil},
		{`-4.1`, `-4.1`, nil},
		// Ones complement operates on unsigned integers.
		{`~0`, `18446744073709551615`, nil},
		{`~0.1`, `18446744073709551615`, nil},
		{`~0 - 1`, `18446744073709551614`, nil},
		// Hexadecimal numbers.
		{`0xa`, `10`, nil},
		// Octal numbers.
		{`0755`, `493`, nil},
		// String conversion
		{`'1' + '2'`, `3`, nil},
		// Strings convert to floats.
		{`'18446744073709551614' + 1`, `1.8446744073709552e+19`, nil},
		// String concatenation.
		{`'a' || 'b'`, `ab`, nil},
		{`'a' || (1 + 2)`, `a3`, nil},
		// Column lookup.
		{`a`, `1`, mapEnv{"a": dInt(1)}},
		{`a`, `2`, mapEnv{"a": dUint(2)}},
		{`a`, `3.1`, mapEnv{"a": dFloat(3.1)}},
		{`a`, `b`, mapEnv{"a": dBytes([]byte("b"))}},
		{`a`, `c`, mapEnv{"a": dString("c")}},
		{`a.b + 1`, `2`, mapEnv{"a.b": dInt(1)}},
		// Boolean expressions.
		{`false AND true`, `false`, nil},
		{`true AND true`, `true`, nil},
		{`true AND false`, `false`, nil},
		{`false AND false`, `false`, nil},
		{`false OR true`, `true`, nil},
		{`true OR true`, `true`, nil},
		{`true OR false`, `true`, nil},
		{`false OR false`, `false`, nil},
		{`NOT false`, `true`, nil},
		{`NOT true`, `false`, nil},
		// Boolean expressions short-circuit the evaluation.
		{`false AND (a = 1)`, `false`, nil},
		{`true OR (a = 1)`, `true`, nil},
		// Comparisons.
		{`0 = 1`, `false`, nil},
		{`0 != 1`, `true`, nil},
		{`0 < 1`, `true`, nil},
		{`0 <= 1`, `true`, nil},
		{`0 > 1`, `false`, nil},
		{`0 >= 1`, `false`, nil},
		{`true = false`, `false`, nil},
		{`true != false`, `true`, nil},
		{`true < false`, `false`, nil},
		{`true <= false`, `false`, nil},
		{`true > false`, `true`, nil},
		{`true >= false`, `true`, nil},
		{`true <=> false`, `false`, nil},
		{`'a' = 'b'`, `false`, nil},
		{`'a' != 'b'`, `true`, nil},
		{`'a' < 'b'`, `true`, nil},
		{`'a' <= 'b'`, `true`, nil},
		{`'a' > 'b'`, `false`, nil},
		{`'a' >= 'b'`, `false`, nil},
		{`'a' >= 'b'`, `false`, nil},
		// Comparison of a string against a number compares using floating point.
		{`'10' > '2'`, `false`, nil},
		{`'10' > 2`, `true`, nil},
		// Comparisons against NULL result in NULL, except for the null-safe equal.
		{`0 = NULL`, `NULL`, nil},
		{`NULL = NULL`, `NULL`, nil},
		{`NULL <=> NULL`, `true`, nil},
		// NULL checks.
		{`0 IS NULL`, `false`, nil},
		{`0 IS NOT NULL`, `true`, nil},
		{`NULL IS NULL`, `true`, nil},
		{`NULL IS NOT NULL`, `false`, nil},
		// Range conditions.
		{`2 BETWEEN 1 AND 3`, `true`, nil},
		{`1 NOT BETWEEN 2 AND 3`, `true`, nil},
		{`'foo' BETWEEN 'a' AND 'z'`, `true`, nil},
		// Case operator.
		{`CASE WHEN true THEN 1 END`, `1`, nil},
		{`CASE WHEN false THEN 1 END`, `NULL`, nil},
		{`CASE WHEN false THEN 1 ELSE 2 END`, `2`, nil},
		{`CASE WHEN false THEN 1 WHEN false THEN 2 END`, `NULL`, nil},
	}
	for i, d := range testData {
		q, err := parser.Parse("SELECT " + d.expr)
		if err != nil {
			t.Fatalf("%d: %v: %s", i, err, d.expr)
		}
		expr := q.(*parser.Select).Exprs[0].(*parser.NonStarExpr).Expr
		r, err := EvalExpr(expr, d.env)
		if err != nil {
			t.Fatalf("%d: %v", i, err)
		}
		if s := r.String(); d.expected != s {
			t.Errorf("%d: expected %s, but found %s: %s", i, d.expected, s, d.expr)
		}
	}
}
开发者ID:Gardenya,项目名称:cockroach,代码行数:101,代码来源:expr_test.go



注:本文中的github.com/cockroachdb/cockroach/sql/parser.Parse函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang parser.ParseExprTraditional函数代码示例发布时间:2022-05-23
下一篇:
Golang parser.NewTypedComparisonExpr函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap