0

私は現在、休止状態のクエリを実行する必要があるgrailsプロジェクトに取り組んでいます。データベース上の既存のデータを使用してコードを実行するたびに、すべてが正常に機能します。しかし、データベースを空にして実行すると、エラーがスローされます。

これは私のコードです:

    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

メッセージ:

サブツリーの予期しない終了[selectsum(case when l.details like'%Gender:Male。%' and l.event =:actActivationEvent then 1 else 0 end)、sum(case when l.details like'%Gender:Female。 %'および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())or(l.username in()or l.username in()))then 1 else 0 end)、sum(case when l.details like ' %Gender:Female。%'and l.event =:actFinishRegEvent and((l.username not in())or(l.username in()or l.username in()))then 1 else 0 end)、sum (l.event =:actFinishRegEvent and((l.username not in())or(l.username in()or l.username in()))then 1 else 0 end)、sum(casewhenl。 '%Gender:Male。%'などの詳細および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(casewhenl。 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 ph.gov.csc.comex.log.AuditLog lここで、l.dateCreated> =:startDateおよびl.dateCreated <:endDate]%Gender:Male。%'and l.event =:actPurgedEvent then 1 else 0 end)、sum(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 ph.gov.csc.comex.log.AuditLog l where l.dateCreated> =:startDate and l.dateCreated <:endDate]%Gender:Male。%'and l.event =:actPurgedEvent then 1 else 0 end)、sum(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 ph.gov.csc.comex.log.AuditLog l where l.dateCreated> =:startDate and l.dateCreated <:endDate]

これをどのように解決しますか?助けてください!ありがとう!

4

1 に答える 1

2

問題は、最初の3つのクエリの結果を最後のクエリの引数として盲目的に渡すという事実に起因します。これにより、以下を含むwhere句が生成されます。

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

これは無効です。in ()句には、括弧内に少なくとも1つの要素が含まれている必要があります。in句に引数として渡すリストの1つが空の場合は、別のクエリを使用する必要があります。

于 2012-06-26T10:31:21.667 に答える