當前位置: 首頁>>代碼示例>>Golang>>正文


Golang parser.NewLexer函數代碼示例

本文整理匯總了Golang中github.com/pingcap/tidb/parser.NewLexer函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewLexer函數的具體用法?Golang NewLexer怎麽用?Golang NewLexer使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewLexer函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestInfoBinder

func (ts *testInfoBinderSuite) TestInfoBinder(c *C) {
	store, err := tidb.NewStore(tidb.EngineGoLevelDBMemory)
	c.Assert(err, IsNil)
	defer store.Close()
	testKit := testkit.NewTestKit(c, store)
	testKit.MustExec("use test")
	testKit.MustExec("create table t (c1 int, c2 int)")
	domain := sessionctx.GetDomain(testKit.Se.(context.Context))

	src := "SELECT c1 from t"
	l := parser.NewLexer(src)
	c.Assert(parser.YYParse(l), Equals, 0)
	stmts := l.Stmts()
	c.Assert(len(stmts), Equals, 1)
	v := &optimizer.InfoBinder{
		Info:          domain.InfoSchema(),
		DefaultSchema: model.NewCIStr("test"),
	}
	selectStmt := stmts[0].(*ast.SelectStmt)
	selectStmt.Accept(v)

	verifier := &binderVerifier{
		c: c,
	}
	selectStmt.Accept(verifier)
}
開發者ID:yzl11,項目名稱:vessel,代碼行數:26,代碼來源:infobinder_test.go

示例2: statement

func statement(sql string) stmt.Statement {
	log.Debug("Compile", sql)
	lexer := parser.NewLexer(sql)
	parser.YYParse(lexer)
	compiler := &optimizer.Compiler{}
	stm, _ := compiler.Compile(lexer.Stmts()[0])
	return stm
}
開發者ID:henrylee2cn,項目名稱:tidb,代碼行數:8,代碼來源:ddl_test.go

示例3: Compile

// Compile is safe for concurrent use by multiple goroutines.
func Compile(src string) ([]stmt.Statement, error) {
	log.Debug("compiling", src)
	l := parser.NewLexer(src)
	if parser.YYParse(l) != 0 {
		log.Warnf("compiling %s, error: %v", src, l.Errors()[0])
		return nil, errors.Trace(l.Errors()[0])
	}

	return l.Stmts(), nil
}
開發者ID:awesomeleo,項目名稱:tidb,代碼行數:11,代碼來源:tidb.go

示例4: CompilePrepare

// CompilePrepare compiles prepared statement, allows placeholder as expr.
// The return values are compiled statement, parameter list and error.
func CompilePrepare(src string) (stmt.Statement, []*expressions.ParamMarker, error) {
	log.Debug("compiling prepared", src)
	l := parser.NewLexer(src)
	l.SetPrepare()
	if parser.YYParse(l) != 0 {
		log.Errorf("compiling %s\n, error: %v", src, l.Errors()[0])
		return nil, nil, errors.Trace(l.Errors()[0])
	}
	sms := l.Stmts()
	if len(sms) != 1 {
		log.Warnf("compiling %s, error: prepared statement should have only one statement.", src)
		return nil, nil, nil
	}
	sm := sms[0]
	return sm, l.ParamList, nil
}
開發者ID:awesomeleo,項目名稱:tidb,代碼行數:18,代碼來源:tidb.go

示例5: Compile

// Compile is safe for concurrent use by multiple goroutines.
func Compile(ctx context.Context, src string) ([]stmt.Statement, error) {
	log.Debug("compiling", src)
	l := parser.NewLexer(src)
	l.SetCharsetInfo(getCtxCharsetInfo(ctx))
	if parser.YYParse(l) != 0 {
		log.Warnf("compiling %s, error: %v", src, l.Errors()[0])
		return nil, errors.Trace(l.Errors()[0])
	}
	rawStmt := l.Stmts()
	stmts := make([]stmt.Statement, len(rawStmt))
	for i, v := range rawStmt {
		compiler := &optimizer.Compiler{}
		stm, err := compiler.Compile(v)
		if err != nil {
			return nil, errors.Trace(err)
		}
		stmts[i] = stm
	}
	return stmts, nil
}
開發者ID:henrylee2cn,項目名稱:tidb,代碼行數:21,代碼來源:tidb.go

示例6: CompilePrepare

// CompilePrepare compiles prepared statement, allows placeholder as expr.
// The return values are compiled statement, parameter list and error.
func CompilePrepare(ctx context.Context, src string) (stmt.Statement, []*expression.ParamMarker, error) {
	log.Debug("compiling prepared", src)
	l := parser.NewLexer(src)
	l.SetCharsetInfo(getCtxCharsetInfo(ctx))
	l.SetPrepare()
	if parser.YYParse(l) != 0 {
		log.Errorf("compiling %s\n, error: %v", src, l.Errors()[0])
		return nil, nil, errors.Trace(l.Errors()[0])
	}
	sms := l.Stmts()
	if len(sms) != 1 {
		log.Warnf("compiling %s, error: prepared statement should have only one statement.", src)
		return nil, nil, nil
	}
	sm := sms[0]
	compiler := &optimizer.Compiler{}
	statement, err := compiler.Compile(sm)
	if err != nil {
		return nil, nil, errors.Trace(err)
	}
	return statement, compiler.ParamMarkers(), nil
}
開發者ID:henrylee2cn,項目名稱:tidb,代碼行數:24,代碼來源:tidb.go

示例7: Compile

// Compile is safe for concurrent use by multiple goroutines.
func Compile(src string) ([]stmt.Statement, error) {
	log.Debug("compiling", src)
	l := parser.NewLexer(src)
	if parser.YYParse(l) != 0 {
		log.Warnf("compiling %s, error: %v", src, l.Errors()[0])
		return nil, errors.Trace(l.Errors()[0])
	}
	rawStmt := l.Stmts()
	stmts := make([]stmt.Statement, len(rawStmt))
	for i, v := range rawStmt {
		if node, ok := v.(ast.Node); ok {
			stm, err := optimizer.Compile(node)
			if err != nil {
				return nil, errors.Trace(err)
			}
			stmts[i] = stm
		} else {
			stmts[i] = v.(stmt.Statement)
		}
	}
	return stmts, nil
}
開發者ID:Brian110,項目名稱:tidb,代碼行數:23,代碼來源:tidb.go

示例8: statement

func statement(sql string) stmt.Statement {
	lexer := parser.NewLexer(sql)
	parser.YYParse(lexer)
	return lexer.Stmts()[0]
}
開發者ID:nengwang,項目名稱:tidb,代碼行數:5,代碼來源:ddl_test.go

示例9: statement

func statement(sql string) stmt.Statement {
	log.Debug("Compile", sql)
	lexer := parser.NewLexer(sql)
	parser.YYParse(lexer)
	return lexer.Stmts()[0]
}
開發者ID:Alienero,項目名稱:tidb,代碼行數:6,代碼來源:ddl_test.go


注:本文中的github.com/pingcap/tidb/parser.NewLexer函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。