xiidea / EasyAuditBundle

A Symfony Bundle To Log Selective Events
http://xiidea.github.io/EasyAuditBundle/
MIT License
89 stars 22 forks source link

Error an exception occurred while executing insert into #14

Closed braianj closed 6 years ago

braianj commented 6 years ago

I got this error when it try to insert into the audit_lo table

An exception occurred while executing 'INSERT INTO audit_log (id, type_id, type, description, event_time, user, impersonatingUser, ip) VALUES (?, ?, ?, ?, ?, ?, ?, ?)' with params [5, "security.interactive_login", "security.interactive_login", "security.interactive_login", "2017-11-22 12:56:48", "bmellor", null, "::1"]:

and this log

`Uncaught PHP Exception Doctrine\DBAL\Exception\SyntaxErrorException: "An exception occurred while executing 'INSERT INTO audit_log (id, type_id, type, description, event_time, user, impersonatingUser, ip) VALUES (?, ?, ?, ?, ?, ?, ?, ?)' with params [5, "security.interactive_login", "security.interactive_login", "security.interactive_login", "2017-11-22 12:56:48", "bmellor", null, "::1"]: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error in or close to «user» LINE 1: ..._log (id, type_id, type, description, event_time, user, impe... ^" at /project/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php line 70`
ronisaha commented 6 years ago

Could you please provide some more information. Like: Symfony version Php version EasyAuditBundle version

Best, if you can provide an example project to reproduce the bug.

braianj commented 6 years ago

Hi @ronisaha, here goes some info:

And the code is the same as the examples

ronisaha commented 6 years ago

Could you also share the entity class. Another question, are you using fos user bundle? If yes which version?

braianj commented 6 years ago

Also comment that i'm using postgreSQL 9.6

This is my entity

<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Xiidea\EasyAuditBundle\Entity\BaseAuditLog;

/**
 * @ORM\Entity
 * @ORM\Table(name="audit_log")
 */
class AuditLog extends BaseAuditLog
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * Type Of Event(Internal Type ID)
     *
     * @var string
     * @ORM\Column(name="type_id", type="string", length=200, nullable=false)
     */
    protected $typeId;

    /**
     * Type Of Event
     *
     * @var string
     * @ORM\Column(name="type", type="string", length=200, nullable=true)
     */
    protected $type;

    /**
     * @var string
     * @ORM\Column(name="description", type="string", length=255, nullable=true)
     */
    protected $description;

    /**
     * Time Of Event
     * @var \DateTime
     * @ORM\Column(name="event_time", type="datetime")
     */
    protected $eventTime;

    /**
     * @var string
     * @ORM\Column(name="user", type="string", length=255)
     */
    protected $user;

    /**
     * @var string
     * @ORM\Column(name="impersonatingUser", type="string", length=255)
     */
    protected $impersonatingUser;

    /**
     * @var string
     * @ORM\Column(name="ip", type="string", length=20, nullable=true)
     */
    protected $ip;    

}

And in order to make it work I need it to change the column user for user_name (it seems like user is a reserved name) and to set impersonatingUser as nullable=true, if not this throw me an error.

hacfi commented 6 years ago

@braianj Yup, user is a reserved keyword in Postgresql: https://www.postgresql.org/docs/9.6/static/sql-keywords-appendix.html

kl3sk commented 6 years ago

Same issue for impersonatingUser, i had to make it nullable in order to work properly.

Can someone explain me what is the goal and how works this property ?

ronisaha commented 6 years ago

Of course you need to make nullable the impersonatingUser property as it is an optional property. impersonatingUser is used when you enable impersonatingUser feature. The field will hold the original user value.

kl3sk commented 6 years ago

Okay thank you, it sounds obvious