Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # To change this template, choose Tools | Templates
- # and open the template in the editor.
- require 'rubygems'
- require 'active_record'
- def connexion_activerecord
- ActiveRecord::Base.establish_connection(
- :host => 'localhost',
- :adapter => 'jdbc_mysql',
- :database => 'test',
- :port => 8889,
- :username => 'root'
- )
- end
- class Employe < ActiveRecord::Base
- def to_s
- str="Nom : " << nom << "\n"
- str=str<< "Prenom : " << prenom << "\n"
- str=str<< "Ville : " << ville << "\n"
- str=str<< "Salaire : " << salaire.to_s << "\n"
- retrun str
- end
- end
- connexion_activeRecord
- Employe.find(:all).each do |e|
- puts e
- end
- a=Employe.find(:last)
- puts a
- Employe.find(:all,
- :order => "salaire DESC, nom ASC",
- :conditions => "salaire > 4900").each { |e| puts e }
- # requete dynamique
- [5000, 7000, 19000].each { |s|
- Employe.find(:all,
- :conditions => ["salaire = ?", s]).each { |e| puts e }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement