本文整理汇总了Golang中github.com/pingcap/tidb/parser.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: colDefStrToFieldType
func (s *testColumnSuite) colDefStrToFieldType(c *C, str string) *types.FieldType {
sqlA := "alter table t modify column a " + str
stmt, err := parser.New().ParseOneStmt(sqlA, "", "")
c.Assert(err, IsNil)
colDef := stmt.(*ast.AlterTableStmt).Specs[0].NewColumn
col, _, err := columnDefToCol(nil, 0, colDef)
c.Assert(err, IsNil)
return &col.FieldType
}
开发者ID:pingcap,项目名称:tidb,代码行数:9,代码来源:column_test.go
示例2: Parse
// Parse parses a query string to raw ast.StmtNode.
func Parse(ctx context.Context, src string) ([]ast.StmtNode, error) {
log.Debug("compiling", src)
charset, collation := getCtxCharsetInfo(ctx)
stmts, err := parser.New().Parse(src, charset, collation)
if err != nil {
log.Warnf("compiling %s, error: %v", src, err)
return nil, errors.Trace(err)
}
return stmts, nil
}
开发者ID:jmptrader,项目名称:tidb,代码行数:11,代码来源:tidb.go
示例3: CreateSession
// CreateSession creates a new session environment.
func CreateSession(store kv.Storage) (Session, error) {
s := &session{
values: make(map[fmt.Stringer]interface{}),
store: store,
sid: atomic.AddInt64(&sessionID, 1),
debugInfos: make(map[string]interface{}),
maxRetryCnt: 10,
parser: parser.New(),
}
domain, err := domap.Get(store)
if err != nil {
return nil, errors.Trace(err)
}
sessionctx.BindDomain(s, domain)
variable.BindSessionVars(s)
variable.GetSessionVars(s).SetStatusFlag(mysql.ServerStatusAutocommit, true)
// session implements variable.GlobalVarAccessor. Bind it to ctx.
variable.BindGlobalVarAccessor(s, s)
// session implements autocommit.Checker. Bind it to ctx
autocommit.BindAutocommitChecker(s, s)
sessionMu.Lock()
defer sessionMu.Unlock()
ver := getStoreBootstrapVersion(store)
if ver == notBootstrapped {
// if no bootstrap and storage is remote, we must use a little lease time to
// bootstrap quickly, after bootstrapped, we will reset the lease time.
// TODO: Using a bootstap tool for doing this may be better later.
if !localstore.IsLocalStore(store) {
sessionctx.GetDomain(s).SetLease(chooseMinLease(100*time.Millisecond, schemaLease))
}
s.SetValue(context.Initing, true)
bootstrap(s)
s.ClearValue(context.Initing)
if !localstore.IsLocalStore(store) {
sessionctx.GetDomain(s).SetLease(schemaLease)
}
finishBootstrap(store)
} else if ver < currentBootstrapVersion {
s.SetValue(context.Initing, true)
upgrade(s)
s.ClearValue(context.Initing)
}
// TODO: Add auth here
privChecker := &privileges.UserPrivileges{}
privilege.BindPrivilegeChecker(s, privChecker)
return s, nil
}
开发者ID:jmptrader,项目名称:tidb,代码行数:56,代码来源:session.go
示例4: TestDMLVistorCover
func (ts *testMiscSuite) TestDMLVistorCover(c *C) {
sql := `delete from somelog where user = 'jcole' order by timestamp_column limit 1;
delete t1, t2 from t1 inner join t2 inner join t3 where t1.id=t2.id and t2.id=t3.id;
select * from t where exists(select * from t k where t.c = k.c having sum(c) = 1);
insert into t_copy select * from t where t.x > 5;
(select a from t1 where a=10 and b=1) union (select a from t2 where a=11 and b=2) order by a limit 10;
update t1 set col1 = col1 + 1, col2 = col1;
show create table t;
load data infile '/tmp/t.csv' into table t fields terminated by 'ab' enclosed by 'b';`
parser := parser.New()
stmts, err := parser.Parse(sql, "", "")
c.Assert(err, IsNil)
for _, stmt := range stmts {
stmt.Accept(visitor{})
stmt.Accept(visitor1{})
}
}
开发者ID:jmptrader,项目名称:tidb,代码行数:18,代码来源:misc_test.go
示例5: SetUpSuite
func (s *testSuite) SetUpSuite(c *C) {
s.Parser = parser.New()
flag.Lookup("mockTikv")
useMockTikv := *mockTikv
if useMockTikv {
store, err := tikv.NewMockTikvStore()
c.Assert(err, IsNil)
s.store = store
tidb.SetSchemaLease(0)
} else {
store, err := tidb.NewStore("memory://test/test")
c.Assert(err, IsNil)
s.store = store
}
logLevel := os.Getenv("log_level")
log.SetLevelByString(logLevel)
executor.BaseLookupTableTaskSize = 2
}
开发者ID:jmptrader,项目名称:tidb,代码行数:18,代码来源:executor_test.go
示例6: bootstrapWithOnlyDDLWork
// Create a new session on store but only do ddl works.
func (s *testSessionSuite) bootstrapWithOnlyDDLWork(store kv.Storage, c *C) {
ss := &session{
values: make(map[fmt.Stringer]interface{}),
store: store,
parser: parser.New(),
sessionVars: variable.NewSessionVars(),
}
ss.SetValue(context.Initing, true)
domain, err := domap.Get(store)
c.Assert(err, IsNil)
sessionctx.BindDomain(ss, domain)
sessionMu.Lock()
defer sessionMu.Unlock()
b, err := checkBootstrapped(ss)
c.Assert(b, IsFalse)
c.Assert(err, IsNil)
doDDLWorks(ss)
// Leave dml unfinished.
}
开发者ID:pingcap,项目名称:tidb,代码行数:20,代码来源:bootstrap_test.go
示例7: createSession
func createSession(store kv.Storage) (*session, error) {
s := &session{
values: make(map[fmt.Stringer]interface{}),
store: store,
maxRetryCnt: 10,
parser: parser.New(),
sessionVars: variable.NewSessionVars(),
}
domain, err := domap.Get(store)
if err != nil {
return nil, errors.Trace(err)
}
sessionctx.BindDomain(s, domain)
// session implements variable.GlobalVarAccessor. Bind it to ctx.
s.sessionVars.GlobalVarsAccessor = s
// TODO: Add auth here
privChecker := &privileges.UserPrivileges{}
privilege.BindPrivilegeChecker(s, privChecker)
return s, nil
}
开发者ID:pingcap,项目名称:tidb,代码行数:21,代码来源:session.go
示例8: main
func main() {
p := parser.New()
stmt, err := p.ParseOneStmt(sql, "", "")
if err != nil {
fmt.Println(err)
}
fmt.Printf("%#v\n\n", stmt)
selectStmt := stmt.(*ast.SelectStmt)
fmt.Printf("selectStmt.From.TableRefs.Left is %#v\n", selectStmt.From.TableRefs.Left)
fmt.Printf("selectStmt.From.TableRefs.Right is %#v\n\n", selectStmt.From.TableRefs.Right)
tableSource := selectStmt.From.TableRefs.Left.(*ast.TableSource)
fmt.Printf("left tableSource.Source is %#v\n", tableSource.Source)
tableName := tableSource.Source.(*ast.TableName)
fmt.Printf("left tableName.Name.O is %#v\n", tableName.Name.O)
tableSource = selectStmt.From.TableRefs.Right.(*ast.TableSource)
fmt.Printf("right tableSource.Source is %#v\n", tableSource.Source)
tableName = tableSource.Source.(*ast.TableName)
fmt.Printf("right tableName.Name.O is %#v\n", tableName.Name.O)
}
开发者ID:cch123,项目名称:test,代码行数:21,代码来源:tableName.go
示例9: TestDDLVisitorCover
func (ts *testMiscSuite) TestDDLVisitorCover(c *C) {
sql := `
create table t (c1 smallint unsigned, c2 int unsigned);
alter table t add column a smallint unsigned after b;
create index t_i on t (id);
create database test character set utf8;
drop database test;
drop index t_i on t;
drop table t;
truncate t;
create table t (
jobAbbr char(4) not null,
constraint foreign key (jobabbr) references ffxi_jobtype (jobabbr) on delete cascade on update cascade
);
`
parser := parser.New()
stmts, err := parser.Parse(sql, "", "")
c.Assert(err, IsNil)
for _, stmt := range stmts {
stmt.Accept(visitor{})
stmt.Accept(visitor1{})
}
}
开发者ID:jmptrader,项目名称:tidb,代码行数:23,代码来源:misc_test.go
示例10: bootstrapWithOnlyDDLWork
// Create a new session on store but only do ddl works.
func (s *testSessionSuite) bootstrapWithOnlyDDLWork(store kv.Storage, c *C) {
ss := &session{
values: make(map[fmt.Stringer]interface{}),
store: store,
sid: atomic.AddInt64(&sessionID, 1),
parser: parser.New(),
}
ss.SetValue(context.Initing, true)
domain, err := domap.Get(store)
c.Assert(err, IsNil)
sessionctx.BindDomain(ss, domain)
variable.BindSessionVars(ss)
variable.GetSessionVars(ss).SetStatusFlag(mysql.ServerStatusAutocommit, true)
// session implements autocommit.Checker. Bind it to ctx
autocommit.BindAutocommitChecker(ss, ss)
sessionMu.Lock()
defer sessionMu.Unlock()
b, err := checkBootstrapped(ss)
c.Assert(b, IsFalse)
c.Assert(err, IsNil)
doDDLWorks(ss)
// Leave dml unfinished.
}
开发者ID:jmptrader,项目名称:tidb,代码行数:24,代码来源:bootstrap_test.go
示例11: SetUpSuite
func (s *testPlanSuite) SetUpSuite(c *C) {
s.Parser = parser.New()
}
开发者ID:yubobo,项目名称:tidb,代码行数:3,代码来源:plan_test.go
示例12: DoPrepare
// DoPrepare prepares the statement, it can be called multiple times without
// side effect.
func (e *PrepareExec) DoPrepare() {
vars := e.Ctx.GetSessionVars()
if e.ID != 0 {
// Must be the case when we retry a prepare.
// Make sure it is idempotent.
_, ok := vars.PreparedStmts[e.ID]
if ok {
return
}
}
charset, collation := vars.GetCharsetInfo()
var (
stmts []ast.StmtNode
err error
)
if sqlParser, ok := e.Ctx.(sqlexec.SQLParser); ok {
stmts, err = sqlParser.ParseSQL(e.SQLText, charset, collation)
} else {
stmts, err = parser.New().Parse(e.SQLText, charset, collation)
}
if err != nil {
e.Err = errors.Trace(err)
return
}
if len(stmts) != 1 {
e.Err = ErrPrepareMulti
return
}
stmt := stmts[0]
if _, ok := stmt.(ast.DDLNode); ok {
e.Err = ErrPrepareDDL
return
}
var extractor paramMarkerExtractor
stmt.Accept(&extractor)
// The parameter markers are appended in visiting order, which may not
// be the same as the position order in the query string. We need to
// sort it by position.
sorter := ¶mMarkerSorter{markers: extractor.markers}
sort.Sort(sorter)
e.ParamCount = len(sorter.markers)
prepared := &Prepared{
Stmt: stmt,
Params: sorter.markers,
SchemaVersion: e.IS.SchemaMetaVersion(),
}
err = plan.PrepareStmt(e.IS, e.Ctx, stmt)
if err != nil {
e.Err = errors.Trace(err)
return
}
if e.ID == 0 {
e.ID = vars.GetNextPreparedStmtID()
}
if e.Name != "" {
vars.PreparedStmtNameToID[e.Name] = e.ID
}
vars.PreparedStmts[e.ID] = prepared
}
开发者ID:pingcap,项目名称:tidb,代码行数:64,代码来源:prepared.go
示例13: SetUpSuite
func (s *testEvaluatorSuite) SetUpSuite(c *C) {
s.Parser = parser.New()
}
开发者ID:yangxuanjia,项目名称:tidb,代码行数:3,代码来源:evaluator_test.go
示例14: SetUpSuite
func (ts *testFlagSuite) SetUpSuite(c *C) {
ts.Parser = parser.New()
}
开发者ID:XuHuaiyu,项目名称:tidb,代码行数:3,代码来源:flag_test.go
示例15: SetUpSuite
func (s *testNameResolverSuite) SetUpSuite(c *C) {
s.Parser = parser.New()
}
开发者ID:pingcap,项目名称:tidb,代码行数:3,代码来源:resolver_test.go
示例16: SetUpSuite
func (s *testEvaluatorSuite) SetUpSuite(c *C) {
s.Parser = parser.New()
s.ctx = mock.NewContext()
}
开发者ID:pingcap,项目名称:tidb,代码行数:4,代码来源:evaluator_test.go
注:本文中的github.com/pingcap/tidb/parser.New函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论