Skip to content

Commit d4ae571

Browse files
author
Phil Bayfield
committed
fix issue 48 and added improvements in issue 47
1 parent 6d99bc3 commit d4ae571

File tree

3 files changed

+39
-26
lines changed

3 files changed

+39
-26
lines changed

README.markdown

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
GoMySQL Version 0.3.0-RC
2-
========================
1+
GoMySQL Version 0.3.0-RC-2
2+
==========================
33

44

55
Revision History
66
----------------
77

88
0.3.x series [testing]
99

10-
* 0.3.0-RC - Fixed TestSimple unit test and added TestSimpleStatement which performs the same tests as TestSimple but uses a prepared statement throughout. Fixed and variable length strings for normal queries now return string types not []byte, text/blobs are indistinguishable so are left in []byte format which is more efficient. All integer values in prepared statements are stored as either int64 or uint64 depending on the unsigned flag, this simplifies conversion greatly when binding the result. Added ParamCount() and RowCount() methods to statements. The built in Date, Time and DateTime types can now be bound as strings in statements. Added auto-reconnect to all methods using the network and added reconnect/recovery support to Prepare and Execute functions. Statement.Reset now frees any remaining rows or complete result sets from the connection before sending the reset command so no longer requires a call to FreeResult prior to calling.
10+
* 0.3.0-RC-2 - Convert additional string types (issue 47). Added a check for NULL fields in the row packet handler to prevent a crash in strconv (issue 48).
11+
* 0.3.0-RC-1 - Fixed TestSimple unit test and added TestSimpleStatement which performs the same tests as TestSimple but uses a prepared statement throughout. Fixed and variable length strings for normal queries now return string types not []byte, text/blobs are indistinguishable so are left in []byte format which is more efficient. All integer values in prepared statements are stored as either int64 or uint64 depending on the unsigned flag, this simplifies conversion greatly when binding the result. Added ParamCount() and RowCount() methods to statements. The built in Date, Time and DateTime types can now be bound as strings in statements. Added auto-reconnect to all methods using the network and added reconnect/recovery support to Prepare and Execute functions. Statement.Reset now frees any remaining rows or complete result sets from the connection before sending the reset command so no longer requires a call to FreeResult prior to calling.
1112
* 0.3.0-beta-1 - Added full statement and functions. Refactored packet handlers into generic functions. Added new BindResult/Fetch method to get result data from prepared statements. Added type conversions for similar types to populate the result pointers with values from the row data. Added simple type conversion to standard queries. Added automatic reconnect for a select number of operations. Added greater number of client errors from the MySQL manual. Added date/time types to allow date/time elements to be stored as integers and ints, making them more useful.
1213
* 0.3.0-alpha-3 - Added new error structs ClientError and ServerError. Replaced majority of os.Error/os.NewError functionality with MySQL specific ClientError objects. Server error responses now return a ServerError. Removed Client.Errno and Client.Error. Added deferred error processing to reader, writer and packets to catch and errors and always return a ClientError. Rewrote auto reconnect to check for specific MySQL error codes.
1314
* 0.3.0-alpha-2 - Added transaction wrappers, Added auto-reconnect functionality to repeatable methods. Removed mutex lock/unlocking, as it is now more appropriate that the application decides when thread safe functions are required and it's considerably safer to have a sequence such as Client.Lock(), Client.Query(...), Client.Unlock(). Added a new test which performs create, drop, select, insert and update queries on a simple demo table to test the majority of the library functionality. Added additional error messages to places where an error could be returned but there was no error number/string set. Many small changes and general improvements.

handler.go

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package mysql
88
import (
99
"os"
1010
"strconv"
11+
"fmt"
1112
)
1213

