housekeeping
2008-Jun-26 04:22 UTC
Rails App Database in MySQL - OK, However what if I need to access multiple Databases of different types ie. Sybase, MSSQL and Oracle
Hi, Although I am an experienced developer, I am new to rails and enjoying how easy it is to build applications. I seem to have come across a stumbling block and was wondering if anyone out there has come across the same problem and could suggest possible solutions. Problem: I have an intranet-based application in a company network - using rails. The application has many sub-applications which may be composed of a handful of pages each. The web application has its own database using MySQL which contains all application specific data, however, I need to retrieve data from different sources which maybe, MSSQL, Oracle or Sybase databases. For example, I need to access a well establish Sybase database server which contains trade data so I can create a summary of daily Profit & Loss - after filtering, various calculations I will archive this summary data in the Applications MySQL DB for performance views etc.over time. The Question: In rails how do I do this neatly, rails is designed to use one database right? Would anyone be able to suggest ways in which I can access such data? Many thanks in advance. H --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ar Chron
2008-Jun-26 14:37 UTC
Re: Rails App Database in MySQL - OK, However what if I need
You''ll need to take over the connection for your different models (this model is MySQL, that model is Sybase, etc). Start here, and google for other examples: http://api.rubyonrails.com/classes/ActiveRecord/Base.html (I''m currently trying to avoid this issue myself in a company app, but I don''t think it will go away, and I won''t be able to avoid it for much longer - I''ll have to connect to MySQL, SQL Server, and Oracle - sigh) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom
2008-Jun-26 16:25 UTC
Re: Rails App Database in MySQL - OK, However what if I need to access multiple Databases of different types ie. Sybase, MSSQL and Oracle
> Problem: > > I have an intranet-based application in a company network - using > rails. The application has many sub-applications which may be composed > of a handful of pages each. > > The web application has its own database using MySQL which contains > all application specific data, however, I need to retrieve data from > different sources which maybe, MSSQL, Oracle or Sybase databases. > > For example, I need to access a well establish Sybase database server > which contains trade data so I can create a summary of daily Profit & > Loss - after filtering, various calculations I will archive this > summary data in the Applications MySQL DB for performance views > etc.over time. > > The Question: > > In rails how do I do this neatly, rails is designed to use one > database right? > Would anyone be able to suggest ways in which I can access such data?Set up the database connection in database.yml. Let''s say it''s named "sybasefu". In the models that need to access that database do this: class SomeThing < ActiveRecord::Base establish_connection "sybasefu" #.... end One thing to check is if you have several models that need to connect to sybasefu, *each* one will open it''s own connection. Unlike your "normal" models which share a single database connection. This was true for Rails 1.1.6 (and yes, I realize how old that is :). To get around it I did this: class MySybaseClasses < ActiveRecord::Base establish_connection "sybasefu" end class Something < MySpaceClasses #.... end class SomethingElse < MySpaceClasses #... end That may or may not still be an issue, but it''s something to check. If it isn''t, let me know :) -philip --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
housekeeping
2008-Jun-27 01:24 UTC
Re: Rails App Database in MySQL - OK, However what if I need to access multiple Databases of different types ie. Sybase, MSSQL and Oracle
Thanks Phillip, checking it out right now... this looks so obvious!! Will let you know how it all pans out, but I am thinking this should do the trick in combination with find_by_sql() for the query. Very helpful thank you :-) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---