Skip to content

adaptations to language evolutions #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
package mysql

import (
"io"
"math"
"os"
"strconv"
)

Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down
112 changes: 56 additions & 56 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,127 +9,127 @@ import "fmt"

// Client error types
type Errno int
type Error string
type Errstr string

const (
CR_UNKNOWN_ERROR Errno = 2000
CR_UNKNOWN_ERROR_STR Error = "Unknown MySQL error"
CR_UNKNOWN_ERROR_STR Errstr ="Unknown MySQL error"
CR_SOCKET_CREATE_ERROR Errno = 2001
CR_SOCKET_CREATE_ERROR_STR Error = "Can't create UNIX socket (%d)"
CR_SOCKET_CREATE_ERROR_STR Errstr ="Can't create UNIX socket (%d)"
CR_CONNECTION_ERROR Errno = 2002
CR_CONNECTION_ERROR_STR Error = "Can't connect to local MySQL server through socket '%s'"
CR_CONNECTION_ERROR_STR Errstr ="Can't connect to local MySQL server through socket '%s'"
CR_CONN_HOST_ERROR Errno = 2003
CR_CONN_HOST_ERROR_STR Error = "Can't connect to MySQL server on '%s'"
CR_CONN_HOST_ERROR_STR Errstr ="Can't connect to MySQL server on '%s'"
CR_IPSOCK_ERROR Errno = 2004
CR_IPSOCK_ERROR_STR Error = "Can't create TCP/IP socket (%d)"
CR_IPSOCK_ERROR_STR Errstr ="Can't create TCP/IP socket (%d)"
CR_UNKNOWN_HOST Errno = 2005
CR_UNKNOWN_HOST_STR Error = "Uknown MySQL server host '%s' (%d)"
CR_UNKNOWN_HOST_STR Errstr ="Uknown MySQL server host '%s' (%d)"
CR_SERVER_GONE_ERROR Errno = 2006
CR_SERVER_GONE_ERROR_STR Error = "MySQL server has gone away"
CR_SERVER_GONE_ERROR_STR Errstr ="MySQL server has gone away"
CR_VERSION_ERROR Errno = 2007
CR_VERSION_ERROR_STR Error = "Protocol mismatch; server version = %d, client version = %d"
CR_VERSION_ERROR_STR Errstr ="Protocol mismatch; server version = %d, client version = %d"
CR_OUT_OF_MEMORY Errno = 2008
CR_OUT_OF_MEMORY_STR Error = "MySQL client ran out of memory"
CR_OUT_OF_MEMORY_STR Errstr ="MySQL client ran out of memory"
CR_WRONG_HOST_INFO Errno = 2009
CR_WRONG_HOST_INFO_STR Error = "Wrong host info"
CR_WRONG_HOST_INFO_STR Errstr ="Wrong host info"
CR_LOCALHOST_CONNECTION Errno = 2010
CR_LOCALHOST_CONNECTION_STR Error = "Localhost via UNIX socket"
CR_LOCALHOST_CONNECTION_STR Errstr ="Localhost via UNIX socket"
CR_TCP_CONNECTION Errno = 2011
CR_TCP_CONNECTION_STR Error = "%s via TCP/IP"
CR_TCP_CONNECTION_STR Errstr ="%s via TCP/IP"
CR_SERVER_HANDSHAKE_ERR Errno = 2012
CR_SERVER_HANDSHAKE_ERR_STR Error = "Error in server handshake"
CR_SERVER_HANDSHAKE_ERR_STR Errstr ="Error in server handshake"
CR_SERVER_LOST Errno = 2013
CR_SERVER_LOST_STR Error = "Lost connection to MySQL server during query"
CR_SERVER_LOST_STR Errstr ="Lost connection to MySQL server during query"
CR_COMMANDS_OUT_OF_SYNC Errno = 2014
CR_COMMANDS_OUT_OF_SYNC_STR Error = "Commands out of sync; you can't run this command now"
CR_COMMANDS_OUT_OF_SYNC_STR Errstr ="Commands out of sync; you can't run this command now"
CR_NAMEDPIPE_CONNECTION Errno = 2015
CR_NAMEDPIPE_CONNECTION_STR Error = "Named pipe: %s"
CR_NAMEDPIPE_CONNECTION_STR Errstr ="Named pipe: %s"
CR_NAMEDPIPEWAIT_ERROR Errno = 2016
CR_NAMEDPIPEWAIT_ERROR_STR Error = "Can't wait for named pipe to host: %s pipe: %s (%lu)"
CR_NAMEDPIPEWAIT_ERROR_STR Errstr ="Can't wait for named pipe to host: %s pipe: %s (%lu)"
CR_NAMEDPIPEOPEN_ERROR Errno = 2017
CR_NAMEDPIPEOPEN_ERROR_STR Error = "Can't open named pipe to host: %s pipe: %s (%lu)"
CR_NAMEDPIPEOPEN_ERROR_STR Errstr ="Can't open named pipe to host: %s pipe: %s (%lu)"
CR_NAMEDPIPESETSTATE_ERROR Errno = 2018
CR_NAMEDPIPESETSTATE_ERROR_STR Error = "Can't set state of named pipe to host: %s pipe: %s (%lu)"
CR_NAMEDPIPESETSTATE_ERROR_STR Errstr ="Can't set state of named pipe to host: %s pipe: %s (%lu)"
CR_CANT_READ_CHARSET Errno = 2019
CR_CANT_READ_CHARSET_STR Error = "Can't initialize character set %s (path: %s)"
CR_CANT_READ_CHARSET_STR Errstr ="Can't initialize character set %s (path: %s)"
CR_NET_PACKET_TOO_LARGE Errno = 2020
CR_NET_PACKET_TOO_LARGE_STR Error = "Got packet bigger than 'max_allowed_packet' bytes"
CR_NET_PACKET_TOO_LARGE_STR Errstr ="Got packet bigger than 'max_allowed_packet' bytes"
CR_EMBEDDED_CONNECTION Errno = 2021
CR_EMBEDDED_CONNECTION_STR Error = "Embedded server"
CR_EMBEDDED_CONNECTION_STR Errstr ="Embedded server"
CR_PROBE_SLAVE_STATUS Errno = 2022
CR_PROBE_SLAVE_STATUS_STR Error = "Error on SHOW SLAVE STATUS:"
CR_PROBE_SLAVE_STATUS_STR Errstr ="Error on SHOW SLAVE STATUS:"
CR_PROBE_SLAVE_HOSTS Errno = 2023
CR_PROBE_SLAVE_HOSTS_STR Error = "Error on SHOW SLAVE HOSTS:"
CR_PROBE_SLAVE_HOSTS_STR Errstr ="Error on SHOW SLAVE HOSTS:"
CR_PROBE_SLAVE_CONNECT Errno = 2024
CR_PROBE_SLAVE_CONNECT_STR Error = "Error connecting to slave:"
CR_PROBE_SLAVE_CONNECT_STR Errstr ="Error connecting to slave:"
CR_PROBE_MASTER_CONNECT Errno = 2025
CR_PROBE_MASTER_CONNECT_STR Error = "Error connecting to master:"
CR_PROBE_MASTER_CONNECT_STR Errstr ="Error connecting to master:"
CR_SSL_CONNECTION_ERROR Errno = 2026
CR_SSL_CONNECTION_ERROR_STR Error = "SSL connection error"
CR_SSL_CONNECTION_ERROR_STR Errstr ="SSL connection error"
CR_MALFORMED_PACKET Errno = 2027
CR_MALFORMED_PACKET_STR Error = "Malformed Packet"
CR_MALFORMED_PACKET_STR Errstr ="Malformed Packet"
CR_WRONG_LICENSE Errno = 2028
CR_WRONG_LICENSE_STR Error = "This client library is licensed only for use with MySQL servers having '%s' license"
CR_WRONG_LICENSE_STR Errstr ="This client library is licensed only for use with MySQL servers having '%s' license"
CR_NULL_POINTER Errno = 2029
CR_NULL_POINTER_STR Error = "Invalid use of null pointer"
CR_NULL_POINTER_STR Errstr ="Invalid use of null pointer"
CR_NO_PREPARE_STMT Errno = 2030
CR_NO_PREPARE_STMT_STR Error = "Statement not prepared"
CR_NO_PREPARE_STMT_STR Errstr ="Statement not prepared"
CR_PARAMS_NOT_BOUND Errno = 2031
CR_PARAMS_NOT_BOUND_STR Error = "No data supplied for parameters in prepared statement"
CR_PARAMS_NOT_BOUND_STR Errstr ="No data supplied for parameters in prepared statement"
CR_DATA_TRUNCATED Errno = 2032
CR_DATA_TRUNCATED_STR Error = "Data truncated"
CR_DATA_TRUNCATED_STR Errstr ="Data truncated"
CR_NO_PARAMETERS_EXISTS Errno = 2033
CR_NO_PARAMETERS_EXISTS_STR Error = "No parameters exist in the statement"
CR_NO_PARAMETERS_EXISTS_STR Errstr ="No parameters exist in the statement"
CR_INVALID_PARAMETER_NO Errno = 2034
CR_INVALID_PARAMETER_NO_STR Error = "Invalid parameter number"
CR_INVALID_PARAMETER_NO_STR Errstr ="Invalid parameter number"
CR_INVALID_BUFFER_USE Errno = 2035
CR_INVALID_BUFFER_USE_STR Error = "Can't send long data for non-string/non-binary data types (parameter: %d)"
CR_INVALID_BUFFER_USE_STR Errstr ="Can't send long data for non-string/non-binary data types (parameter: %d)"
CR_UNSUPPORTED_PARAM_TYPE Errno = 2036
CR_UNSUPPORTED_PARAM_TYPE_STR Error = "Using unsupported parameter type: %s (parameter: %d)"
CR_UNSUPPORTED_PARAM_TYPE_STR Errstr ="Using unsupported parameter type: %s (parameter: %d)"
CR_CONN_UNKNOW_PROTOCOL Errno = 2047
CR_CONN_UNKNOW_PROTOCOL_STR Error = "Wrong or unknown protocol"
CR_CONN_UNKNOW_PROTOCOL_STR Errstr ="Wrong or unknown protocol"
CR_SECURE_AUTH Errno = 2049
CR_SECURE_AUTH_STR Error = "Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)"
CR_SECURE_AUTH_STR Errstr ="Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)"
CR_FETCH_CANCELED Errno = 2050
CR_FETCH_CANCELED_STR Error = "Row retrieval was canceled by mysql_stmt_close() call"
CR_FETCH_CANCELED_STR Errstr ="Row retrieval was canceled by mysql_stmt_close() call"
CR_NO_DATA Errno = 2051
CR_NO_DATA_STR Error = "Attempt to read column without prior row fetch"
CR_NO_DATA_STR Errstr ="Attempt to read column without prior row fetch"
CR_NO_STMT_METADATA Errno = 2052
CR_NO_STMT_METADATA_STR Error = "Prepared statement contains no metadata"
CR_NO_STMT_METADATA_STR Errstr ="Prepared statement contains no metadata"
CR_NO_RESULT_SET Errno = 2053
CR_NO_RESULT_SET_STR Error = "Attempt to read a row while there is no result set associated with the statement"
CR_NO_RESULT_SET_STR Errstr ="Attempt to read a row while there is no result set associated with the statement"
CR_NOT_IMPLEMENTED Errno = 2054
CR_NOT_IMPLEMENTED_STR Error = "This feature is not implemented yet"
CR_NOT_IMPLEMENTED_STR Errstr ="This feature is not implemented yet"
CR_SERVER_LOST_EXTENDED Errno = 2055
CR_SERVER_LOST_EXTENDED_STR Error = "Lost connection to MySQL server at '%s', system error: %d"
CR_SERVER_LOST_EXTENDED_STR Errstr ="Lost connection to MySQL server at '%s', system error: %d"
CR_STMT_CLOSED Errno = 2056
CR_STMT_CLOSED_STR Error = "Statement closed indirectly because of a preceeding %s() call"
CR_STMT_CLOSED_STR Errstr ="Statement closed indirectly because of a preceeding %s() call"
CR_NEW_STMT_METADATA Errno = 2057
CR_NEW_STMT_METADATA_STR Error = "The number of columns in the result set differs from the number of bound buffers. You must reset the statement, rebind the result set columns, and execute the statement again"
CR_NEW_STMT_METADATA_STR Errstr ="The number of columns in the result set differs from the number of bound buffers. You must reset the statement, rebind the result set columns, and execute the statement again"
CR_ALREADY_CONNECTED Errno = 2058
CR_ALREADY_CONNECTED_STR Error = "This handle is already connected"
CR_ALREADY_CONNECTED_STR Errstr ="This handle is already connected"
CR_AUTH_PLUGIN_CANNOT_LOAD Errno = 2059
CR_AUTH_PLUGIN_CANNOT_LOAD_STR Error = "Authentication plugin '%s' cannot be loaded: %s"
CR_AUTH_PLUGIN_CANNOT_LOAD_STR Errstr ="Authentication plugin '%s' cannot be loaded: %s"
)

