Add LOCK table support.
This commit is contained in:
parent
dd9b815dbb
commit
c9561ecc37
8 changed files with 142 additions and 116 deletions
|
|
@ -13,115 +13,12 @@ type Statement interface {
|
|||
Execute(db types.Db) (sql.Result, error)
|
||||
}
|
||||
|
||||
// LockStatement is used to take Read/Write lock on tables.
|
||||
// See http://dev.mysql.com/doc/refman/5.0/en/lock-tables.html
|
||||
//type LockStatement interface {
|
||||
// Statement
|
||||
//
|
||||
// AddReadLock(table *Table) LockStatement
|
||||
// AddWriteLock(table *Table) LockStatement
|
||||
//}
|
||||
|
||||
//// UnlockStatement can be used to release tableName locks taken using LockStatement.
|
||||
//// NOTE: You can not selectively release a lock and continue to hold lock on
|
||||
//// another tableName. UnlockStatement releases all the lock held in the current
|
||||
//// session.
|
||||
//type UnlockStatement interface {
|
||||
// Statement
|
||||
//}
|
||||
//
|
||||
//// SetGtidNextStatement returns a SQL statement that can be used to explicitly set the next GTID.
|
||||
//type GtidNextStatement interface {
|
||||
// Statement
|
||||
//}
|
||||
//
|
||||
////
|
||||
//// UNION SELECT Statement ======================================================
|
||||
////
|
||||
////
|
||||
//// LOCK statement ===========================================================
|
||||
////
|
||||
//
|
||||
//// NewLockStatement returns a SQL representing empty set of locks. You need to use
|
||||
//// AddReadLock/AddWriteLock to add tables that need to be locked.
|
||||
//// NOTE: You need at least one lock in the set for it to be a valid statement.
|
||||
//func NewLockStatement() LockStatement {
|
||||
// return &lockStatementImpl{}
|
||||
//}
|
||||
//
|
||||
//type lockStatementImpl struct {
|
||||
// locks []tableLock
|
||||
//}
|
||||
//
|
||||
//type tableLock struct {
|
||||
// t *Table
|
||||
// w bool
|
||||
//}
|
||||
//
|
||||
//func (l *lockStatementImpl) Execute(db *sql.DB, data interface{}) error {
|
||||
// return nil
|
||||
//}
|
||||
//
|
||||
//// AddReadLock takes read lock on the tableName.
|
||||
//func (s *lockStatementImpl) AddReadLock(t *Table) LockStatement {
|
||||
// s.locks = append(s.locks, tableLock{t: t, w: false})
|
||||
// return s
|
||||
//}
|
||||
//
|
||||
//// AddWriteLock takes write lock on the tableName.
|
||||
//func (s *lockStatementImpl) AddWriteLock(t *Table) LockStatement {
|
||||
// s.locks = append(s.locks, tableLock{t: t, w: true})
|
||||
// return s
|
||||
//}
|
||||
//
|
||||
//func (s *lockStatementImpl) String() (sql string, err error) {
|
||||
// if len(s.locks) == 0 {
|
||||
// return "", errors.New("No locks added")
|
||||
// }
|
||||
//
|
||||
// buf := new(bytes.Buffer)
|
||||
// _, _ = buf.WriteString("LOCK TABLES ")
|
||||
//
|
||||
// for idx, lock := range s.locks {
|
||||
// if lock.t == nil {
|
||||
// return "", errors.Newf("nil tableName.", buf.String())
|
||||
// }
|
||||
//
|
||||
// if err = lock.t.Serialize(buf); err != nil {
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// if lock.w {
|
||||
// _, _ = buf.WriteString(" WRITE")
|
||||
// } else {
|
||||
// _, _ = buf.WriteString(" READ")
|
||||
// }
|
||||
//
|
||||
// if idx != len(s.locks)-1 {
|
||||
// _, _ = buf.WriteString(", ")
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return buf.String(), nil
|
||||
//}
|
||||
//
|
||||
//// NewUnlockStatement returns SQL statement that can be used to release tableName locks
|
||||
//// grabbed by the current session.
|
||||
//func NewUnlockStatement() UnlockStatement {
|
||||
// return &unlockStatementImpl{}
|
||||
//}
|
||||
//
|
||||
//type unlockStatementImpl struct {
|
||||
//}
|
||||
//
|
||||
//func (u *unlockStatementImpl) Execute(db *sql.DB, data interface{}) error {
|
||||
// return nil
|
||||
//}
|
||||
//
|
||||
//func (s *unlockStatementImpl) String() (sql string, err error) {
|
||||
// return "UNLOCK TABLES", nil
|
||||
//}
|
||||
//
|
||||
|
||||
//// SET GTID_NEXT statement returns a SQL statement that can be used to explicitly set the next GTID.
|
||||
//func NewGtidNextStatement(sid []byte, gno uint64) GtidNextStatement {
|
||||
// return >idNextStatementImpl{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue