Module: Redmine::Database
- Defined in:
 - lib/redmine/database.rb
 
Overview
Helper module to get information about the Redmine database
Class Method Summary collapse
- 
  
    
      .like(left, right, options = {})  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Returns a SQL statement for case/accent (if possible) insensitive match.
 - 
  
    
      .mysql?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
Returns true if the database is MySQL.
 - 
  
    
      .postgresql?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
Returns true if the database is PostgreSQL.
 - 
  
    
      .postgresql_unaccent?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
Returns true if the database is a PostgreSQL >=9.0 database with the unaccent extension installed.
 - 
  
    
      .postgresql_version  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Returns the PostgreSQL version or nil if another DBMS is used.
 - 
  
    
      .reset  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Resets database information.
 
Class Method Details
.like(left, right, options = {}) ⇒ Object
Returns a SQL statement for case/accent (if possible) insensitive match
      53 54 55 56 57 58 59 60 61 62 63 64 65  | 
    
      # File 'lib/redmine/database.rb', line 53 def like(left, right, ={}) neg = ([:match] == false ? 'NOT ' : '') if postgresql? if postgresql_unaccent? "unaccent(#{left}) #{neg}ILIKE unaccent(#{right})" else "#{left} #{neg}ILIKE #{right}" end else "#{left} #{neg}LIKE #{right}" end end  | 
  
.mysql? ⇒ Boolean
Returns true if the database is MySQL
      48 49 50  | 
    
      # File 'lib/redmine/database.rb', line 48 def mysql? (ActiveRecord::Base.connection.adapter_name =~ /mysql/i).present? end  | 
  
.postgresql? ⇒ Boolean
Returns true if the database is PostgreSQL
      23 24 25  | 
    
      # File 'lib/redmine/database.rb', line 23 def postgresql? (ActiveRecord::Base.connection.adapter_name =~ /postgresql/i).present? end  | 
  
.postgresql_unaccent? ⇒ Boolean
Returns true if the database is a PostgreSQL >=9.0 database with the unaccent extension installed
      33 34 35 36 37 38 39 40 41 42 43 44 45  | 
    
      # File 'lib/redmine/database.rb', line 33 def postgresql_unaccent? if postgresql? return @postgresql_unaccent unless @postgresql_unaccent.nil? begin sql = "SELECT name FROM pg_available_extensions WHERE installed_version IS NOT NULL and name = 'unaccent'" @postgresql_unaccent = postgresql_version >= 90000 && ActiveRecord::Base.connection.select_value(sql).present? rescue false end else false end end  | 
  
.postgresql_version ⇒ Object
Returns the PostgreSQL version or nil if another DBMS is used
      28 29 30  | 
    
      # File 'lib/redmine/database.rb', line 28 def postgresql_version postgresql? ? ActiveRecord::Base.connection.send(:postgresql_version) : nil end  | 
  
.reset ⇒ Object
Resets database information
      68 69 70  | 
    
      # File 'lib/redmine/database.rb', line 68 def reset @postgresql_unaccent = nil end  |