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


Golang sqldb.NewSQLError函数代码示例

本文整理汇总了Golang中github.com/youtube/vitess/go/sqldb.NewSQLError函数的典型用法代码示例。如果您正苦于以下问题:Golang NewSQLError函数的具体用法?Golang NewSQLError怎么用?Golang NewSQLError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewSQLError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestTabletErrorRetriableErrorTypeOverwrite

func TestTabletErrorRetriableErrorTypeOverwrite(t *testing.T) {
	sqlErr := sqldb.NewSQLError(mysql.ErrOptionPreventsStatement, "HY000", "read-only")
	tabletErr := NewTabletErrorSQL(vtrpcpb.ErrorCode_INTERNAL_ERROR, sqlErr)
	if tabletErr.ErrorCode != vtrpcpb.ErrorCode_QUERY_NOT_SERVED {
		t.Fatalf("got: %v wanted: QUERY_NOT_SERVED", tabletErr.ErrorCode)
	}

	sqlErr = sqldb.NewSQLError(mysql.ErrDupEntry, "23000", "error")
	tabletErr = NewTabletErrorSQL(vtrpcpb.ErrorCode_INTERNAL_ERROR, sqlErr)
	if tabletErr.ErrorCode != vtrpcpb.ErrorCode_INTEGRITY_ERROR {
		t.Fatalf("got: %v wanted: INTEGRITY_ERROR", tabletErr.ErrorCode)
	}

	sqlErr = sqldb.NewSQLError(mysql.ErrDataTooLong, "22001", "error")
	tabletErr = NewTabletErrorSQL(vtrpcpb.ErrorCode_INTERNAL_ERROR, sqlErr)
	if tabletErr.ErrorCode != vtrpcpb.ErrorCode_BAD_INPUT {
		t.Fatalf("got: %v wanted: BAD_INPUT", tabletErr.ErrorCode)
	}

	sqlErr = sqldb.NewSQLError(mysql.ErrDataOutOfRange, "22003", "error")
	tabletErr = NewTabletErrorSQL(vtrpcpb.ErrorCode_INTERNAL_ERROR, sqlErr)
	if tabletErr.ErrorCode != vtrpcpb.ErrorCode_BAD_INPUT {
		t.Fatalf("got: %v wanted: BAD_INPUT", tabletErr.ErrorCode)
	}
}
开发者ID:dumbunny,项目名称:vitess,代码行数:25,代码来源:tablet_error_test.go

示例2: TestQueryExecutorPlanUpsertPk

func TestQueryExecutorPlanUpsertPk(t *testing.T) {
	db := setUpQueryExecutorTest()
	db.AddQuery("insert into test_table values (1) /* _stream test_table (pk ) (1 ); */", &mproto.QueryResult{})
	want := &mproto.QueryResult{
		Rows: make([][]sqltypes.Value, 0),
	}
	query := "insert into test_table values(1) on duplicate key update val=1"
	ctx := context.Background()
	tsv := newTestTabletServer(ctx, enableRowCache|enableStrict, db)
	qre := newTestQueryExecutor(ctx, tsv, query, 0)
	defer tsv.StopService()
	checkPlanID(t, planbuilder.PLAN_UPSERT_PK, qre.plan.PlanId)
	got, err := qre.Execute()
	if err != nil {
		t.Fatalf("qre.Execute() = %v, want nil", err)
	}
	if !reflect.DeepEqual(got, want) {
		t.Fatalf("got: %v, want: %v", got, want)
	}

	db.AddRejectedQuery("insert into test_table values (1) /* _stream test_table (pk ) (1 ); */", errRejected)
	_, err = qre.Execute()
	wantErr := "error: rejected"
	if err == nil || err.Error() != wantErr {
		t.Fatalf("qre.Execute() = %v, want %v", err, wantErr)
	}

	db.AddRejectedQuery(
		"insert into test_table values (1) /* _stream test_table (pk ) (1 ); */",
		sqldb.NewSQLError(mysql.ErrDupEntry, "err"),
	)
	db.AddQuery("update test_table set val = 1 where pk in (1) /* _stream test_table (pk ) (1 ); */", &mproto.QueryResult{})
	_, err = qre.Execute()
	wantErr = "error: err (errno 1062)"
	if err == nil || err.Error() != wantErr {
		t.Fatalf("qre.Execute() = %v, want %v", err, wantErr)
	}

	db.AddRejectedQuery(
		"insert into test_table values (1) /* _stream test_table (pk ) (1 ); */",
		sqldb.NewSQLError(mysql.ErrDupEntry, "ERROR 1062 (23000): Duplicate entry '2' for key 'PRIMARY'"),
	)
	db.AddQuery(
		"update test_table set val = 1 where pk in (1) /* _stream test_table (pk ) (1 ); */",
		&mproto.QueryResult{RowsAffected: 1},
	)
	got, err = qre.Execute()
	if err != nil {
		t.Fatalf("qre.Execute() = %v, want nil", err)
	}
	want = &mproto.QueryResult{
		RowsAffected: 2,
	}
	if !reflect.DeepEqual(got, want) {
		t.Fatalf("got: %v, want: %v", got, want)
	}
}
开发者ID:yab,项目名称:vitess,代码行数:57,代码来源:query_executor_test.go

