当前位置: 首页>>代码示例>>Golang>>正文


Golang Statement.StatementTag方法代码示例

本文整理汇总了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
}
开发者ID:hvaara,项目名称:cockroach,代码行数:66,代码来源:executor.go

示例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
}
开发者ID:knz,项目名称:cockroach,代码行数:85,代码来源:executor.go


注:本文中的github.com/cockroachdb/cockroach/pkg/sql/parser.Statement.StatementTag方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。