Closed yunge closed 13 years ago
Hi, thanks for the report.
There is a bit of a problem using normal queries in that many types are sent by the server and reported as "string" but in fact we would never ever want them to be converted to strings as they are binary types. Hence, for the time being I left them in raw []byte format, will hopefully have a better resolution for this for the final release.
The new statements are much nicer to use as you can bind a parameter of the type you want to use in your program and the library will convert (provided the types are reasonably easy to convert between).
This has been improved in my local copy which will form 0.3.0-RC.
VARCHAR, CHAR etc will now be converted to strings
TEXT, BLOB etc are left as []byte as they are indistinguishable and it's more memory efficient to leave them as a slice, especially if there is a lot of data. You can type assert them as []byte then cast to string:
str := string(row[5].([]byte))
It's not the most elegant solution, but there isn't really a way to make it much nicer for standard queries.
That would be great! I think convert BLOB to []byte is certainly good. As VARCHAR is large enough for normal usage of string type since MySql5.0, so leave TEXT to []byte for memory efficient is acceptable too, so I just waiting for the new release, thanks.
This is the thinking behind it (if you're interested):
When a packet is read it's always into a slice (so []byte) so by simply setting each field to another slice it's much more efficient as it references the same underlying array (1 copy in memory for the whole packet). However if we were to string convert a big text/blob field automatically it would create a copy in memory and use double the memory.
The original data would get garbage collected at some point, but the GC in Go is not instant so I don't want to rely on the GC to clean up memory straight away (which in reality won't happen).
Resolved in RC-2
As "Go row data formats" saying, "varchar" would be convert to "string", but I got []byte, which is really inconvenient to handle, please check it, thanks.