This project is archived and is in readonly mode.
Binary table default values
-
Pratik
- Assigned user set to Pratik
- State changed from new to incomplete
You should try to submit a failing test case. http://guides.rails.info/contrib... would come handy :)
Thanks.
-
CancelProfileIsBroken
- Tag changed from binary, database, tables to binary, bugmash, database, tables
-
Jeremy Kemper
- State changed from incomplete to invalid
- Tag changed from binary, bugmash, database, tables to binary, database, tables
- Milestone cleared.
Correct: MySQL does not permit default values for BLOB or TEXT columns. You can provide one, but MySQL will silently ignore it.
Workaround: provide your own default when you create new records using a before_create callback.
-
Jatinder Singh
Correct MySQL doesn't permit default values for BLOB or TEXT columns. but MySQL has BINARY and VARBINARY types(which support default values), and AR considers them as as type "binary". here is relevant piece of code from schema_definitions.rb,
def simplified_type(field_type) case field_type when /int/i :integer when /float|double/i :float when /decimal|numeric|number/i extract_scale(field_type) == 0 ? :integer : :decimal when /datetime/i :datetime when /timestamp/i :timestamp when /time/i :time when /date/i :date when /clob/i, /text/i :text when /blob/i, /binary/i :binary when /char/i, /string/i :string when /boolean/i :boolean end endI think its right for AR to consider BINARY and VARBINARY as BINARY type, and utilize methods like string_to_binary with them. The only difference I see is with default values. here is a potential fix for the problem, http://gist.github.com/164981. let me know how it looks and I can create a patch for it.
-
Jatinder Singh
I'll create a patch for this fix and missing tests for MySQLColumn.
-
Jatinder Singh
- Tag changed from binary, database, tables to binary, bugmash, database, tables
-
Jatinder Singh
- Tag changed from binary, bugmash, database, tables to activerecord, binary, bugmash, database, mysql, tables
I've attached a patch with tests for the fix for master. Patch for 2.3-stable coming up next.
-
Jatinder Singh
- Tag changed from activerecord, binary, bugmash, database, mysql, tables to activerecord, binary, bugmash, database, mysql, patch, tables
-
Jatinder Singh
I just realized that the same patch gets applied to 2-3-stable successfully.
-
Repository
- State changed from open to committed
(from [8a49af31581095a35b6dc8b20ed12c2f9fb80855]) AR should respect default values for MySQL BINARY and VARBINARY columns.
[#1273 Binary table default values state:committed]
Signed-off-by: Jeremy Kemper jeremy@bitsweat.net
http://github.com/rails/rails/commit/8a49af31581095a35b6dc8b20ed12c... -
Repository
(from [5704ecffadffa04981ec5999c362cb691d4a676e]) AR should respect default values for MySQL BINARY and VARBINARY columns.
[#1273 Binary table default values state:committed]
Signed-off-by: Jeremy Kemper jeremy@bitsweat.net
http://github.com/rails/rails/commit/5704ecffadffa04981ec5999c362cb... -
Jeremy Kemper
- Tag changed from activerecord, binary, bugmash, database, mysql, patch, tables to activerecord, binary, database, mysql, patch, tables
