github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/pingcap/tidb/server/driver.go (about) 1 // Copyright 2015 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package server 15 16 import "github.com/insionng/yougam/libraries/pingcap/tidb/util/types" 17 18 // IDriver opens IContext. 19 type IDriver interface { 20 // OpenCtx opens an IContext with connection id, client capability, collation and dbname. 21 OpenCtx(connID uint64, capability uint32, collation uint8, dbname string) (IContext, error) 22 } 23 24 // IContext is the interface to execute commant. 25 type IContext interface { 26 // Status returns server status code. 27 Status() uint16 28 29 // LastInsertID returns last inserted ID. 30 LastInsertID() uint64 31 32 // AffectedRows returns affected rows of last executed command. 33 AffectedRows() uint64 34 35 // WarningCount returns warning count of last executed command. 36 WarningCount() uint16 37 38 // CurrentDB returns current DB. 39 CurrentDB() string 40 41 // Execute executes a SQL statement. 42 Execute(sql string) (ResultSet, error) 43 44 // Prepare prepares a statement. 45 Prepare(sql string) (statement IStatement, columns, params []*ColumnInfo, err error) 46 47 // GetStatement gets IStatement by statement ID. 48 GetStatement(stmtID int) IStatement 49 50 // FieldList returns columns of a table. 51 FieldList(tableName string) (columns []*ColumnInfo, err error) 52 53 // Close closes the IContext. 54 Close() error 55 56 // Auth verifies user's authentication. 57 Auth(user string, auth []byte, salt []byte) bool 58 } 59 60 // IStatement is the interface to use a prepared statement. 61 type IStatement interface { 62 // ID returns statement ID 63 ID() int 64 65 // Execute executes the statement. 66 Execute(args ...interface{}) (ResultSet, error) 67 68 // AppendParam appends parameter to the statement. 69 AppendParam(paramID int, data []byte) error 70 71 // NumParams returns number of parameters. 72 NumParams() int 73 74 // BoundParams returns bound parameters. 75 BoundParams() [][]byte 76 77 // Reset removes all bound parameters. 78 Reset() 79 80 // Close closes the statement. 81 Close() error 82 } 83 84 // ResultSet is the result set of an query. 85 type ResultSet interface { 86 Columns() ([]*ColumnInfo, error) 87 Next() ([]types.Datum, error) 88 Close() error 89 }