crystal-lang / crystal-mysql

MySQL connector for Crystal
MIT License
107 stars 36 forks source link

Binary strings #8

Closed crisward closed 8 years ago

crisward commented 8 years ago

Having trouble reading binary strings, ie (column type text).

I can handle this in my application with text = String.new(bytes) but this is something which should be handled in the driver. Mysql returns text as type blob, not sure if there is a way to auto detect text?

If you have any pointers how to add this I have no problem taking a look.

bcardiff commented 8 years ago

The first thing to check is whether blob and text can be distinguished from each other. I think they are advertised as blobs.

https://dev.mysql.com/doc/internals/en/com-query-response.html#column-type

If that's the case then using a DB.mapping could be an option.

Or, in order to use ResultSet#read(T) you a TextBlob type could be defined to add an overload that will handle that conversion and return String.

Or the String overload could handle reading from blobs.

In crystal, strings are utf-8 valid sequence only. For binary data a Slice need to be used.