123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- package xugu
- import (
- "encoding/binary"
- "fmt"
- )
- type xuguResult struct {
- xgConn *xuguConn
- // Returns the number of rows affected
- // by update, delete and other related operations
- affectedRows int64
- // Returns the GUID number of
- // the insert operation (not supported)
- insertId int64
- }
- // LastInsertId returns the integer generated by the database
- // in response to a command. Typically this will be from an
- // "auto increment" column when inserting a new row. Not all
- // databases support this feature, and the syntax of such
- // statements varies.
- func (result *xuguResult) LastInsertId() (int64, error) {
- sockSendPutStatement(result.xgConn, []byte("select last_insert_id();"), nil, 0)
- sockSendExecute(result.xgConn)
- //接收结果
- //recv msg
- aR, err := xuguSockRecvMsg(result.xgConn)
- if err != nil {
- return 0, err
- }
- switch aR.rt {
- case selectResult:
- return int64(binary.BigEndian.Uint64(aR.s.Values[0][0].Col_Data)), nil
- }
- return 0, fmt.Errorf("last insert id error")
- }
- // RowsAffected returns the number of rows affected by an
- // update, insert, or delete. Not every database or database
- // driver may support this.
- func (result *xuguResult) RowsAffected() (int64, error) {
- return result.affectedRows, nil
- }
|