// Client error struct
type ClientError struct {
Errno Errno
Error Error
Errstr Errstr
}

// 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.Errstr)
}

// Server error struct
type ServerError struct {
Errno Errno
Error Error
Errstr Errstr
}

// 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.Errstr)
}
51 changes: 24 additions & 27 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -46,11 +43,11 @@ func handleError(p *packetError, c *Client) (err os.Error) {
c.serverStatus ^= SERVER_MORE_RESULTS_EXISTS
}
// Return error
return &ServerError{Errno(p.errno), Error(p.error)}
return &ServerError{Errno(p.errno), Errstr(p.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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -276,17 +273,17 @@ func handleBinaryRow(p *packetRowBinary, c *Client, r *Result) (err os.Error) {
case FIELD_TYPE_BIT, FIELD_TYPE_DECIMAL, FIELD_TYPE_NEWDECIMAL, FIELD_TYPE_VARCHAR,
FIELD_TYPE_TINY_BLOB, FIELD_TYPE_MEDIUM_BLOB, FIELD_TYPE_LONG_BLOB, FIELD_TYPE_BLOB,
FIELD_TYPE_VAR_STRING, FIELD_TYPE_STRING, FIELD_TYPE_GEOMETRY:
num, n, err := btolcb(p.data[pos:])
if err != nil {
return
num, n, _err := btolcb(p.data[pos:])
if _err != nil {
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
num, n, _err := btolcb(p.data[pos:])
if _err != nil {
return _err
}
// New date
d := Date{}
Expand All @@ -306,9 +303,9 @@ func handleBinaryRow(p *packetRowBinary, c *Client, r *Result) (err os.Error) {
pos += uint64(n) + num
// Time (From libmysql/libmysql.c read_binary_time)
case FIELD_TYPE_TIME:
num, n, err := btolcb(p.data[pos:])
if err != nil {
return
num, n, _err := btolcb(p.data[pos:])
if _err != nil {
return _err
}
// New time
t := Time{}
Expand All @@ -328,9 +325,9 @@ func handleBinaryRow(p *packetRowBinary, c *Client, r *Result) (err os.Error) {
pos += uint64(n) + num
// Datetime/Timestamp (From libmysql/libmysql.c read_binary_datetime)
case FIELD_TYPE_TIMESTAMP, FIELD_TYPE_DATETIME:
num, n, err := btolcb(p.data[pos:])
if err != nil {
return
num, n, _err := btolcb(p.data[pos:])
if _err != nil {
return _err
}
// New datetime
d := DateTime{}
Expand Down
Loading