correctly quote column names in MySQL, PostgreSQL and SQLite3 - reportable - Fork of reportable required by WarVox, from hdm/reportable.
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
       ---
 (DIR) commit 57786c071a39c14d77d4ae9bbe33a05f2080fca8
 (DIR) parent 947a3fec849491b5d2a242632151639589465ae7
 (HTM) Author: Marco Otte-Witte <marco.otte-witte@simplabs.com>
       Date:   Fri,  5 Mar 2010 17:31:46 +0100
       
       correctly quote column names in MySQL, PostgreSQL and SQLite3
       
       Diffstat:
         M generators/reportable_migration/te… |       2 +-
         M lib/saulabs/reportable/report_cach… |       8 +++++---
         M spec/classes/report_cache_spec.rb   |      12 +++++++++---
         M spec/db/schema.rb                   |       6 +++---
       
       4 files changed, 18 insertions(+), 10 deletions(-)
       ---
 (DIR) diff --git a/generators/reportable_migration/templates/migration.erb b/generators/reportable_migration/templates/migration.erb
       @@ -6,7 +6,7 @@ class <%= class_name %> < ActiveRecord::Migration
              t.string   :report_name,      :null => false
              t.string   :grouping,         :null => false
              t.string   :aggregation,      :null => false
       -      t.string   :condition,        :null => false
       +      t.string   :conditions,       :null => false
              t.float    :value,            :null => false, :default => 0
              t.datetime :reporting_period, :null => false
        
 (DIR) diff --git a/lib/saulabs/reportable/report_cache.rb b/lib/saulabs/reportable/report_cache.rb
       @@ -92,13 +92,13 @@ module Saulabs
                  data ? data[1] : 0.0
                end
        
       -        def self.build_cached_data(report, grouping, condition, reporting_period, value)
       +        def self.build_cached_data(report, grouping, conditions, reporting_period, value)
                  self.new(
                    :model_name       => report.klass.to_s,
                    :report_name      => report.name.to_s,
                    :grouping         => grouping.identifier.to_s,
                    :aggregation      => report.aggregation.to_s,
       -            :condition        => condition.to_s,
       +            :conditions       => conditions.to_s,
                    :reporting_period => reporting_period.date_time,
                    :value            => value
                  )
       @@ -106,7 +106,9 @@ module Saulabs
        
                def self.read_cached_data(report, options)
                  conditions = [
       -            'model_name = ? AND report_name = ? AND grouping = ? AND aggregation = ? AND `condition` = ?',
       +            %w(model_name report_name grouping aggregation conditions).map do |column_name|
       +              "#{self.connection.quote_column_name(column_name)} = ?"
       +            end.join(' AND '),
                    report.klass.to_s,
                    report.name.to_s,
                    options[:grouping].identifier.to_s,
 (DIR) diff --git a/spec/classes/report_cache_spec.rb b/spec/classes/report_cache_spec.rb
       @@ -122,7 +122,9 @@ describe Saulabs::Reportable::ReportCache do
            it 'should read existing data from the cache' do
              Saulabs::Reportable::ReportCache.should_receive(:all).once.with(
                :conditions => [
       -          'model_name = ? AND report_name = ? AND grouping = ? AND aggregation = ? AND `condition` = ? AND reporting_period >= ?',
       +          %w(model_name report_name grouping aggregation conditions).map do |column_name|
       +            "#{Saulabs::Reportable::ReportCache.connection.quote_column_name(column_name)} = ?"
       +          end.join(' AND ') + ' AND reporting_period >= ?',
                  @report.klass.to_s,
                  @report.name.to_s,
                  @report.options[:grouping].identifier.to_s,
       @@ -141,7 +143,9 @@ describe Saulabs::Reportable::ReportCache do
              end_date = Time.now
              Saulabs::Reportable::ReportCache.should_receive(:all).once.with(
                :conditions => [
       -          'model_name = ? AND report_name = ? AND grouping = ? AND aggregation = ? AND `condition` = ? AND reporting_period BETWEEN ? AND ?',
       +          %w(model_name report_name grouping aggregation conditions).map do |column_name|
       +            "#{Saulabs::Reportable::ReportCache.connection.quote_column_name(column_name)} = ?"
       +          end.join(' AND ') + ' AND reporting_period BETWEEN ? AND ?',
                  @report.klass.to_s,
                  @report.name.to_s,
                  @report.options[:grouping].identifier.to_s,
       @@ -162,7 +166,9 @@ describe Saulabs::Reportable::ReportCache do
              Saulabs::Reportable::ReportCache.should_receive(:find).once.with(
                :all,
                :conditions => [
       -          'model_name = ? AND report_name = ? AND grouping = ? AND aggregation = ? AND `condition` = ? AND reporting_period >= ?',
       +          %w(model_name report_name grouping aggregation conditions).map do |column_name|
       +            "#{Saulabs::Reportable::ReportCache.connection.quote_column_name(column_name)} = ?"
       +          end.join(' AND ') + ' AND reporting_period >= ?',
                  @report.klass.to_s,
                  @report.name.to_s,
                  grouping.identifier.to_s,
 (DIR) diff --git a/spec/db/schema.rb b/spec/db/schema.rb
       @@ -13,7 +13,7 @@ ActiveRecord::Schema.define(:version => 1) do
            t.string   :report_name,      :null => false
            t.string   :grouping,         :null => false
            t.string   :aggregation,      :null => false
       -    t.string   :condition,        :null => false
       +    t.string   :conditions,       :null => false
            t.float    :value,            :null => false, :default => 0
            t.datetime :reporting_period, :null => false
        
       @@ -24,14 +24,14 @@ ActiveRecord::Schema.define(:version => 1) do
            :report_name,
            :grouping,
            :aggregation,
       -    :condition
       +    :conditions
          ], :name => :name_model_grouping_agregation
          add_index :reportable_cache, [
            :model_name,
            :report_name,
            :grouping,
            :aggregation,
       -    :condition,
       +    :conditions,
            :reporting_period
          ], :unique => true, :name => :name_model_grouping_aggregation_period