Skip to content
Browse files

Fixing to work with latest(as of 2011-11-14) go.

  • Loading branch information...
1 parent 0002d16 commit 3082ac247cce647765b911e54b67b217eda7efab @jgastal committed Nov 14, 2011
Showing with 111 additions and 120 deletions.
  1. +4 −4 convert.go
  2. +6 −6 error.go
  3. +15 −18 handler.go
  4. +33 −33 mysql.go
  5. +2 −2 mysql_test.go
  6. +24 −25 packet.go
  7. +3 −4 reader.go
  8. +2 −4 result.go
  9. +20 −21 statement.go
  10. +2 −3 writer.go
View
8 convert.go
@@ -6,8 +6,8 @@
package mysql
import (
+ "io"
"math"
- "os"
"strconv"
)
@@ -169,7 +169,7 @@ func f64tob(f float64) []byte {
}
// bytes to length
-func btolcb(b []byte) (num uint64, n int, err os.Error) {
+func btolcb(b []byte) (num uint64, n int, err error) {
switch {
// 0-250 = value of first byte
case b[0] <= 250:
@@ -193,7 +193,7 @@ func btolcb(b []byte) (num uint64, n int, err os.Error) {
}
// Check there are enough bytes
if len(b) < n {
- err = os.EOF
+ err = io.EOF
return
}
// Get uint64
@@ -248,7 +248,7 @@ func atof64(i interface{}) (f float64) {
case float64:
return t
case string:
- var err os.Error
+ var err error
f, err = strconv.Atof64(t)
if err != nil {
panic("Invalid string for floating point conversion")
View
12 error.go
@@ -115,21 +115,21 @@ const (
// Client error struct
type ClientError struct {
Errno Errno
- Error Error
+ Err Error
}
// Convert to string
-func (e *ClientError) String() string {
- return fmt.Sprintf("#%d %s", e.Errno, e.Error)
+func (e *ClientError) Error() string {
+ return fmt.Sprintf("#%d %s", e.Errno, e.Err)
}
// Server error struct
type ServerError struct {
Errno Errno
- Error Error
+ Err Error
}
// Convert to string
-func (e *ServerError) String() string {
- return fmt.Sprintf("#%d %s", e.Errno, e.Error)
+func (e *ServerError) Error() string {
+ return fmt.Sprintf("#%d %s", e.Errno, e.Err)
}
View
33 handler.go
@@ -5,13 +5,10 @@
// license that can be found in the LICENSE file.
package mysql
-import (
- "os"
- "strconv"
-)
+import "strconv"
// OK packet handler
-func handleOK(p *packetOK, c *Client, a, i *uint64, w *uint16) (err os.Error) {
+func handleOK(p *packetOK, c *Client, a, i *uint64, w *uint16) (err error) {
// Log OK result
c.log(1, "[%d] Received OK packet", p.sequence)
// Check sequence
@@ -32,7 +29,7 @@ func handleOK(p *packetOK, c *Client, a, i *uint64, w *uint16) (err os.Error) {
}
// Error packet handler
-func handleError(p *packetError, c *Client) (err os.Error) {
+func handleError(p *packetError, c *Client) (err error) {
// Log error result
c.log(1, "[%d] Received error packet", p.sequence)
// Check sequence
@@ -50,7 +47,7 @@ func handleError(p *packetError, c *Client) (err os.Error) {
}
// EOF packet handler
-func handleEOF(p *packetEOF, c *Client) (err os.Error) {
+func handleEOF(p *packetEOF, c *Client) (err error) {
// Log EOF result
c.log(1, "[%d] Received EOF packet", p.sequence)
// Check sequence
@@ -70,7 +67,7 @@ func handleEOF(p *packetEOF, c *Client) (err os.Error) {
}
// Result set packet handler
-func handleResultSet(p *packetResultSet, c *Client, r *Result) (err os.Error) {
+func handleResultSet(p *packetResultSet, c *Client, r *Result) (err error) {
// Log error result
c.log(1, "[%d] Received result set packet", p.sequence)
// Check sequence
@@ -84,7 +81,7 @@ func handleResultSet(p *packetResultSet, c *Client, r *Result) (err os.Error) {
}
// Field packet handler
-func handleField(p *packetField, c *Client, r *Result) (err os.Error) {
+func handleField(p *packetField, c *Client, r *Result) (err error) {
// Log field result
c.log(1, "[%d] Received field packet", p.sequence)
// Check sequence
@@ -110,7 +107,7 @@ func handleField(p *packetField, c *Client, r *Result) (err os.Error) {
}
// Row packet hander
-func handleRow(p *packetRowData, c *Client, r *Result) (err os.Error) {
+func handleRow(p *packetRowData, c *Client, r *Result) (err error) {
// Log field result
c.log(1, "[%d] Received row packet", p.sequence)
// Check sequence
@@ -128,7 +125,7 @@ func handleRow(p *packetRowData, c *Client, r *Result) (err os.Error) {
// Iterate fields to get types
for i, f := range r.fields {
// Check null
- if len(p.row[i].([]byte)) ==0 {
+ if len(p.row[i].([]byte)) == 0 {
field = nil
} else {
switch f.Type {
@@ -173,7 +170,7 @@ func handleRow(p *packetRowData, c *Client, r *Result) (err os.Error) {
}
// Prepare OK packet handler
-func handlePrepareOK(p *packetPrepareOK, c *Client, s *Statement) (err os.Error) {
+func handlePrepareOK(p *packetPrepareOK, c *Client, s *Statement) (err error) {
// Log result
c.log(1, "[%d] Received prepare OK packet", p.sequence)
// Check sequence
@@ -190,7 +187,7 @@ func handlePrepareOK(p *packetPrepareOK, c *Client, s *Statement) (err os.Error)
}
// Parameter packet handler
-func handleParam(p *packetParameter, c *Client) (err os.Error) {
+func handleParam(p *packetParameter, c *Client) (err error) {
// Log result
c.log(1, "[%d] Received parameter packet", p.sequence)
// Check sequence
@@ -203,7 +200,7 @@ func handleParam(p *packetParameter, c *Client) (err os.Error) {
}
// Binary row packet handler
-func handleBinaryRow(p *packetRowBinary, c *Client, r *Result) (err os.Error) {
+func handleBinaryRow(p *packetRowBinary, c *Client, r *Result) (err error) {
// Log binary row result
c.log(1, "[%d] Received binary row packet", p.sequence)
// Check sequence
@@ -278,15 +275,15 @@ func handleBinaryRow(p *packetRowBinary, c *Client, r *Result) (err os.Error) {
FIELD_TYPE_VAR_STRING, FIELD_TYPE_STRING, FIELD_TYPE_GEOMETRY:
num, n, err := btolcb(p.data[pos:])
if err != nil {
- return
+ return err
}
field = p.data[pos+uint64(n) : pos+uint64(n)+num]
pos += uint64(n) + num
// Date (From libmysql/libmysql.c read_binary_datetime)
case FIELD_TYPE_DATE:
num, n, err := btolcb(p.data[pos:])
if err != nil {
- return
+ return err
}
// New date
d := Date{}
@@ -308,7 +305,7 @@ func handleBinaryRow(p *packetRowBinary, c *Client, r *Result) (err os.Error) {
case FIELD_TYPE_TIME:
num, n, err := btolcb(p.data[pos:])
if err != nil {
- return
+ return err
}
// New time
t := Time{}
@@ -330,7 +327,7 @@ func handleBinaryRow(p *packetRowBinary, c *Client, r *Result) (err os.Error) {
case FIELD_TYPE_TIMESTAMP, FIELD_TYPE_DATETIME:
num, n, err := btolcb(p.data[pos:])
if err != nil {
- return
+ return err
}
// New datetime
d := DateTime{}
View
66 mysql.go
@@ -11,8 +11,8 @@ import (
"fmt"
"io"
"log"
- "os"
"net"
+ "os"
"strings"
"sync"
"time"
@@ -100,7 +100,7 @@ func NewClient(protocol ...uint8) (c *Client) {
}
// Connect to server via TCP
-func DialTCP(raddr, user, passwd string, dbname ...string) (c *Client, err os.Error) {
+func DialTCP(raddr, user, passwd string, dbname ...string) (c *Client, err error) {
c = NewClient(DEFAULT_PROTOCOL)
// Add port if not set
if strings.Index(raddr, ":") == -1 {
@@ -112,7 +112,7 @@ func DialTCP(raddr, user, passwd string, dbname ...string) (c *Client, err os.Er
}
// Connect to server via unix socket
-func DialUnix(raddr, user, passwd string, dbname ...string) (c *Client, err os.Error) {
+func DialUnix(raddr, user, passwd string, dbname ...string) (c *Client, err error) {
c = NewClient(DEFAULT_PROTOCOL)
// Use default socket if socket is empty
if raddr == "" {
@@ -124,7 +124,7 @@ func DialUnix(raddr, user, passwd string, dbname ...string) (c *Client, err os.E
}
// Connect to the server
-func (c *Client) Connect(network, raddr, user, passwd string, dbname ...string) (err os.Error) {
+func (c *Client) Connect(network, raddr, user, passwd string, dbname ...string) (err error) {
// Log connect
c.log(1, "=== Begin connect ===")
// Check not already connected
@@ -152,7 +152,7 @@ func (c *Client) Connect(network, raddr, user, passwd string, dbname ...string)
}
// Close connection to server
-func (c *Client) Close() (err os.Error) {
+func (c *Client) Close() (err error) {
// Log close
c.log(1, "=== Begin close ===")
// Check connection
@@ -173,7 +173,7 @@ func (c *Client) Close() (err os.Error) {
}
// Change the current database
-func (c *Client) ChangeDb(dbname string) (err os.Error) {
+func (c *Client) ChangeDb(dbname string) (err error) {
// Auto reconnect
defer func() {
if err != nil && c.checkNet(err) && c.Reconnect {
@@ -205,7 +205,7 @@ func (c *Client) ChangeDb(dbname string) (err os.Error) {
}
// Send a query/queries to the server
-func (c *Client) Query(sql string) (err os.Error) {
+func (c *Client) Query(sql string) (err error) {
// Auto reconnect
defer func() {
if err != nil && c.checkNet(err) && c.Reconnect {
@@ -242,7 +242,7 @@ func (c *Client) Query(sql string) (err os.Error) {
}
// Fetch all rows for a result and store it, returning the result set
-func (c *Client) StoreResult() (result *Result, err os.Error) {
+func (c *Client) StoreResult() (result *Result, err error) {
// Auto reconnect
defer func() {
err = c.simpleReconnect(err)
@@ -269,7 +269,7 @@ func (c *Client) StoreResult() (result *Result, err os.Error) {
}
// Use a result set, does not store rows
-func (c *Client) UseResult() (result *Result, err os.Error) {
+func (c *Client) UseResult() (result *Result, err error) {
// Auto reconnect
defer func() {
err = c.simpleReconnect(err)
@@ -290,7 +290,7 @@ func (c *Client) UseResult() (result *Result, err os.Error) {
}
// Free the current result
-func (c *Client) FreeResult() (err os.Error) {
+func (c *Client) FreeResult() (err error) {
// Auto reconnect
defer func() {
err = c.simpleReconnect(err)
@@ -329,7 +329,7 @@ func (c *Client) MoreResults() bool {
}
// Move to the next available result
-func (c *Client) NextResult() (more bool, err os.Error) {
+func (c *Client) NextResult() (more bool, err error) {
// Auto reconnect
defer func() {
err = c.simpleReconnect(err)
@@ -354,7 +354,7 @@ func (c *Client) NextResult() (more bool, err os.Error) {
}
// Set autocommit
-func (c *Client) SetAutoCommit(state bool) (err os.Error) {
+func (c *Client) SetAutoCommit(state bool) (err error) {
// Log set autocommit
c.log(1, "=== Begin set autocommit ===")
// Use set autocommit query
@@ -368,23 +368,23 @@ func (c *Client) SetAutoCommit(state bool) (err os.Error) {
}
// Start a transaction
-func (c *Client) Start() (err os.Error) {
+func (c *Client) Start() (err error) {
// Log start transaction
c.log(1, "=== Begin start transaction ===")
// Use start transaction query
return c.Query("start transaction")
}
// Commit a transaction
-func (c *Client) Commit() (err os.Error) {
+func (c *Client) Commit() (err error) {
// Log commit
c.log(1, "=== Begin commit ===")
// Use commit query
return c.Query("commit")
}
// Rollback a transaction
-func (c *Client) Rollback() (err os.Error) {
+func (c *Client) Rollback() (err error) {
// Log rollback
c.log(1, "=== Begin rollback ===")
// Use rollback query
@@ -412,7 +412,7 @@ func (c *Client) Escape(s string) (esc string) {
}
// Initialise a new statment
-func (c *Client) InitStmt() (stmt *Statement, err os.Error) {
+func (c *Client) InitStmt() (stmt *Statement, err error) {
// Check connection
if !c.checkConn() {
return nil, &ClientError{CR_COMMANDS_OUT_OF_SYNC, CR_COMMANDS_OUT_OF_SYNC_STR}
@@ -424,7 +424,7 @@ func (c *Client) InitStmt() (stmt *Statement, err os.Error) {
}
// Initialise and prepare a new statement
-func (c *Client) Prepare(sql string) (stmt *Statement, err os.Error) {
+func (c *Client) Prepare(sql string) (stmt *Statement, err error) {
// Initialise a new statement
stmt, err = c.InitStmt()
if err != nil {
@@ -530,7 +530,7 @@ func (c *Client) checkResult() bool {
}
// Check if a network error occurred
-func (c *Client) checkNet(err os.Error) bool {
+func (c *Client) checkNet(err error) bool {
if cErr, ok := err.(*ClientError); ok {
if cErr.Errno == CR_SERVER_GONE_ERROR || cErr.Errno == CR_SERVER_LOST {
return true
@@ -540,7 +540,7 @@ func (c *Client) checkNet(err os.Error) bool {
}
// Performs the actual connect
-func (c *Client) connect() (err os.Error) {
+func (c *Client) connect() (err error) {
// Connect to server
err = c.dial()
if err != nil {
@@ -582,7 +582,7 @@ func (c *Client) connect() (err os.Error) {
}
// Connect to server
-func (c *Client) dial() (err os.Error) {
+func (c *Client) dial() (err error) {
// Log connect
c.log(1, "Connecting to server via %s to %s", c.network, c.raddr)
// Connect to server
@@ -597,7 +597,7 @@ func (c *Client) dial() (err os.Error) {
}
// Log error
if cErr, ok := err.(*ClientError); ok {
- c.log(1, string(cErr.Error))
+ c.log(1, string(cErr.Err))
}
return
}
@@ -612,7 +612,7 @@ func (c *Client) dial() (err os.Error) {
}
// Read initial packet from server
-func (c *Client) init() (err os.Error) {
+func (c *Client) init() (err error) {
// Log read packet
c.log(1, "Reading handshake initialization packet from server")
// Read packet
@@ -653,7 +653,7 @@ func (c *Client) init() (err os.Error) {
}
// Send auth packet to the server
-func (c *Client) auth() (err os.Error) {
+func (c *Client) auth() (err error) {
// Log write packet
c.log(1, "Sending authentication packet to server")
// Construct packet
@@ -699,7 +699,7 @@ func (c *Client) auth() (err os.Error) {
}
// Simple non-recovered reconnect
-func (c *Client) simpleReconnect(err os.Error) os.Error {
+func (c *Client) simpleReconnect(err error) error {
if err != nil && c.checkNet(err) && c.Reconnect {
c.log(1, "!!! Lost connection to server !!!")
c.connected = false
@@ -712,7 +712,7 @@ func (c *Client) simpleReconnect(err os.Error) os.Error {
}
// Perform reconnect if a network error occurs
-func (c *Client) reconnect() (err os.Error) {
+func (c *Client) reconnect() (err error) {
// Log auto reconnect
c.log(1, "=== Begin auto reconnect attempt ===")
// Reset the client
@@ -730,7 +730,7 @@ func (c *Client) reconnect() (err os.Error) {
}
// Send a command to the server
-func (c *Client) command(command command, args ...interface{}) (err os.Error) {
+func (c *Client) command(command command, args ...interface{}) (err error) {
// Log write packet
c.log(1, "Sending command packet to server")
// Simple validation, arg count
@@ -783,7 +783,7 @@ func (c *Client) command(command command, args ...interface{}) (err os.Error) {
}
// Get field packets for a result
-func (c *Client) getFields() (err os.Error) {
+func (c *Client) getFields() (err error) {
// Check for a valid result
if c.result == nil {
return &ClientError{CR_NO_RESULT_SET, CR_NO_RESULT_SET_STR}
@@ -793,7 +793,7 @@ func (c *Client) getFields() (err os.Error) {
c.sequence++
eof, err := c.getResult(PACKET_FIELD | PACKET_EOF)
if err != nil {
- return
+ return err
}
if eof {
break
@@ -803,7 +803,7 @@ func (c *Client) getFields() (err os.Error) {
}
// Get next row for a result
-func (c *Client) getRow() (eof bool, err os.Error) {
+func (c *Client) getRow() (eof bool, err error) {
// Check for a valid result
if c.result == nil {
return false, &ClientError{CR_NO_RESULT_SET, CR_NO_RESULT_SET_STR}
@@ -815,11 +815,11 @@ func (c *Client) getRow() (eof bool, err os.Error) {
}
// Get all rows for the result
-func (c *Client) getAllRows() (err os.Error) {
+func (c *Client) getAllRows() (err error) {
for {
eof, err := c.getRow()
if err != nil {
- return
+ return err
}
if eof {
break
@@ -829,7 +829,7 @@ func (c *Client) getAllRows() (err os.Error) {
}
// Get result
-func (c *Client) getResult(types packetType) (eof bool, err os.Error) {
+func (c *Client) getResult(types packetType) (eof bool, err error) {
// Log read result
c.log(1, "Reading result packet from server")
// Get result packet
@@ -860,7 +860,7 @@ func (c *Client) getResult(types packetType) (eof bool, err os.Error) {
}
// Sequence check
-func (c *Client) checkSequence(sequence uint8) (err os.Error) {
+func (c *Client) checkSequence(sequence uint8) (err error) {
if sequence != c.sequence {
c.log(1, "Sequence doesn't match - expected %d but got %d, commands out of sync", c.sequence, sequence)
return &ClientError{CR_COMMANDS_OUT_OF_SYNC, CR_COMMANDS_OUT_OF_SYNC_STR}
View
4 mysql_test.go
@@ -7,8 +7,8 @@ package mysql
import (
"fmt"
+ "math/rand"
"os"
- "rand"
"strconv"
"sync"
"testing"
@@ -54,7 +54,7 @@ const (
var (
db *Client
- err os.Error
+ err error
checkOnce sync.Once
skipTests bool
)
View
49 packet.go
@@ -7,7 +7,7 @@ package mysql
import (
"bytes"
- "os"
+ "io"
)
// Packet type identifier
@@ -33,12 +33,12 @@ const (
// Readable packet interface
type packetReadable interface {
- read(data []byte) (err os.Error)
+ read(data []byte) (err error)
}
// Writable packet interface
type packetWritable interface {
- write() (data []byte, err os.Error)
+ write() (data []byte, err error)
}
// Generic packet interface (read/writable)
@@ -54,19 +54,19 @@ type packetBase struct {
}
// Read a slice from the data
-func (p *packetBase) readSlice(data []byte, delim byte) (slice []byte, err os.Error) {
+func (p *packetBase) readSlice(data []byte, delim byte) (slice []byte, err error) {
pos := bytes.IndexByte(data, delim)
if pos > -1 {
slice = data[:pos]
} else {
slice = data
- err = os.EOF
+ err = io.EOF
}
return
}
// Read length coded string
-func (p *packetBase) readLengthCodedString(data []byte) (s string, n int, err os.Error) {
+func (p *packetBase) readLengthCodedString(data []byte) (s string, n int, err error) {
// Read bytes and convert to string
b, n, err := p.readLengthCodedBytes(data)
if err != nil {
@@ -76,15 +76,15 @@ func (p *packetBase) readLengthCodedString(data []byte) (s string, n int, err os
return
}
-func (p *packetBase) readLengthCodedBytes(data []byte) (b []byte, n int, err os.Error) {
+func (p *packetBase) readLengthCodedBytes(data []byte) (b []byte, n int, err error) {
// Get string length
num, n, err := btolcb(data)
if err != nil {
return
}
// Check data length
if len(data) < n+int(num) {
- err = os.EOF
+ err = io.EOF
return
}
// Get bytes
@@ -101,7 +101,6 @@ func (p *packetBase) addHeader(data []byte) (pkt []byte) {
return
}
-
// Init packet
type packetInit struct {
packetBase
@@ -115,7 +114,7 @@ type packetInit struct {
}
// Init packet reader
-func (p *packetInit) read(data []byte) (err os.Error) {
+func (p *packetInit) read(data []byte) (err error) {
// Recover errors
defer func() {
if e := recover(); e != nil {
@@ -169,7 +168,7 @@ type packetAuth struct {
}
// Auth packet writer
-func (p *packetAuth) write() (data []byte, err os.Error) {
+func (p *packetAuth) write() (data []byte, err error) {
// Recover errors
defer func() {
if e := recover(); e != nil {
@@ -238,7 +237,7 @@ type packetOK struct {
}
// OK packet reader
-func (p *packetOK) read(data []byte) (err os.Error) {
+func (p *packetOK) read(data []byte) (err error) {
// Recover errors
defer func() {
if e := recover(); e != nil {
@@ -285,7 +284,7 @@ type packetError struct {
}
// Error packet reader
-func (p *packetError) read(data []byte) (err os.Error) {
+func (p *packetError) read(data []byte) (err error) {
// Recover errors
defer func() {
if e := recover(); e != nil {
@@ -318,7 +317,7 @@ type packetEOF struct {
}
// EOF packet reader
-func (p *packetEOF) read(data []byte) (err os.Error) {
+func (p *packetEOF) read(data []byte) (err error) {
// Recover errors
defer func() {
if e := recover(); e != nil {
@@ -347,7 +346,7 @@ type packetPassword struct {
}
// Password packet writer
-func (p *packetPassword) write() (data []byte, err os.Error) {
+func (p *packetPassword) write() (data []byte, err error) {
// Recover errors
defer func() {
if e := recover(); e != nil {
@@ -371,7 +370,7 @@ type packetCommand struct {
}
// Command packet writer
-func (p *packetCommand) write() (data []byte, err os.Error) {
+func (p *packetCommand) write() (data []byte, err error) {
// Recover errors
defer func() {
if e := recover(); e != nil {
@@ -450,7 +449,7 @@ type packetResultSet struct {
}
// Result set packet reader
-func (p *packetResultSet) read(data []byte) (err os.Error) {
+func (p *packetResultSet) read(data []byte) (err error) {
// Recover errors
defer func() {
if e := recover(); e != nil {
@@ -493,7 +492,7 @@ type packetField struct {
}
// Field packet reader
-func (p *packetField) read(data []byte) (err os.Error) {
+func (p *packetField) read(data []byte) (err error) {
// Recover errors
defer func() {
if e := recover(); e != nil {
@@ -599,7 +598,7 @@ type packetRowData struct {
}
// Row data packet reader
-func (p *packetRowData) read(data []byte) (err os.Error) {
+func (p *packetRowData) read(data []byte) (err error) {
// Recover errors
defer func() {
if e := recover(); e != nil {
@@ -613,7 +612,7 @@ func (p *packetRowData) read(data []byte) (err os.Error) {
// Read string
b, n, err := p.readLengthCodedBytes(data[pos:])
if err != nil {
- return
+ return err
}
// Add to slice
p.row = append(p.row, b)
@@ -636,7 +635,7 @@ type packetPrepareOK struct {
}
// Prepare ok packet reader
-func (p *packetPrepareOK) read(data []byte) (err os.Error) {
+func (p *packetPrepareOK) read(data []byte) (err error) {
// Recover errors
defer func() {
if e := recover(); e != nil {
@@ -669,7 +668,7 @@ type packetParameter struct {
}
// Parameter packet reader
-func (p *packetParameter) read(data []byte) (err os.Error) {
+func (p *packetParameter) read(data []byte) (err error) {
// Recover errors
defer func() {
if e := recover(); e != nil {
@@ -690,7 +689,7 @@ type packetLongData struct {
}
// Long data packet writer
-func (p *packetLongData) write() (data []byte, err os.Error) {
+func (p *packetLongData) write() (data []byte, err error) {
// Recover errors
defer func() {
if e := recover(); e != nil {
@@ -724,7 +723,7 @@ type packetExecute struct {
}
// Execute packet writer
-func (p *packetExecute) write() (data []byte, err os.Error) {
+func (p *packetExecute) write() (data []byte, err error) {
// Recover errors
defer func() {
if e := recover(); e != nil {
@@ -769,7 +768,7 @@ type packetRowBinary struct {
}
// Row binary packet reader
-func (p *packetRowBinary) read(data []byte) (err os.Error) {
+func (p *packetRowBinary) read(data []byte) (err error) {
// Recover errors
defer func() {
if e := recover(); e != nil {
View
7 reader.go
@@ -8,7 +8,6 @@ package mysql
import (
"io"
"net"
- "os"
)
// Packet reader struct
@@ -26,12 +25,12 @@ func newReader(conn io.ReadWriteCloser) *reader {
}
// Read the next packet
-func (r *reader) readPacket(types packetType) (p packetReadable, err os.Error) {
+func (r *reader) readPacket(types packetType) (p packetReadable, err error) {
// Deferred error processing
defer func() {
if err != nil {
// EOF errors
- if err == os.EOF || err == io.ErrUnexpectedEOF {
+ if err == io.EOF || err == io.ErrUnexpectedEOF {
err = &ClientError{CR_SERVER_LOST, CR_SERVER_LOST_STR}
}
// OpError
@@ -127,7 +126,7 @@ func (r *reader) readPacket(types packetType) (p packetReadable, err os.Error) {
}
// Read n bytes long number
-func (r *reader) readNumber(n uint8) (num uint64, err os.Error) {
+func (r *reader) readNumber(n uint8) (num uint64, err error) {
// Read bytes into array
buf := make([]byte, n)
nr, err := io.ReadFull(r.conn, buf)
View
6 result.go
@@ -5,8 +5,6 @@
// license that can be found in the LICENSE file.
package mysql
-import "os"
-
// Result struct
type Result struct {
// Pointer to the client
@@ -75,7 +73,7 @@ func (r *Result) RowCount() uint64 {
return 0
}
-func (r *Result) getRow() (eof bool, err os.Error) {
+func (r *Result) getRow() (eof bool, err error) {
if r.s != nil {
return r.s.getRow()
}
@@ -133,7 +131,7 @@ func (r *Result) FetchRows() []Row {
}
// Free the result
-func (r *Result) Free() (err os.Error) {
+func (r *Result) Free() (err error) {
if r.s != nil {
err = r.s.FreeResult()
} else {
View
41 statement.go
@@ -6,7 +6,6 @@
package mysql
import (
- "os"
"reflect"
"strconv"
)
@@ -42,7 +41,7 @@ type Statement struct {
}
// Prepare new statement
-func (s *Statement) Prepare(sql string) (err os.Error) {
+func (s *Statement) Prepare(sql string) (err error) {
// Auto reconnect
defer func() {
if err != nil && s.c.checkNet(err) && s.c.Reconnect {
@@ -79,7 +78,7 @@ func (s *Statement) Prepare(sql string) (err os.Error) {
s.c.sequence++
eof, err := s.getResult(PACKET_PARAM | PACKET_EOF)
if err != nil {
- return
+ return err
}
if eof {
break
@@ -105,7 +104,7 @@ func (s *Statement) ParamCount() uint16 {
}
// Bind params
-func (s *Statement) BindParams(params ...interface{}) (err os.Error) {
+func (s *Statement) BindParams(params ...interface{}) (err error) {
// Check prepared
if !s.prepared {
return &ClientError{CR_NO_PREPARE_STMT, CR_NO_PREPARE_STMT_STR}
@@ -208,7 +207,7 @@ func (s *Statement) BindParams(params ...interface{}) (err os.Error) {
}
// Send long data
-func (s *Statement) SendLongData(num int, data []byte) (err os.Error) {
+func (s *Statement) SendLongData(num int, data []byte) (err error) {
// Auto reconnect
defer func() {
err = s.c.simpleReconnect(err)
@@ -264,7 +263,7 @@ func (s *Statement) SendLongData(num int, data []byte) (err os.Error) {
}
// Execute
-func (s *Statement) Execute() (err os.Error) {
+func (s *Statement) Execute() (err error) {
// Auto reconnect
defer func() {
if err != nil && s.c.checkNet(err) && s.c.Reconnect {
@@ -362,7 +361,7 @@ func (s *Statement) FetchColumns() []*Field {
}
// Bind result
-func (s *Statement) BindResult(params ...interface{}) (err os.Error) {
+func (s *Statement) BindResult(params ...interface{}) (err error) {
s.resultParams = params
return
}
@@ -377,7 +376,7 @@ func (s *Statement) RowCount() uint64 {
}
// Fetch next row
-func (s *Statement) Fetch() (eof bool, err os.Error) {
+func (s *Statement) Fetch() (eof bool, err error) {
// Auto reconnect
defer func() {
err = s.c.simpleReconnect(err)
@@ -473,7 +472,7 @@ func (s *Statement) Fetch() (eof bool, err os.Error) {
}
// Use result
-func (s *Statement) UseResult() (*Result, os.Error) {
+func (s *Statement) UseResult() (*Result, error) {
// Log use result
s.c.log(1, "=== Begin use result ===")
// Check prepared
@@ -494,7 +493,7 @@ func (s *Statement) UseResult() (*Result, os.Error) {
}
// Store result
-func (s *Statement) StoreResult() (err os.Error) {
+func (s *Statement) StoreResult() (err error) {
// Auto reconnect
defer func() {
err = s.c.simpleReconnect(err)
@@ -521,7 +520,7 @@ func (s *Statement) StoreResult() (err os.Error) {
}
// Free result
-func (s *Statement) FreeResult() (err os.Error) {
+func (s *Statement) FreeResult() (err error) {
// Auto reconnect
defer func() {
err = s.c.simpleReconnect(err)
@@ -547,7 +546,7 @@ func (s *Statement) MoreResults() bool {
}
// Next result
-func (s *Statement) NextResult() (more bool, err os.Error) {
+func (s *Statement) NextResult() (more bool, err error) {
// Auto reconnect
defer func() {
err = s.c.simpleReconnect(err)
@@ -579,7 +578,7 @@ func (s *Statement) NextResult() (more bool, err os.Error) {
}
// Reset statement
-func (s *Statement) Reset() (err os.Error) {
+func (s *Statement) Reset() (err error) {
// Auto reconnect
defer func() {
err = s.c.simpleReconnect(err)
@@ -612,7 +611,7 @@ func (s *Statement) Reset() (err os.Error) {
}
// Close statement
-func (s *Statement) Close() (err os.Error) {
+func (s *Statement) Close() (err error) {
// Auto reconnect
defer func() {
err = s.c.simpleReconnect(err)
@@ -669,13 +668,13 @@ func (s *Statement) getNullBitMap() (nbm []byte) {
}
// Get all result fields
-func (s *Statement) getFields() (err os.Error) {
+func (s *Statement) getFields() (err error) {
// Loop till EOF
for {
s.c.sequence++
eof, err := s.getResult(PACKET_FIELD | PACKET_EOF)
if err != nil {
- return
+ return err
}
if eof {
break
@@ -685,7 +684,7 @@ func (s *Statement) getFields() (err os.Error) {
}
// Get next row for a result
-func (s *Statement) getRow() (eof bool, err os.Error) {
+func (s *Statement) getRow() (eof bool, err error) {
// Check for a valid result
if s.result == nil {
return false, &ClientError{CR_NO_RESULT_SET, CR_NO_RESULT_SET_STR}
@@ -697,11 +696,11 @@ func (s *Statement) getRow() (eof bool, err os.Error) {
}
// Get all rows for the result
-func (s *Statement) getAllRows() (err os.Error) {
+func (s *Statement) getAllRows() (err error) {
for {
eof, err := s.getRow()
if err != nil {
- return
+ return err
}
if eof {
break
@@ -711,7 +710,7 @@ func (s *Statement) getAllRows() (err os.Error) {
}
// Get result
-func (s *Statement) getResult(types packetType) (eof bool, err os.Error) {
+func (s *Statement) getResult(types packetType) (eof bool, err error) {
// Log read result
s.c.log(1, "Reading result packet from server")
// Get result packet
@@ -746,7 +745,7 @@ func (s *Statement) getResult(types packetType) (eof bool, err os.Error) {
}
// Free any result sets waiting to be read
-func (s *Statement) freeAll(next bool) (err os.Error) {
+func (s *Statement) freeAll(next bool) (err error) {
// Check for unread rows
if !s.result.allRead {
// Read all rows
View
5 writer.go
@@ -8,7 +8,6 @@ package mysql
import (
"io"
"net"
- "os"
)
// Packet writer struct
@@ -24,12 +23,12 @@ func newWriter(conn io.ReadWriteCloser) *writer {
}
// Write packet to the server
-func (w *writer) writePacket(p packetWritable) (err os.Error) {
+func (w *writer) writePacket(p packetWritable) (err error) {
// Deferred error processing
defer func() {
if err != nil {
// EOF errors
- if err == os.EOF || err == io.ErrUnexpectedEOF {
+ if err == io.EOF || err == io.ErrUnexpectedEOF {
err = &ClientError{CR_SERVER_LOST, CR_SERVER_LOST_STR}
}
// OpError

0 comments on commit 3082ac2

Please sign in to comment.
Something went wrong with that request. Please try again.