# Emulate\_booleans for a specific connection

**URL:** <https://www.ruby-forum.com/t/emulate-booleans-for-a-specific-connection/181539>\
**Category:** Rails\
**Created:** [January 13, 2010, 11:56am UTC](https://www.ruby-forum.com/t/emulate-booleans-for-a-specific-connection/181539 "2010-01-13T11:56:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nerd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f475e1/32.png) [@nerd](https://www.ruby-forum.com/u/nerd)\
**Post date:** [January 13, 2010, 11:56am UTC](https://www.ruby-forum.com/t/emulate-booleans-for-a-specific-connection/181539/1 "2010-01-13T11:56:28Z")

</div>

Hello,  
I’m running an environment with connections to different types of  
databases (using AR) in addition to the default mysql(5) connection.  
The MSSQL-Connections are working fine. Just one “old” 3rd party  
database makes problems: an old mysql(4) database. The problem is,  
that there are colums of type tinyint(1) which gets by default  
translated to boolean. As the mysql(5) environment uses the same  
connection adapter I cannot simply set emulate\_booleans globally to  
false via environment.rb (somewhere the boolean mapping is used) . As  
all these 3rd party connections are established using  
establish\_connection blocks I tried to set this there… but it seems  
to be ignored, as I’m still stopped with ‘ArgumentError: binary  
columns cannot have a default value: “0”’, which for my understanding  
should not occur when setting the emulation to false…  
Where’s my fault? Or is it impossible to set this behavior (briefly  
said) Model/Connection wise ?!

Thanks for any idea!

Christian Meyer  
Web-Application-Developer

---

<div class="post-metadata">

**Author:** ![nerd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f475e1/32.png) [@nerd](https://www.ruby-forum.com/u/nerd)\
**Post date:** [January 13, 2010, 11:59am UTC](https://www.ruby-forum.com/t/emulate-booleans-for-a-specific-connection/181539/2 "2010-01-13T11:59:24Z")

</div>

On Jan 12, 11:25Â pm, nerd [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> establish\_connection blocks I tried to set this there… but it seems  
> to be ignored, as I’m still stopped with ‘ArgumentError: binary  
> columns cannot have a default value: “0”’, which for my understanding  
> should not occur when setting the emulation to false…  
> Where’s my fault? Or is it impossible to set this behavior (briefly  
> said) Model/Connection wise ?!

Dumb suggestion:

class LegacyMysqlAdapter \<  
ActiveRecord::ConnectionAdapters::MysqlAdapter  
def self.emulate\_booleans  
false  
ense  
end

then set the appropriate database connection’s adapter to legacy\_mysql

Fred

---

<div class="post-metadata">

**Author:** ![nerd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f475e1/32.png) [@nerd](https://www.ruby-forum.com/u/nerd)\
**Post date:** [January 14, 2010, 2:08pm UTC](https://www.ruby-forum.com/t/emulate-booleans-for-a-specific-connection/181539/3 "2010-01-14T14:08:10Z")

</div>

On 13 Jan., 11:57, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Dumb suggestion:
> 
> class LegacyMysqlAdapter \<  
> ActiveRecord::ConnectionAdapters::MysqlAdapter  
> Â def self.emulate\_booleans  
> Â Â false  
> Â ense  
> end
> 
> then set the appropriate database connection’s adapter to legacy\_mysql

I already tried this kind of easy solution… but this fails as  
establish\_connection from activerecord/lib/active\_record/  
connection\_adapters/abstract/connection\_specification.rb tries to load  
an gem with this name…

Christian Meyer

---

<div class="post-metadata">

**Author:** ![nerd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f475e1/32.png) [@nerd](https://www.ruby-forum.com/u/nerd)\
**Post date:** [January 14, 2010, 2:54pm UTC](https://www.ruby-forum.com/t/emulate-booleans-for-a-specific-connection/181539/4 "2010-01-14T14:54:25Z")

</div>

On Jan 14, 1:06Â pm, nerd [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On 13 Jan., 11:57, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > then set the appropriate database connection’s adapter to legacy\_mysql
> 
> I already tried this kind of easy solution… but this fails as  
> establish\_connection from activerecord/lib/active\_record/  
> connection\_adapters/abstract/connection\_specification.rb tries to load  
> an gem with this name…

Then stick the above in a gem (and perhaps then vendor it into your  
app)

Fred
