ActiveRecord is by far the best I have seen the ORM library, apart from DB2, supports all the mainstream databases. If you want to know how to use a separate Activerecord, please follow me.



Introduce my system environment:

OS: windows2003

DataBase: Oracle10g

Ruby: 1.8.7 (2008-05-31 patchlevel 0) [i386-mswin32]

activerecord: 2.2.2

activerecord-oracle_enhanced-adapter: 1.1.8

ruby-oci8: 1.0.3



Preparation work:

1. To install ruby, needless to say all right

2. Installed activerecord, gem install activerecord

3. Installed adapter, gem install activerecord-oracle_enhanced-adapter

4. To create a test directory mkdir dbtest

ok, that's all



Create a rb file, which reads as follows



require 'rubygems'  
require 'active_record'  
  
ActiveRecord::Base.establish_connection(  
  :adapter  => 'oracle_enhanced',   
  :database => 'test',   #oracle service name
  :username => 'system',   
  :password => 'system')  





You can also put the database configuration information in a separate document, create a file database.yml, which reads as follows



adapter:  oracle_enhanced
database: test
username: system
password: system



Rb file for changes



require 'rubygems'  
require 'active_record'  
require 'yaml'  
  
dbconfig = YAML::load(File.open('database.yml'))  
ActiveRecord::Base.establish_connection(dbconfig)  

Try the effect of



require 'rubygems'  
require 'active_record'  
require 'yaml'    
  
dbconfig = YAML::load(File.open('database.yml'))  
ActiveRecord::Base.establish_connection(dbconfig)  

class User < ActiveRecord::Base 
  set_table_name "my_user"
end  
  
puts User.count  



If you want to add ActiveRecord logs, can be done



require 'rubygems'  
require 'active_record'  
require 'yaml'  
require 'logger'  
  
dbconfig = YAML::load(File.open('database.yml'))  
ActiveRecord::Base.establish_connection(dbconfig)  
ActiveRecord::Base.logger = Logger.new(File.open('database.log', 'a'))  
  
class User < ActiveRecord::Base
   set_table_name "my_user"
end  
  
puts User.count  



This produced a document database.log



OK, here today on the bar