# mautic:campaigns:trigger DBALException

**URL:** <https://forum.mautic.org/t/mautictrigger-dbalexception/2525>\
**Category:** Development\
**Created:** [October 16, 2015, 12:02pm UTC](https://forum.mautic.org/t/mautictrigger-dbalexception/2525 "2015-10-16T12:02:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![enzo](https://avatars.discourse-cdn.com/v4/letter/e/3ab097/32.png) [@enzo](https://forum.mautic.org/u/enzo)\
**Post date:** [October 16, 2015, 12:02pm UTC](https://forum.mautic.org/t/mautictrigger-dbalexception/2525/1 "2015-10-16T12:02:21Z")

</div>

php /var/www/mautic/app/console -f mautic:campaigns:trigger --env=prod  
  
  
  
[DoctrineDBALDBALException]  
  
An exception occurred while executing ‘SELECT e.lead\_id, e.event\_id, e.date\_triggered, e.is\_scheduled FROM campaign\_lead\_event\_log e WHERE (e.campaign\_id = 4) AND (e.lead\_id IN (32)) HAVING ((SELECT count(eh.event\_id) FROM campaign\_lead\_event\_log eh WHERE (eh.lead\_id = e.lead\_id) AND (eh.event\_id IN ())) \> 0) AND ((SELECT count(eh.event\_id) FROM campaign\_lead\_event\_log eh WHERE (eh.lead\_id = e.lead\_id) AND (eh.event\_id IN (13))) = 0)’:SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘))) \> 0) AND ((SELECT count(eh.event\_id) FROM campaign\_lead\_event\_log eh WHERE (’ at line 1  
  
  
  
[PDOException]  
  
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘))) \> 0) AND ((SELECT count(eh.event\_id) FROM campaign\_lead\_event\_log eh WHERE (’ at line 1  
  
  
  
This is how you can reproduce this error:  
  
  
  
Create a campaign  
  
Source: campaign form -\> Decision: submit form -\> (decision: yes) action: adjust lead points (decision: no) action: send email  
  
Then in Leads add a lead to the campaign  
  
  
  
During mautic:campaigns:trigger execution, triggerNegativeEvents() call $repo-\>getEventLog($campaignId, $campaignLeads, array($grandParentId), array\_keys($events)) with $grandParentId = NULL.  
  
In getEventLog $grandParentId is used inside the SQL query in “eh.event\_id IN ()” condition.  
  
  
  
  
  
To fix this error and to skip null array $havingEvents I changed this line in EventRepository.php:  
  
  
  
if (!empty($havingEvents)) {  
  
  
  
In:  
  
  
  
if (!empty($havingEvents) && !is\_null(current($havingEvents))) {

---

<div class="post-metadata">

**Author:** ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)\
**Post date:** [October 21, 2015, 10:19am UTC](https://forum.mautic.org/t/mautictrigger-dbalexception/2525/2 "2015-10-21T10:19:48Z")

</div>

[https://github.com/mautic/mautic/pull/906](https://github.com/mautic/mautic/pull/906) is not part of staging branch yet. Try this:

`git checkout -b escopecz-form_field_value_decision staging
git pull https://github.com/escopecz/mautic.git form_field_value_decision`

then clear cache and test again please.

---

<div class="post-metadata">

**Author:** ![enzo](https://avatars.discourse-cdn.com/v4/letter/e/3ab097/32.png) [@enzo](https://forum.mautic.org/u/enzo)\
**Post date:** [October 21, 2015, 2:19pm UTC](https://forum.mautic.org/t/mautictrigger-dbalexception/2525/3 "2015-10-21T14:19:55Z")

</div>

It works!

Triggering events for campaign 1  
Triggering first level events  
0 event(s) executed

Triggering scheduled events  
0 total events(s) to be processed in batches of 100  
0 event(s) executed

Triggering ‘non-action’ events  
1 total lead(s) to be analyzed in batches of 100  
0/1 [\>---------------------------] 0%  
1/1 [============================] 100%  
1 event(s) executed

---

<div class="post-metadata">

**Author:** ![enzo](https://avatars.discourse-cdn.com/v4/letter/e/3ab097/32.png) [@enzo](https://forum.mautic.org/u/enzo)\
**Post date:** [October 21, 2015, 10:15am UTC](https://forum.mautic.org/t/mautictrigger-dbalexception/2525/4 "2015-10-21T10:15:51Z")

</div>

Fresh install from staging branch, same error.

php app/console -f mautic:campaigns:trigger

Triggering events for campaign 1  
Triggering first level events  
0 event(s) executed

Triggering scheduled events  
0 total events(s) to be processed in batches of 100  
0 event(s) executed

Triggering ‘non-action’ events  
1 total lead(s) to be analyzed in batches of 100  
0/1 [\>---------------------------] 0%

[DoctrineDBALDBALException]  
An exception occurred while executing ‘SELECT e.lead\_id, e.event\_id, e.date\_triggered, e.is\_scheduled FROM campaign\_lead\_event\_log e WHERE (e.campaign\_id = 1) AND (e.lead\_id IN (1)) HAVING ((SELECT count(eh.event\_id) FR  
OM campaign\_lead\_event\_log eh WHERE (eh.lead\_id = e.lead\_id) AND (eh.event\_id IN ())) \> 0) AND ((SELECT count(eh.event\_id) FROM campaign\_lead\_event\_log eh WHERE (eh.lead\_id = e.lead\_id) AND (eh.event\_id IN (3))) = 0)’:  
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘))) \> 0) AND ((SELECT count(  
eh.event\_id) FROM campaign\_lead\_event\_log eh WHERE (’ at line 1

[PDOException]  
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘))) \> 0) AND ((SELECT count(  
eh.event\_id) FROM campaign\_lead\_event\_log eh WHERE (’ at line 1

mautic:campaigns:trigger [-i|–campaign-id[="…"]] [–scheduled-only] [–negative-only] [-l|–batch-limit[="…"]] [-m|–max-events[="…"]] [-f|–force]

---

<div class="post-metadata">

**Author:** ![enzo](https://avatars.discourse-cdn.com/v4/letter/e/3ab097/32.png) [@enzo](https://forum.mautic.org/u/enzo)\
**Post date:** [October 16, 2015, 12:02pm UTC](https://forum.mautic.org/t/mautictrigger-dbalexception/2525/5 "2015-10-16T12:02:21Z")

</div>

php /var/www/mautic/app/console -f mautic:campaigns:trigger --env=prod

[DoctrineDBALDBALException]  
An exception occurred while executing ‘SELECT e.lead\_id, e.event\_id, e.date\_triggered, e.is\_scheduled FROM campaign\_lead\_event\_log e WHERE (e.campaign\_id = 4) AND (e.lead\_id IN (32)) HAVING ((SELECT count(eh.event\_id) FROM campaign\_lead\_event\_log eh WHERE (eh.lead\_id = e.lead\_id) AND (eh.event\_id IN ())) \> 0) AND ((SELECT count(eh.event\_id) FROM campaign\_lead\_event\_log eh WHERE (eh.lead\_id = e.lead\_id) AND (eh.event\_id IN (13))) = 0)’:SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘))) \> 0) AND ((SELECT count(eh.event\_id) FROM campaign\_lead\_event\_log eh WHERE (’ at line 1

[PDOException]  
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘))) \> 0) AND ((SELECT count(eh.event\_id) FROM campaign\_lead\_event\_log eh WHERE (’ at line 1

This is how you can reproduce this error:

Create a campaign  
Source: campaign form -\> Decision: submit form -\> (decision: yes) action: adjust lead points (decision: no) action: send email  
Then in Leads add a lead to the campaign

During mautic:campaigns:trigger execution, triggerNegativeEvents() call $repo-\>getEventLog($campaignId, $campaignLeads, array($grandParentId), array\_keys($events)) with $grandParentId = NULL.  
In getEventLog $grandParentId is used inside the SQL query in “eh.event\_id IN ()” condition.

To fix this error and to skip null array $havingEvents I changed this line in EventRepository.php:

```
    if (!empty($havingEvents)) {

```

In:

```
    if (!empty($havingEvents) && !is_null(current($havingEvents))) {
```

---

<div class="post-metadata">

**Author:** ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)\
**Post date:** [October 19, 2015, 9:25am UTC](https://forum.mautic.org/t/mautictrigger-dbalexception/2525/6 "2015-10-19T09:25:46Z")

</div>

This issue might be solved by [https://github.com/mautic/mautic/pull/906](https://github.com/mautic/mautic/pull/906). If you use the GitHub version for development, please, test that pull request and write a comment.

---

<div class="post-metadata">

**Author:** ![silavapi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/silavapi/32/7424_2.png) [@silavapi](https://forum.mautic.org/u/silavapi)\
**Post date:** [February 2, 2020, 10:57pm UTC](https://forum.mautic.org/t/mautictrigger-dbalexception/2525/7 "2020-02-02T22:57:48Z")

</div>