1314
// OK packet handler
@@ -111,6 +112,9 @@ func handleField(p *packetField, c *Client, r *Result) (err os.Error) {
111112

112113
// Row packet hander
113114
func handleRow(p *packetRowData, c *Client, r *Result) (err os.Error) {
115+
defer func() {
116+
fmt.Printf("Error: %#v\n", err)
117+
}()
114118
// Log field result
115119
c.log(1, "[%d] Received row packet", p.sequence)
116120
// Check sequence
@@ -127,40 +131,48 @@ func handleRow(p *packetRowData, c *Client, r *Result) (err os.Error) {
127131
var field interface{}
128132
// Iterate fields to get types
129133
for i, f := range r.fields {
130-
switch f.Type {
131-
// Signed/unsigned ints
132-
case FIELD_TYPE_TINY, FIELD_TYPE_SHORT, FIELD_TYPE_YEAR, FIELD_TYPE_INT24, FIELD_TYPE_LONG, FIELD_TYPE_LONGLONG:
133-
if f.Flags&FLAG_UNSIGNED > 0 {
134-
field, err = strconv.Atoui64(string(p.row[i].([]byte)))
135-
} else {
136-
field, err = strconv.Atoi64(string(p.row[i].([]byte)))
137-
}
138-
if err != nil {
139-
return
140-
}
141-
// Floats and doubles
142-
case FIELD_TYPE_FLOAT, FIELD_TYPE_DOUBLE:
143-
field, err = strconv.Atof64(string(p.row[i].([]byte)))
144-
if err != nil {
145-
return
134+
// Check null
135+
if len(p.row[i].([]byte)) ==0 {
136+
field = nil
137+
} else {
138+
switch f.Type {
139+
// Signed/unsigned ints
140+
case FIELD_TYPE_TINY, FIELD_TYPE_SHORT, FIELD_TYPE_YEAR, FIELD_TYPE_INT24, FIELD_TYPE_LONG, FIELD_TYPE_LONGLONG:
141+
if f.Flags&FLAG_UNSIGNED > 0 {
142+
field, err = strconv.Atoui64(string(p.row[i].([]byte)))
143+
} else {
144+
field, err = strconv.Atoi64(string(p.row[i].([]byte)))
145+
}
146+
if err != nil {
147+
return
148+
}
149+
// Floats and doubles
150+
case FIELD_TYPE_FLOAT, FIELD_TYPE_DOUBLE:
151+
field, err = strconv.Atof64(string(p.row[i].([]byte)))
152+
if err != nil {
153+
return
154+
}
155+
// Strings
156+
case FIELD_TYPE_DECIMAL, FIELD_TYPE_NEWDECIMAL, FIELD_TYPE_VARCHAR, FIELD_TYPE_VAR_STRING, FIELD_TYPE_STRING:
157+
field = string(p.row[i].([]byte))
158+
// Anything else
159+
default:
160+
field = p.row[i]
146161
}
147-
// Strings
148-
case FIELD_TYPE_DECIMAL, FIELD_TYPE_NEWDECIMAL, FIELD_TYPE_VARCHAR, FIELD_TYPE_VAR_STRING, FIELD_TYPE_STRING:
149-
field = string(p.row[i].([]byte))
150-
// Anything else
151-
default:
152-
field = p.row[i]
153162
}
154163
// Add to row
155164
row = append(row, field)
156165
}
166+
fmt.Printf("%#v\n", row)
157167
// Stored result
158168
if r.mode == RESULT_STORED {
169+
fmt.Println("Appending")
159170
// Cast and append the row
160171
r.rows = append(r.rows, Row(row))
161172
}
162173
// Used result
163174
if r.mode == RESULT_USED {
175+
fmt.Println("Overwriting")
164176
// Only save 1 row, overwrite previous
165177
r.rows = []Row{Row(row)}
166178
}

mysql.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
// Constants
2222
const (
2323
// General
24-
VERSION = "0.3.0-RC"
24+
VERSION = "0.3.0-RC-2"
2525
DEFAULT_PORT = "3306"
2626
DEFAULT_SOCKET = "/var/run/mysqld/mysqld.sock"
2727
MAX_PACKET_SIZE = 1<<24 - 1

0 commit comments

Comments
 (0)