mirror of https://github.com/go-gitea/gitea.git
Fix error log when loading issues caused by a xorm bug (#7271)
* fix error log when loading issues caused by a xorm bug * upgrade packages * fix fmt * fix Consistency * fix testspull/7298/head
parent
baefea311f
commit
aa7c34cf86
@ -0,0 +1,207 @@ |
||||
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
|
||||
//
|
||||
// Copyright 2012 The Go-MySQL-Driver Authors. All rights reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
// You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
// +build go1.8
|
||||
|
||||
package mysql |
||||
|
||||
import ( |
||||
"context" |
||||
"database/sql" |
||||
"database/sql/driver" |
||||
) |
||||
|
||||
// Ping implements driver.Pinger interface
|
||||
func (mc *mysqlConn) Ping(ctx context.Context) (err error) { |
||||
if mc.closed.IsSet() { |
||||
errLog.Print(ErrInvalidConn) |
||||
return driver.ErrBadConn |
||||
} |
||||
|
||||
if err = mc.watchCancel(ctx); err != nil { |
||||
return |
||||
} |
||||
defer mc.finish() |
||||
|
||||
if err = mc.writeCommandPacket(comPing); err != nil { |
||||
return |
||||
} |
||||
|
||||
return mc.readResultOK() |
||||
} |
||||
|
||||
// BeginTx implements driver.ConnBeginTx interface
|
||||
func (mc *mysqlConn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) { |
||||
if err := mc.watchCancel(ctx); err != nil { |
||||
return nil, err |
||||
} |
||||
defer mc.finish() |
||||
|
||||
if sql.IsolationLevel(opts.Isolation) != sql.LevelDefault { |
||||
level, err := mapIsolationLevel(opts.Isolation) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
err = mc.exec("SET TRANSACTION ISOLATION LEVEL " + level) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
} |
||||
|
||||
return mc.begin(opts.ReadOnly) |
||||
} |
||||
|
||||
func (mc *mysqlConn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) { |
||||
dargs, err := namedValueToValue(args) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
|
||||
if err := mc.watchCancel(ctx); err != nil { |
||||
return nil, err |
||||
} |
||||
|
||||
rows, err := mc.query(query, dargs) |
||||
if err != nil { |
||||
mc.finish() |
||||
return nil, err |
||||
} |
||||
rows.finish = mc.finish |
||||
return rows, err |
||||
} |
||||
|
||||
func (mc *mysqlConn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error) { |
||||
dargs, err := namedValueToValue(args) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
|
||||
if err := mc.watchCancel(ctx); err != nil { |
||||
return nil, err |
||||
} |
||||
defer mc.finish() |
||||
|
||||
return mc.Exec(query, dargs) |
||||
} |
||||
|
||||
func (mc *mysqlConn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) { |
||||
if err := mc.watchCancel(ctx); err != nil { |
||||
return nil, err |
||||
} |
||||
|
||||
stmt, err := mc.Prepare(query) |
||||
mc.finish() |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
|
||||
select { |
||||
default: |
||||
case <-ctx.Done(): |
||||
stmt.Close() |
||||
return nil, ctx.Err() |
||||
} |
||||
return stmt, nil |
||||
} |
||||
|
||||
func (stmt *mysqlStmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error) { |
||||
dargs, err := namedValueToValue(args) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
|
||||
if err := stmt.mc.watchCancel(ctx); err != nil { |
||||
return nil, err |
||||
} |
||||
|
||||
rows, err := stmt.query(dargs) |
||||
if err != nil { |
||||
stmt.mc.finish() |
||||
return nil, err |
||||
} |
||||
rows.finish = stmt.mc.finish |
||||
return rows, err |
||||
} |
||||
|
||||
func (stmt *mysqlStmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error) { |
||||
dargs, err := namedValueToValue(args) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
|
||||
if err := stmt.mc.watchCancel(ctx); err != nil { |
||||
return nil, err |
||||
} |
||||
defer stmt.mc.finish() |
||||
|
||||
return stmt.Exec(dargs) |
||||
} |
||||
|
||||
func (mc *mysqlConn) watchCancel(ctx context.Context) error { |
||||
if mc.watching { |
||||
// Reach here if canceled,
|
||||
// so the connection is already invalid
|
||||
mc.cleanup() |
||||
return nil |
||||
} |
||||
// When ctx is already cancelled, don't watch it.
|
||||
if err := ctx.Err(); err != nil { |
||||
return err |
||||
} |
||||
// When ctx is not cancellable, don't watch it.
|
||||
if ctx.Done() == nil { |
||||