Advertisement
Guest User

Untitled

a guest
May 27th, 2015
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. # To change this template, choose Tools | Templates
  2. # and open the template in the editor.
  3.  
  4. require 'rubygems'
  5. require 'active_record'
  6.  
  7. def connexion_activerecord
  8. ActiveRecord::Base.establish_connection(
  9. :host => 'localhost',
  10. :adapter => 'jdbc_mysql',
  11. :database => 'test',
  12. :port => 8889,
  13. :username => 'root'
  14. )
  15. end
  16.  
  17. class Employe < ActiveRecord::Base
  18.  
  19. def to_s
  20. str="Nom : " << nom << "\n"
  21. str=str<< "Prenom : " << prenom << "\n"
  22. str=str<< "Ville : " << ville << "\n"
  23. str=str<< "Salaire : " << salaire.to_s << "\n"
  24.  
  25. retrun str
  26. end
  27. end
  28.  
  29. connexion_activeRecord
  30.  
  31. Employe.find(:all).each do |e|
  32. puts e
  33. end
  34.  
  35. a=Employe.find(:last)
  36. puts a
  37.  
  38. Employe.find(:all,
  39. :order => "salaire DESC, nom ASC",
  40. :conditions => "salaire > 4900").each { |e| puts e }
  41.  
  42. # requete dynamique
  43. [5000, 7000, 19000].each { |s|
  44. Employe.find(:all,
  45. :conditions => ["salaire = ?", s]).each { |e| puts e }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement