activerecord-fb-adapter
activerecord-fb-adapter copied to clipboard
Boolean value 'T' and 'F'
In our database we use the boolean values 'T' and 'F'.
i need to:
- save 'T' and 'F' from the application to db.
- read 'T' and 'F' from db and interpret it as true or false
http://www.rubydoc.info/gems/activerecord-fb-adapter/1.0.3/ActiveRecord/ConnectionAdapters/FbAdapter
thank you, but i think its not working.
in my environment.rb
ActiveRecord::ConnectionAdapters::FbAdapter.boolean_domain = { :true => 'T', :false => 'F', :name => 'BOOLEAN', :type => 'char' }
in db:
CREATE DOMAIN BOOLEAN AS CHAR(1) CHECK (VALUE IN ('T', 'F'));
i have a table named cars and a column named running
running is has a field type CHAR, size 1 and domain boolean
so, if i try
@car.running = true
@car.save!
i get Fb::Error: Incompatible column/host variable data type Dynamic SQL Error SQL error code = -303 arithmetic exception, numeric overflow, or string truncation string right truncation
the same if i try to save 1 or 'T'
if i remove the check in the domain boolean i got the same results.
update cars set running = 'T'
works. so i think there is an issue with the activerecord-fb-adapter.
@rowland can you help me? i have been trying to get this work since 2 days
if i remove the line in environment.rb, its inserting 1. (@car.running = true, 1, 'T')
i got something new:
i set the column size to 3
@car.running = true
@car.save!
he saves now 'T' in the column, but it should be a T :(
there is another big problem:
if i insert the T manuell (update cars set running = 'T') in the column and call:
puts "#{@car.running}"
i got a "false", but i should get a "true"
i can do something weird like Car.find_by(running: true).running is false
without the line in environment.rb and with 1 and 0 and domain smallint its working.
In my case the link Rowland sad works, but I have to change the line in environment.rb:
ActiveRecord::ConnectionAdapters::FbAdapter.boolean_domain = { :true => 'T ', :false => 'F ', :name => 'BOOLEAN', :type => 'char' }
Note the three spaces after the letter in 'T ' and 'F '.
I really don't know why, but the data was stored this way in the database.