プロジェクト

全般

プロフィール

Vote #68144

完了

Error in SQL

Admin Redmine さんが約4年前に追加. 約4年前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
Code cleanup/refactoring_30
対象バージョン:
開始日:
2010/09/16
期日:
進捗率:

100%

予定工数:
category_id:
30
version_id:
24
issue_org_id:
6413
author_id:
3217
assigned_to_id:
1188
comments:
3
status_id:
5
tracker_id:
1
plus1:
0
affected_version:
closed_on:
affected_version_id:
21
ステータス-->[Closed]

説明

Hi all!

I am using redmine and having an SQL error when trying to get the issues resume inside a project.

Environment:

Ruby 1.8.7 pathlevel 249)
Rails 2.3.5
Oracle (yes, I know it's not supported but the solution below seems so easy and won't cause regression I think)

The error is in the SQL executed in the file app/models/issue.rb, line 828:
Where now is

def self.count_and_group_by(options)
    project = options.delete(:project)
    select_field = options.delete(:field)
    joins = options.delete(:joins)

    where = "i.#{select_field}=j.id"
    
    ActiveRecord::Base.connection.select_all("select    s.id as status_id, 
                                                s.is_closed as closed, 
                                                j.id as #{select_field},
                                                count(i.id) as total 
                                              from 
                                                  #{Issue.table_name} i, #{IssueStatus.table_name} s, #{joins} as j
                                              where 
                                                i.status_id=s.id 
                                                and #{where}
                                                and i.project_id=#{project.id}
                                              group by s.id, s.is_closed, j.id")
  end

it should be

def self.count_and_group_by(options)
    project = options.delete(:project)
    select_field = options.delete(:field)
    joins = options.delete(:joins)

    where = "i.#{select_field}=j.id"
    
    ActiveRecord::Base.connection.select_all("select    s.id as status_id, 
                                                s.is_closed as closed, 
                                                j.id as #{select_field},
                                                count(i.id) as total 
                                              from 
                                                  #{Issue.table_name} i, #{IssueStatus.table_name} s, #{joins}  j
                                              where 
                                                i.status_id=s.id 
                                                and #{where}
                                                and i.project_id=#{project.id}
                                              group by s.id, s.is_closed, j.id")
  end

The "as j" in the SQL query is wrong and causes SQL error. Deleting "as" makes it working ok.


journals

Eric, JB: seems ok to me, anyone of you could commit this?
--------------------------------------------------------------------------------
It was introduced with r3365 : before this refactoring, there was no "as" word in "from" clauses. So we can be sure there won't be any regression, thanks for pointing this out (and reviewing!). Committed in r4091
--------------------------------------------------------------------------------
Merged into 1.0-stable for release in 1.0.2
--------------------------------------------------------------------------------

Admin Redmine さんが約4年前に更新

  • カテゴリCode cleanup/refactoring_30 にセット
  • 対象バージョン1.0.2_24 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0