amavisd sql driver

[email protected] Wed, 24 Nov 2004 15:25:46 +0100
Newsgroups gmane.comp.horde.sam
Message-ID <[email protected]>
Hi,

I'm new on this list.

I'm looking on the sam amavisd-sql driver.

I think there's a little "bug" on the function _store() in
sam/lib/Driver/amavisd_sql.php

When we do :
 /* Check any additions to the lists. */
we always try to add every new email comming from the form in the senders=
 table
even if this email is already in the table.

As there is a unique key on the field email, pear return an error :=20
Cannot set options: DB Error: constraint violation

I have modified the driver to check if the email is already in the sender=
s=20
table :

      $query =3D sprintf('SELECT %s FROM %s WHERE %s =3D %s',
                       $this->_mapAttributeToField('senders', 'id'),
                       $this->_mapNameToTable('senders'),
                       $this->_mapAttributeToField('senders', 'email'),
                       $this->_db->quote($sender));
      $senderID =3D $this->_db->getOne($query);
      if (is_a($result, 'PEAR_Error')) {
          return $senderID;
      }
  =20
      if($senderID=3D=3D""){ */
                      // email address is not found so we add it
              $query =3D sprintf('INSERT INTO %s (%s) VALUES (%s)',
                       $this->_mapNameToTable('senders'),
                       $this->_mapAttributeToField('senders', 'email'),
                       $this->_db->quote($sender));

              $result =3D $this->_db->query($query);
              if (is_a($result, 'PEAR_Error')) {
                      return $result;
              }

              $query =3D sprintf('SELECT %s FROM %s WHERE %s =3D %s',
                       $this->_mapAttributeToField('senders', 'id'),
                       $this->_mapNameToTable('senders'),
                       $this->_mapAttributeToField('senders', 'email'),
                       $this->_db->quote($sender));
               $senderID =3D $this->_db->getOne($query);
              if (is_a($result, 'PEAR_Error')) {
                  return $senderID;
              }
      }


Perhaps the code  $senderID=3D=3D"" isn't very good in pear mode, but it =
was my
first time looking pear code.


Jean
--=20
sam mailing list - Join the hunt: http://horde.org/bounties/#sam
Frequently Asked Questions: http://horde.org/faq/
To unsubscribe, mail: [email protected]