示例3: ExecuteFetch

// ExecuteFetch executes the query on the connection
func (conn *Connection) ExecuteFetch(query string, maxrows int, wantfields bool) (qr *sqltypes.Result, err error) {
	if conn.IsClosed() {
		return nil, sqldb.NewSQLError(2006, "Connection is closed")
	}

	if C.vt_execute(&conn.c, (*C.char)(hack.StringPointer(query)), C.ulong(len(query)), 0) != 0 {
		return nil, conn.lastError(query)
	}
	defer conn.CloseResult()

	qr = &sqltypes.Result{}
	qr.RowsAffected = uint64(conn.c.affected_rows)
	qr.InsertID = uint64(conn.c.insert_id)
	if conn.c.num_fields == 0 {
		return qr, nil
	}

	if qr.RowsAffected > uint64(maxrows) {
		return nil, &sqldb.SQLError{
			Num:     0,
			Message: fmt.Sprintf("Row count exceeded %d", maxrows),
			Query:   string(query),
		}
	}
	if wantfields {
		qr.Fields = conn.Fields()
	}
	qr.Rows, err = conn.fetchAll()
	return qr, err
}
开发者ID:littleyang,项目名称:vitess,代码行数:31,代码来源:mysql.go

示例4: TestTabletErrorRetriableErrorTypeOverwrite

func TestTabletErrorRetriableErrorTypeOverwrite(t *testing.T) {
	sqlErr := sqldb.NewSQLError(mysql.ErrOptionPreventsStatement, "read-only")
	tabletErr := NewTabletErrorSQL(ErrFatal, vtrpc.ErrorCode_INTERNAL_ERROR, sqlErr)
	if tabletErr.ErrorType != ErrRetry || tabletErr.ErrorCode != vtrpc.ErrorCode_QUERY_NOT_SERVED {
		t.Fatalf("tablet error should have error type ErrRetry and error code %v", vtrpc.ErrorCode_QUERY_NOT_SERVED)
	}
}
开发者ID:richarwu,项目名称:vitess,代码行数:7,代码来源:tablet_error_test.go

示例5: TestTabletErrorRetriableErrorTypeOverwrite

func TestTabletErrorRetriableErrorTypeOverwrite(t *testing.T) {
	sqlErr := sqldb.NewSQLError(mysql.ErrOptionPreventsStatement, "HY000", "read-only")
	tabletErr := NewTabletErrorSQL(vtrpcpb.ErrorCode_INTERNAL_ERROR, sqlErr)
	if tabletErr.ErrorCode != vtrpcpb.ErrorCode_QUERY_NOT_SERVED {
		t.Fatalf("got: %v wanted: QUERY_NOT_SERVED", tabletErr.ErrorCode)
	}
}
开发者ID:CowLeo,项目名称:vitess,代码行数:7,代码来源:tablet_error_test.go

示例6: TestTabletErrorPrefix

func TestTabletErrorPrefix(t *testing.T) {
	tabletErr := NewTabletErrorSQL(ErrRetry, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSQLError(2000, "test"))
	if tabletErr.Prefix() != "retry: " {
		t.Fatalf("tablet error with error type: ErrRetry should has prefix: 'retry: '")
	}
	tabletErr = NewTabletErrorSQL(ErrFatal, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSQLError(2000, "test"))
	if tabletErr.Prefix() != "fatal: " {
		t.Fatalf("tablet error with error type: ErrFatal should has prefix: 'fatal: '")
	}
	tabletErr = NewTabletErrorSQL(ErrTxPoolFull, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSQLError(2000, "test"))
	if tabletErr.Prefix() != "tx_pool_full: " {
		t.Fatalf("tablet error with error type: ErrTxPoolFull should has prefix: 'tx_pool_full: '")
	}
	tabletErr = NewTabletErrorSQL(ErrNotInTx, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSQLError(2000, "test"))
	if tabletErr.Prefix() != "not_in_tx: " {
		t.Fatalf("tablet error with error type: ErrNotInTx should has prefix: 'not_in_tx: '")
	}
}
开发者ID:cgvarela,项目名称:vitess,代码行数:18,代码来源:tablet_error_test.go

示例7: TestTabletErrorPrefix

