# Icingaweb2 director SQLSTATE\[42000\]: Syntax error on editing services

**URL:** <https://community.icinga.com/t/icingaweb2-director-sqlstate-42000-syntax-error-on-editing-services/14382>\
**Category:** Icinga Director\
**Created:** [December 13, 2024, 9:51am UTC](https://community.icinga.com/t/icingaweb2-director-sqlstate-42000-syntax-error-on-editing-services/14382 "2024-12-13T09:51:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![andyb2000](https://community.icinga.com/user_avatar/community.icinga.com/andyb2000/32/2697_2.png) [@andyb2000](https://community.icinga.com/u/andyb2000)\
**Post date:** [December 13, 2024, 9:51am UTC](https://community.icinga.com/t/icingaweb2-director-sqlstate-42000-syntax-error-on-editing-services/14382/1 "2024-12-13T09:51:42Z")

</div>

I’m crossposting this here as it’s more of an issue in director than it is icingaweb2 itself I suspect.

My other post:  
[https://community.icinga.com/t/icingaweb2-sqlstate-syntax-error-on-modify-a-service-for-director/14375](https://community.icinga.com/t/icingaweb2-sqlstate-syntax-error-on-modify-a-service-for-director/14375)

Shows the issue, it appears to be in code:

/usr/share/icingaweb2/modules/director/library/Director/DataType/DataTypeDatalist.php  
Where the $this-\>getSetting(‘datalist\_id’) is not returning a value and causing an SQL exception.  
I commented this out as a quick test:

```auto
    protected function getEntries(QuickForm $form)
    {
        /** @var DirectorObjectForm $form */
        $db = $form->getDb()->getDbAdapter();
        $roles = Acl::instance()->listRoleNames();
        $select = $db->select()
            ->from('director_datalist_entry', ['entry_name', 'entry_value'])
// ->where('list_id = ?', $this->getSetting('datalist_id'))
            ->order('entry_value ASC');

        if (empty($roles)) {
            $select->where('allowed_roles IS NULL');
        } else {
            $parts = ['allowed_roles IS NULL'];
            foreach ($roles as $role) {
                $parts[] = $db->quoteInto("allowed_roles LIKE ?", '%' . \json_encode($role) . '%');
            }
            $select->where('(' . \implode(' OR ', $parts) . ')');
        }

        return $db->fetchPairs($select);
    }

```

which worked.  
I don’t have any datalist’s defined so this is probably the issue, has a check somewhere been missed?

---

<div class="post-metadata">

**Author:** ![apenning](https://community.icinga.com/user_avatar/community.icinga.com/apenning/32/7669_2.png) [@apenning](https://community.icinga.com/u/apenning)\
**Post date:** [January 7, 2025, 9:44am UTC](https://community.icinga.com/t/icingaweb2-director-sqlstate-42000-syntax-error-on-editing-services/14382/2 "2025-01-07T09:44:21Z")

</div>

Thanks for your detailed bug report! I have created an issue in the Director’s bug tracker to make the Director developers aware of this.

> <https://github.com/Icinga/icingaweb2-module-director/issues/2948>
>
> This is a cross post from the Icinga Community forum:
> \- https://community.icing…a.com/t/icingaweb2-sqlstate-syntax-error-on-modify-a-service-for-director/14375
> \- https://community.icinga.com/t/icingaweb2-director-sqlstate-42000-syntax-error-on-editing-services/14382/1
> 
> The reporter experienced the following error when using Icinga Director:
> \`\`\`
> 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 '?) AND ((allowed\_roles IS NULL OR allowed\_roles LIKE '%\\"Administrators\\"%' OR a' at line 1, query was: SELECT director\_datalist\_entry.entry\_name, director\_datalist\_entry.entry\_value FROM director\_datalist\_entry WHERE (list\_id = ?) AND ((allowed\_roles IS NULL OR allowed\_roles LIKE '%\\"Administrators\\"%' OR allowed\_roles LIKE '%\\"nops\\"%')) ORDER BY entry\_value ASC
> \`\`\`
> 
> As outlined in the second post, \`$this-\>getSetting('datalist\_id')\` seems to be empty in their setup, resulting in an invalid query. The reporter's quick fix was by removing the \`WHERE\` clause from the query.
> 
> https://github.com/Icinga/icingaweb2-module-director/blob/de8fe109e2f1dfb92059370ffeefa625e1144a10/library/Director/DataType/DataTypeDatalist.php#L98-L101
