本文整理匯總了Golang中github.com/cockroachdb/cockroach/sql/driver.Response_Result_Rows_Row.Values方法的典型用法代碼示例。如果您正苦於以下問題:Golang Response_Result_Rows_Row.Values方法的具體用法?Golang Response_Result_Rows_Row.Values怎麽用?Golang Response_Result_Rows_Row.Values使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cockroachdb/cockroach/sql/driver.Response_Result_Rows_Row
的用法示例。
在下文中一共展示了Response_Result_Rows_Row.Values方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: protoFromRow
func protoFromRow(r ResultRow) driver.Response_Result_Rows_Row {
rr := driver.Response_Result_Rows_Row{
Values: make([]driver.Datum, 0, len(r.Values)),
}
for _, v := range r.Values {
rr.Values = append(rr.Values, protoFromDatum(v))
}
return rr
}
示例2: execStmt
func (e *Executor) execStmt(stmt parser.Statement, planMaker *planner) (driver.Response_Result, error) {
var result driver.Response_Result
switch stmt.(type) {
case *parser.BeginTransaction:
if planMaker.txn != nil {
return result, errTransactionInProgress
}
// Start a transaction here and not in planMaker to prevent begin
// transaction from being called within an auto-transaction below.
planMaker.setTxn(client.NewTxn(e.db), time.Now())
planMaker.txn.SetDebugName("sql", 0)
case *parser.CommitTransaction, *parser.RollbackTransaction:
if planMaker.txn == nil {
return result, errNoTransactionInProgress
} else if planMaker.txn.Proto.Status == roachpb.ABORTED {
// Reset to allow starting a new transaction.
planMaker.resetTxn()
return result, nil
}
case *parser.SetTransaction:
if planMaker.txn == nil {
return result, errNoTransactionInProgress
}
default:
if planMaker.txn != nil && planMaker.txn.Proto.Status == roachpb.ABORTED {
return result, errTransactionAborted
}
}
// Bind all the placeholder variables in the stmt to actual values.
if err := parser.FillArgs(stmt, &planMaker.params); err != nil {
return result, err
}
// Create a function which both makes and executes the plan, populating
// result.
//
// TODO(pmattis): Should this be a separate function? Perhaps we should move
// some of the common code back out into execStmts and have execStmt contain
// only the body of this closure.
f := func(timestamp time.Time) error {
planMaker.evalCtx.StmtTimestamp = parser.DTimestamp{Time: timestamp}
plan, err := planMaker.makePlan(stmt)
if err != nil {
return err
}
switch stmt.StatementType() {
case parser.DDL:
result.Union = &driver.Response_Result_DDL_{DDL: &driver.Response_Result_DDL{}}
case parser.RowsAffected:
resultRowsAffected := driver.Response_Result_RowsAffected{}
result.Union = &resultRowsAffected
for plan.Next() {
resultRowsAffected.RowsAffected++
}
case parser.Rows:
var resultRows driver.Response_Result_Rows
for _, column := range plan.Columns() {
datum, err := makeDriverDatum(column.typ)
if err != nil {
return err
}
resultRows.Columns = append(resultRows.Columns, &driver.Response_Result_Rows_Column{
Name: column.name,
Typ: datum,
})
}
result.Union = &driver.Response_Result_Rows_{
Rows: &resultRows,
}
for plan.Next() {
values := plan.Values()
row := driver.Response_Result_Rows_Row{Values: make([]driver.Datum, 0, len(values))}
for _, val := range values {
datum, err := makeDriverDatum(val)
if err != nil {
return err
}
row.Values = append(row.Values, datum)
}
resultRows.Rows = append(resultRows.Rows, row)
}
}
return plan.Err()
}
// If there is a pending transaction.
if planMaker.txn != nil {
err := f(time.Now())
return result, err
}
if testingWaitForMetadata {
// We might need to verify metadata. Lock the system config so that
// no gossip updates sneak in under us.
//.........這裏部分代碼省略.........
示例3: execStmt
func (e *Executor) execStmt(stmt parser.Statement, params parameters, planMaker *planner) (driver.Response_Result, error) {
var result driver.Response_Result
switch stmt.(type) {
case *parser.BeginTransaction:
if planMaker.txn != nil {
return result, errTransactionInProgress
}
// Start a transaction here and not in planMaker to prevent begin
// transaction from being called within an auto-transaction below.
planMaker.setTxn(client.NewTxn(e.db), time.Now())
planMaker.txn.SetDebugName("sql", 0)
case *parser.CommitTransaction, *parser.RollbackTransaction:
if planMaker.txn == nil {
return result, errNoTransactionInProgress
} else if planMaker.txn.Proto.Status == roachpb.ABORTED {
// Reset to allow starting a new transaction.
planMaker.resetTxn()
return result, nil
}
case *parser.SetTransaction:
if planMaker.txn == nil {
return result, errNoTransactionInProgress
}
default:
if planMaker.txn != nil && planMaker.txn.Proto.Status == roachpb.ABORTED {
return result, errTransactionAborted
}
}
// Bind all the placeholder variables in the stmt to actual values.
if err := parser.FillArgs(stmt, params); err != nil {
return result, err
}
// Create a function which both makes and executes the plan, populating
// result.
//
// TODO(pmattis): Should this be a separate function? Perhaps we should move
// some of the common code back out into execStmts and have execStmt contain
// only the body of this closure.
f := func(timestamp time.Time) error {
planMaker.evalCtx.StmtTimestamp = parser.DTimestamp{Time: timestamp}
plan, err := planMaker.makePlan(stmt)
if err != nil {
return err
}
switch stmt.StatementType() {
case parser.DDL:
result.Union = &driver.Response_Result_DDL_{DDL: &driver.Response_Result_DDL{}}
case parser.RowsAffected:
resultRowsAffected := driver.Response_Result_RowsAffected{}
result.Union = &resultRowsAffected
for plan.Next() {
resultRowsAffected.RowsAffected++
}
case parser.Rows:
resultRows := &driver.Response_Result_Rows{
Columns: plan.Columns(),
}
result.Union = &driver.Response_Result_Rows_{
Rows: resultRows,
}
for plan.Next() {
values := plan.Values()
row := driver.Response_Result_Rows_Row{Values: make([]driver.Datum, 0, len(values))}
for _, val := range values {
if val == parser.DNull {
row.Values = append(row.Values, driver.Datum{})
continue
}
switch vt := val.(type) {
case parser.DBool:
row.Values = append(row.Values, driver.Datum{
Payload: &driver.Datum_BoolVal{BoolVal: bool(vt)},
})
case parser.DInt:
row.Values = append(row.Values, driver.Datum{
Payload: &driver.Datum_IntVal{IntVal: int64(vt)},
})
case parser.DFloat:
row.Values = append(row.Values, driver.Datum{
Payload: &driver.Datum_FloatVal{FloatVal: float64(vt)},
})
case parser.DBytes:
row.Values = append(row.Values, driver.Datum{
Payload: &driver.Datum_BytesVal{BytesVal: []byte(vt)},
})
case parser.DString:
row.Values = append(row.Values, driver.Datum{
Payload: &driver.Datum_StringVal{StringVal: string(vt)},
})
case parser.DDate:
row.Values = append(row.Values, driver.Datum{
Payload: &driver.Datum_DateVal{DateVal: int64(vt)},
})
case parser.DTimestamp:
//.........這裏部分代碼省略.........