hello
I am writing a tutorial about mysql ruby and I have a question
about the MysqlField class
the method “type” returns the field type. in my examples
it returns a number for example 253 for a field with type VARCHAR.
is it possible to get a more readable representation of this value??
hello
I am writing a tutorial about mysql ruby and I have a question
about the MysqlField class
the method “type” returns the field type. in my examples
it returns a number for example 253 for a field with type VARCHAR.
is it possible to get a more readable representation of this value??
the types are defined as constants of the MysqlField class. you can build
a lookup-table with something like
types = Hash.new
MysqlField.constants.each { |cname|
cval = MysqlField.const_get(cname)
if (cname =~ /^TYPE_/)
types[cval.to_i] = cname
end
}
after that you have a hash that maps the types to their
constant-names. unfortunately the 253 for TYPE_VAR_STRING is not
defined in the mysql-extension.
For easier client code, the client should no longer use
FIELD_TYPE_TINY_BLOB, FIELD_TYPE_MEDIUM_BLOB, FIELD_TYPE_LONG_BLOB
or FIELD_TYPE_VAR_STRING (as previously returned by
mysql_list_fields). You should instead only use FIELD_TYPE_BLOB or
FIELD_TYPE_STRING. If you want exact types, you should use the
command SHOW FIELDS."
so you should do m.query(“SHOW FIELDS FROM table”) instead of m.list_fields(‘table’)
to get a more readable representation of your metadata, i guess.