func TestTabletErrorPrefix(t *testing.T) {
	tabletErr := NewTabletErrorSQL(vtrpcpb.ErrorCode_QUERY_NOT_SERVED, sqldb.NewSQLError(2000, "HY000", "test"))
	if tabletErr.Prefix() != "retry: " {
		t.Fatalf("tablet error with error code: QUERY_NOT_SERVED should has prefix: 'retry: '")
	}
	tabletErr = NewTabletErrorSQL(vtrpcpb.ErrorCode_INTERNAL_ERROR, sqldb.NewSQLError(2000, "HY000", "test"))
	if tabletErr.Prefix() != "fatal: " {
		t.Fatalf("tablet error with error code: INTERNAL_ERROR should has prefix: 'fatal: '")
	}
	tabletErr = NewTabletErrorSQL(vtrpcpb.ErrorCode_RESOURCE_EXHAUSTED, sqldb.NewSQLError(2000, "HY000", "test"))
	if tabletErr.Prefix() != "tx_pool_full: " {
		t.Fatalf("tablet error with error code: RESOURCE_EXHAUSTED should has prefix: 'tx_pool_full: '")
	}
	tabletErr = NewTabletErrorSQL(vtrpcpb.ErrorCode_NOT_IN_TX, sqldb.NewSQLError(2000, "HY000", "test"))
	if tabletErr.Prefix() != "not_in_tx: " {
		t.Fatalf("tablet error with error code: NOT_IN_TX should has prefix: 'not_in_tx: '")
	}
}
开发者ID:dumbunny,项目名称:vitess,代码行数:18,代码来源:tablet_error_test.go

示例8: ExecuteStreamFetch

// ExecuteStreamFetch starts a streaming query to mysql. Use FetchNext
// on the Connection until it returns nil or error
func (conn *Connection) ExecuteStreamFetch(query string) (err error) {
	if conn.IsClosed() {
		return sqldb.NewSQLError(2006, "Connection is closed")
	}
	if C.vt_execute(&conn.c, (*C.char)(hack.StringPointer(query)), C.ulong(len(query)), 1) != 0 {
		return conn.lastError(query)
	}
	return nil
}
开发者ID:littleyang,项目名称:vitess,代码行数:11,代码来源:mysql.go

示例9: TestTabletErrorPrefix

func TestTabletErrorPrefix(t *testing.T) {
	tabletErr := NewTabletErrorSQL(ErrRetry, vtrpc.ErrorCode_QUERY_NOT_SERVED, sqldb.NewSQLError(2000, "test"))
	if tabletErr.Prefix() != "retry: " {
		t.Fatalf("tablet error with error type: ErrRetry should has prefix: 'retry: '")
	}
	tabletErr = NewTabletErrorSQL(ErrFatal, vtrpc.ErrorCode_INTERNAL_ERROR, sqldb.NewSQLError(2000, "test"))
	if tabletErr.Prefix() != "fatal: " {
		t.Fatalf("tablet error with error type: ErrFatal should has prefix: 'fatal: '")
	}
	tabletErr = NewTabletErrorSQL(ErrTxPoolFull, vtrpc.ErrorCode_RESOURCE_EXHAUSTED, sqldb.NewSQLError(2000, "test"))
	if tabletErr.Prefix() != "tx_pool_full: " {
		t.Fatalf("tablet error with error type: ErrTxPoolFull should has prefix: 'tx_pool_full: '")
	}
	tabletErr = NewTabletErrorSQL(ErrNotInTx, vtrpc.ErrorCode_NOT_IN_TX, sqldb.NewSQLError(2000, "test"))
	if tabletErr.Prefix() != "not_in_tx: " {
		t.Fatalf("tablet error with error type: ErrNotInTx should has prefix: 'not_in_tx: '")
	}
}
开发者ID:richarwu,项目名称:vitess,代码行数:18,代码来源:tablet_error_test.go

示例10: TestTabletErrorTxPoolFull

func TestTabletErrorTxPoolFull(t *testing.T) {
	tabletErr := NewTabletErrorSQL(ErrTxPoolFull, vtrpc.ErrorCode_RESOURCE_EXHAUSTED, sqldb.NewSQLError(1000, "test"))
	queryServiceStats := NewQueryServiceStats("", false)
	defer func() {
		err := recover()
		if err != nil {
			t.Fatalf("error should have been handled already")
		}
	}()
	defer logError(queryServiceStats)
	panic(tabletErr)
}
开发者ID:richarwu,项目名称:vitess,代码行数:12,代码来源:tablet_error_test.go

示例11: TestTabletErrorFatal

func TestTabletErrorFatal(t *testing.T) {
	tabletErr := NewTabletErrorSQL(ErrFatal, vtrpc.ErrorCode_INTERNAL_ERROR, sqldb.NewSQLError(1000, "test"))
	queryServiceStats := NewQueryServiceStats("", false)
	defer func() {
		err := recover()
		if err != nil {
			t.Fatalf("error should have been handled already")
		}
	}()
	defer logError(queryServiceStats)
	panic(tabletErr)
}
开发者ID:richarwu,项目名称:vitess,代码行数:12,代码来源:tablet_error_test.go

