本文整理汇总了Golang中github.com/cockroachdb/cockroach/sql/parser.Statement.String方法的典型用法代码示例。如果您正苦于以下问题:Golang Statement.String方法的具体用法?Golang Statement.String怎么用?Golang Statement.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cockroachdb/cockroach/sql/parser.Statement
的用法示例。
在下文中一共展示了Statement.String方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: query
func (c *conn) query(stmt parser.Statement, args []driver.Value) (*rows, error) {
// TODO(pmattis): Apply the args to the statement.
switch p := stmt.(type) {
case *parser.CreateDatabase:
return c.CreateDatabase(p, args)
case *parser.CreateTable:
return c.CreateTable(p, args)
case *parser.Delete:
return c.Delete(p, args)
case *parser.Insert:
return c.Insert(p, args)
case *parser.Select:
return c.Select(p, args)
case *parser.ShowColumns:
return c.Send(createCall(stmt.String(), args))
case *parser.ShowDatabases:
return c.Send(createCall(stmt.String(), args))
case *parser.ShowIndex:
return c.Send(createCall(stmt.String(), args))
case *parser.ShowTables:
return c.Send(createCall(stmt.String(), args))
case *parser.Update:
return c.Update(p, args)
case *parser.Use:
c.database = p.Name
return c.Send(createCall(stmt.String(), args))
case *parser.AlterTable:
case *parser.AlterView:
case *parser.CreateIndex:
case *parser.CreateView:
case *parser.DropDatabase:
case *parser.DropIndex:
case *parser.DropTable:
case *parser.DropView:
case *parser.RenameTable:
case *parser.Set:
case *parser.TruncateTable:
case *parser.Union:
// Various unimplemented statements.
default:
return nil, fmt.Errorf("unknown statement type: %T", stmt)
}
return nil, fmt.Errorf("TODO(pmattis): unimplemented: %T %s", stmt, stmt)
}