本文整理汇总了Golang中github.com/cockroachdb/cockroach/pkg/sql/parser.Statement.StatementTag方法的典型用法代码示例。如果您正苦于以下问题:Golang Statement.StatementTag方法的具体用法?Golang Statement.StatementTag怎么用?Golang Statement.StatementTag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cockroachdb/cockroach/pkg/sql/parser.Statement
的用法示例。
在下文中一共展示了Statement.StatementTag方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: execStmt
// The current transaction might have been committed/rolled back when this returns.
func (e *Executor) execStmt(
stmt parser.Statement, planMaker *planner, autoCommit bool,
) (Result, error) {
var result Result
plan, err := planMaker.makePlan(stmt, autoCommit)
if err != nil {
return result, err
}
defer plan.Close()
distSQLMode := testDistSQL
if planMaker.session.DistSQLMode != distSQLDisabled {
distSQLMode = planMaker.session.DistSQLMode
}
if distSQLMode != distSQLDisabled {
if err := hackPlanToUseDistSQL(plan, distSQLMode); err != nil {
return result, err
}
}
if err := plan.Start(); err != nil {
return result, err
}
result.PGTag = stmt.StatementTag()
result.Type = stmt.StatementType()
switch result.Type {
case parser.RowsAffected:
count, err := countRowsAffected(plan)
if err != nil {
return result, err
}
result.RowsAffected += count
case parser.Rows:
result.Columns = plan.Columns()
for _, c := range result.Columns {
if err := checkResultType(c.Typ); err != nil {
return result, err
}
}
result.Rows = NewRowContainer(planMaker.session.makeBoundAccount(), result.Columns, 0)
next, err := plan.Next()
for ; next; next, err = plan.Next() {
// The plan.Values DTuple needs to be copied on each iteration.
values := plan.Values()
for _, val := range values {
if err := checkResultType(val.ResolvedType()); err != nil {
return result, err
}
}
if _, err := result.Rows.AddRow(values); err != nil {
return result, err
}
}
if err != nil {
return result, err
}
}
return result, nil
}
示例2: execStmt
// The current transaction might have been committed/rolled back when this returns.
func (e *Executor) execStmt(
stmt parser.Statement, planMaker *planner, autoCommit bool,
) (Result, error) {
var result Result
plan, err := planMaker.makePlan(stmt, autoCommit)
if err != nil {
return result, err
}
defer plan.Close()
distSQLMode := testDistSQL
if planMaker.session.DistSQLMode != distSQLDisabled {
distSQLMode = planMaker.session.DistSQLMode
}
if distSQLMode != distSQLDisabled {
if err := hackPlanToUseDistSQL(plan, distSQLMode); err != nil {
return result, err
}
}
if err := plan.Start(); err != nil {
return result, err
}
result.PGTag = stmt.StatementTag()
result.Type = stmt.StatementType()
switch result.Type {
case parser.RowsAffected:
count, err := countRowsAffected(plan)
if err != nil {
return result, err
}
result.RowsAffected += count
case parser.Rows:
result.Columns = plan.Columns()
for _, c := range result.Columns {
if err := checkResultType(c.Typ); err != nil {
return result, err
}
}
result.Rows = planMaker.NewRowContainer(
planMaker.session.makeBoundAccount(),
result.Columns, 0)
// valuesAlloc is used to allocate the backing storage for the
// result row slices in chunks.
var valuesAlloc []parser.Datum
const maxChunkSize = 64 // Arbitrary, could use tuning.
chunkSize := 4 // Arbitrary as well.
next, err := plan.Next()
for ; next; next, err = plan.Next() {
// The plan.Values DTuple needs to be copied on each iteration.
values := plan.Values()
n := len(values)
if len(valuesAlloc) < n {
valuesAlloc = make(parser.DTuple, len(result.Columns)*chunkSize)
if chunkSize < maxChunkSize {
chunkSize *= 2
}
}
row := valuesAlloc[:0:n]
valuesAlloc = valuesAlloc[n:]
for _, val := range values {
if err := checkResultType(val.ResolvedType()); err != nil {
return result, err
}
row = append(row, val)
}
if err := result.Rows.AddRow(row); err != nil {
return result, err
}
}
if err != nil {
return result, err
}
}
return result, nil
}