示例12: TestTabletErrorHandleRetryError

func TestTabletErrorHandleRetryError(t *testing.T) {
	var err error
	tabletErr := NewTabletErrorSQL(ErrRetry, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSQLError(1000, "test"))
	logStats := newSqlQueryStats("TestTabletErrorHandleError", context.Background())
	queryServiceStats := NewQueryServiceStats("", false)
	defer func() {
		_, ok := err.(*TabletError)
		if !ok {
			t.Fatalf("error should be a TabletError, but got error: %v", err)
		}
	}()
	defer handleError(&err, logStats, queryServiceStats)
	panic(tabletErr)
}
开发者ID:cgvarela,项目名称:vitess,代码行数:14,代码来源:tablet_error_test.go

示例13: TestTabletErrorHandleTxPoolFullError

func TestTabletErrorHandleTxPoolFullError(t *testing.T) {
	var err error
	tabletErr := NewTabletErrorSQL(ErrTxPoolFull, vtrpc.ErrorCode_RESOURCE_EXHAUSTED, sqldb.NewSQLError(1000, "test"))
	logStats := newLogStats("TestTabletErrorHandleError", context.Background())
	queryServiceStats := NewQueryServiceStats("", false)
	defer func() {
		_, ok := err.(*TabletError)
		if !ok {
			t.Fatalf("error should be a TabletError, but got error: %v", err)
		}
	}()
	defer handleError(&err, logStats, queryServiceStats)
	panic(tabletErr)
}
开发者ID:richarwu,项目名称:vitess,代码行数:14,代码来源:tablet_error_test.go

示例14: TestTabletErrorMsgTooLong

func TestTabletErrorMsgTooLong(t *testing.T) {
	buf := make([]byte, 2*maxErrLen)
	for i := 0; i < 2*maxErrLen; i++ {
		buf[i] = 'a'
	}
	msg := string(buf)
	sqlErr := sqldb.NewSQLError(mysql.ErrDupEntry, "23000", msg)
	tabletErr := NewTabletErrorSQL(vtrpcpb.ErrorCode_INTERNAL_ERROR, sqlErr)
	if tabletErr.ErrorCode != vtrpcpb.ErrorCode_INTEGRITY_ERROR {
		t.Fatalf("got %v wanted INTEGRITY_ERROR", tabletErr.ErrorCode)
	}
	if tabletErr.Message != string(buf[:maxErrLen]) {
		t.Fatalf("message should be capped, only %d character will be shown", maxErrLen)
	}
}
开发者ID:dumbunny,项目名称:vitess,代码行数:15,代码来源:tablet_error_test.go

示例15: TestTabletErrorConnError

func TestTabletErrorConnError(t *testing.T) {
	tabletErr := NewTabletErrorSQL(ErrFatal, vtrpc.ErrorCode_INTERNAL_ERROR, sqldb.NewSQLError(1999, "test"))
	if IsConnErr(tabletErr) {
		t.Fatalf("table error: %v is not a connection error", tabletErr)
	}
	tabletErr = NewTabletErrorSQL(ErrFatal, vtrpc.ErrorCode_INTERNAL_ERROR, sqldb.NewSQLError(2000, "test"))
	if !IsConnErr(tabletErr) {
		t.Fatalf("table error: %v is a connection error", tabletErr)
	}
	tabletErr = NewTabletErrorSQL(ErrFatal, vtrpc.ErrorCode_INTERNAL_ERROR, sqldb.NewSQLError(mysql.ErrServerLost, "test"))
	if IsConnErr(tabletErr) {
		t.Fatalf("table error: %v is not a connection error", tabletErr)
	}
	want := "fatal: the query was killed either because it timed out or was canceled: test (errno 2013)"
	if tabletErr.Error() != want {
		t.Fatalf("tablet error: %v, want %s", tabletErr, want)
	}
	sqlErr := sqldb.NewSQLError(1998, "test")
	if IsConnErr(sqlErr) {
		t.Fatalf("sql error: %v is not a connection error", sqlErr)
	}
	sqlErr = sqldb.NewSQLError(2001, "test")
	if !IsConnErr(sqlErr) {
		t.Fatalf("sql error: %v is a connection error", sqlErr)
	}

	err := fmt.Errorf("(errno 2005)")
	if !IsConnErr(err) {
		t.Fatalf("error: %v is a connection error", err)
	}

	err = fmt.Errorf("(errno 123456789012345678901234567890)")
	if IsConnErr(err) {
		t.Fatalf("error: %v is not a connection error", err)
	}
}
开发者ID:richarwu,项目名称:vitess,代码行数:36,代码来源:tablet_error_test.go


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