Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boolean value 'T' and 'F' #74

Open
fwidtmann opened this issue Dec 20, 2016 · 5 comments
Open

Boolean value 'T' and 'F' #74

fwidtmann opened this issue Dec 20, 2016 · 5 comments

Comments

@fwidtmann
Copy link

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
@fwidtmann
Copy link
Author

fwidtmann commented Dec 21, 2016

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')

@fwidtmann
Copy link
Author

fwidtmann commented Dec 21, 2016

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 :(

@fwidtmann
Copy link
Author

fwidtmann commented Dec 21, 2016

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.

@Seralto
Copy link

Seralto commented Feb 10, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants