当前位置: 首页>>代码示例>>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;未经允许,请勿转载。