ondemannen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2013-Dec-17 12:05 UTC
ActiveRecord and tiny_tds
Hi, I''m having some issues trying to run .find_by_sql against a Win MSSQL 2008 server. When I use the tiny_tds gem the query works without any issues. require ''rubygems'' gem ''tiny_tds'', ''= 0.6.2'' require ''tiny_tds'' gem ''activerecord'', ''= 3.2.12'' require ''active_record'' require ''activerecord-sqlserver-adapter'' client = TinyTds::Client.new(:username => ''user'',:password => ''pass'',:host => ''host'',:database => ''db'') result = client.execute(sql) => #<TinyTds::Result:0x000000022c3e48> When I try the same query with an ActiveRecord::Base model I don''t see any results (I''ve tried both :host and :dataserver with the same result). class Ipdb < ActiveRecord::Base establish_connection( :adapter => "sqlserver", :host => ''host'', :username => ''user'', :password => ''pass'', :database => ''db'', ) self.table_name = "View_All_IPs" end ai = Ipdb.find_by_sql(sql) p ai.size => 1 p ai.inspect =>"[#<Ipdb >]" p ai[0].class => Ipdb() p ai[0] => #<Ipdb > Any ideas about where the problem may be? Thanks J-H Johansen -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/3ab64e2c-d464-4fed-bfaa-52504fb04a23%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
ondemannen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2013-Dec-17 15:12 UTC
Re: ActiveRecord and tiny_tds
After some more debugging I finally realized that the object actually had some data attached to it. It must have been the .inspect which fooled me into thinking it was empty. ai = Ipdb.where("[IP Address] = ?", ip) ai.each do |b| puts b["IP Address"] puts b.Information end This outputs the information needed. Not sure why the object doesn''t output all this information when I ''inspect'' it... kl. 13:05:07 UTC+1 tirsdag 17. desember 2013 skrev ondem...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org følgende:> Hi, > > I''m having some issues trying to run .find_by_sql against a Win MSSQL 2008 > server. When I use the tiny_tds gem the query works without any issues. > > require ''rubygems'' > gem ''tiny_tds'', ''= 0.6.2'' > require ''tiny_tds'' > gem ''activerecord'', ''= 3.2.12'' > require ''active_record'' > require ''activerecord-sqlserver-adapter'' > > client = TinyTds::Client.new(:username => ''user'',:password => ''pass'',:host > => ''host'',:database => ''db'') > result = client.execute(sql) > => #<TinyTds::Result:0x000000022c3e48> > > > When I try the same query with an ActiveRecord::Base model I don''t see any > results (I''ve tried both :host and :dataserver with the same result). > > class Ipdb < ActiveRecord::Base > establish_connection( > :adapter => "sqlserver", > :host => ''host'', > :username => ''user'', > :password => ''pass'', > :database => ''db'', > ) > self.table_name = "View_All_IPs" > end > ai = Ipdb.find_by_sql(sql) > p ai.size > => 1 > p ai.inspect > =>"[#<Ipdb >]" > p ai[0].class > => Ipdb() > p ai[0] > => #<Ipdb > > > Any ideas about where the problem may be? > > Thanks > J-H Johansen >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/89f0d137-d0b2-4036-bf8f-3d680e81ee30%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Possibly Parallel Threads
- TinyTds::Client.new() gives an error "undefined symbol: dbsetluser"
- Unable to Install ruby-odbc gem on windows 2008 server bit
- Windows new installation - Always problems
- Any comment on adding #cast and #cast! to ActiveRecord::Relation?
- Which AR Interfaces Leverage PreparedStatements/Binds?