本文整理汇总了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)
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例8: statement
func statement(sql string) stmt.Statement {
lexer := parser.NewLexer(sql)
parser.YYParse(lexer)
return lexer.Stmts()[0]
}
示例9: statement
func statement(sql string) stmt.Statement {
log.Debug("Compile", sql)
lexer := parser.NewLexer(sql)
parser.YYParse(lexer)
return lexer.Stmts()[0]
}