當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。