2012-06-26 2 views
0

현재 최대 절전 모드 쿼리를 실행해야하는 grails 프로젝트를 만들고 있습니다. 데이터베이스의 기존 데이터로 코드를 실행할 때마다 모든 것이 잘 작동합니다. 그러나 데이터베이스를 비우면서 실행하면 오류가 발생합니다. 나는 빈 데이터베이스와 코드를 실행할 때grails의 Hibernate Query Language

def actActivation = AuditLog.executeQuery("select ll.username from AuditLog ll where ll.event = ? ",[AuditLogEvent.ACCOUNT_ACTIVATION]) 
    def actDeleted = AuditLog.executeQuery("select ll.username from AuditLog ll where ll.event = ? ",[AuditLogEvent.ACCOUNT_DELETION]) 
    def actPurged = AuditLog.executeQuery("select ll.username from AuditLog ll where ll.event = ? ",[AuditLogEvent.ACCOUNT_PURGING]) 
    def list = AuditLog.executeQuery("""select sum(case when l.details like '%Gender: Male.%' and l.event = :actActivationEvent then 1 else 0 end), 
      sum(case when l.details like '%Gender: Female.%' and l.event = :actActivationEvent then 1 else 0 end), 
      sum(case when l.event = :actActivationEvent then 1 else 0 end), 
      sum(case when l.details like '%Gender: Male.%' and l.event = :actFinishRegEvent and ((l.username not in(:actActivation)) or (l.username in(:actDeleted) or l.username in(:actPurged))) then 1 else 0 end), 
      sum(case when l.details like '%Gender: Female.%' and l.event = :actFinishRegEvent and ((l.username not in(:actActivation)) or (l.username in(:actDeleted) or l.username in(:actPurged))) then 1 else 0 end), 
      sum(case when l.event = :actFinishRegEvent and ((l.username not in(:actActivation)) or (l.username in(:actDeleted) or l.username in(:actPurged))) then 1 else 0 end), 
      sum(case when l.details like '%Gender: Male.%' and l.event = :actDeletionEvent then 1 else 0 end), 
      sum(case when l.details like '%Gender: Female.%' and l.event = :actDeletionEvent then 1 else 0 end), 
      sum(case when l.event = :actDeletionEvent then 1 else 0 end), 
      sum(case when l.details like '%Gender: Male.%' and l.event = :actPurgedEvent then 1 else 0 end), 
      sum(case when l.details like '%Gender: Female.%' and l.event = :actPurgedEvent then 1 else 0 end), 
      sum(case when l.event = :actPurgedEvent then 1 else 0 end)     
     from AuditLog l 
     where l.dateCreated >= :startDate and l.dateCreated < :endDate""", 
     [ 
      actActivationEvent:AuditLogEvent.ACCOUNT_ACTIVATION, 
      actDeletionEvent:AuditLogEvent.ACCOUNT_DELETION, 
      actPurgedEvent:AuditLogEvent.ACCOUNT_PURGING, 
      actFinishRegEvent:AuditLogEvent.FINISH_REGISTRATION, 
      actActivation:actActivation, 
      actDeleted:actDeleted, 
      actPurged:actPurged, 
      startDate: startDate, 
      endDate:endDate 
     ]) 

이 오류 메시지입니다 :

이 내 코드입니다.

등급 : org.hibernate.hql.ast.QuerySyntaxException

메시지 :

하위 트리 [선택 합 (사건의

예기치 않은 종료 할 때와 같은 l.details '% 성별 :. 남성 %'와 l.event = : actActivationEvent, then 1 else 0 end), sum (l.details가 '% 성별 : 여성. %'및 l.event = : actActivationEvent, 1 else 0 end와 같은 경우), sum (l.event = : actActivationEvent, then 1 else 0 end), 합계 ('% 성별 : 남성. %'및 l.event = : actFinishRegEvent 및 ((.() 또는 l.username in())) then 1 else 0 end), sum (l.details가 '% 성별 : 여성. %'와 같은 경우) 및 l.event = : actFinishRegEvent 및 ((l.username in()) 또는 (l.username in() 또는 l.username in())) 다음 1 else 0 end), sum : actFinishRegEvent와 ((l.username not in()) 또는 (l.username in() 또는 l.username in())) 다음 1 else 0 end), sum (l.details가 '% 성별 : 남성 (예 : '% 성별 : 여성. %'및 l.event = : actDeletionEvent, 1 else else end), sum (대/소문자 구분) l.event = : actDeletionEvent, then 1 else 0 end), 합계 (l.details가 '% 성별 : 남성. %'및 l.event = : actPurgedEvent, 1 else else end와 같은 경우), sum ph.gov.csc.comex.log에서 '% 성별 : 여성. %'및 l.event = : actPurgedEvent, 그 다음 1 else 0 end), sum (l.event = : actPurgedEvent, 1 else else end와 같은 세부 정보) .AuditLog l 어디 l.dateCreated> = : startDate 및 l.dateCreated < : endDate]

어떻게 해결할 수 있습니까? 도와주세요! 감사!

답변

2

문제는 3 개의 첫 번째 쿼리 결과를 마지막 쿼리의 인수로 맹목적으로 전달한다는 점에서 비롯됩니다. 이것은 포함하는 WHERE 절 결과 : 잘못된

where ... l.username not in() ... 

합니다. in() 절에는 적어도 괄호 안에 하나의 요소가 있어야합니다. in 절에 인수로 전달한 목록 중 하나가 비어 있으면 다른 쿼리를 사용해야합니다.

+0

정말 고마워요! 이것은 정말로 도움이되었습니다! – chemilleX3