Menu

#23 vacation table insertion problems

open
Jasper
5
2010-10-18
2010-10-08
No

Insertions into the vacation table fail for several reasons:

1. The number of placeholders do not match the number of elements passed.
2. The fields and their order is not defined in the INSERT. This means that minor changes to the table will cause failures.
3. Postgresql does not allow you to set a boolean field to "1". The value passed must be "true".
4. (concerning the UPDATE) it is not necessary to change the value of the email field in the UPDATE.

The following changes to virtual.class.php seem to fix these problems for me:
if (!$update) {
- $sql = "INSERT INTO {$this->cfg['dbase']}.vacation VALUES (?,?,?,'',?,NOW(),1)";
+ $sql = "INSERT INTO vacation (email, subject, body, created, active, domain) VALUES (?,?,?,NOW(),true,?)";
+ $this->db->query($sql, Q($this->user->data['username']), $this->subject, $this->body, $this->domain);
} else {
- $sql = "UPDATE {$this->cfg['dbase']}.vacation SET email=?,subject=?,body=?,domain=?,active=1 WHERE email=?";
+ $sql = "UPDATE vacation SET subject=?,body=?,domain=?,active=true WHERE email=?";
+ $this->db->query($sql, $this->subject, $this->body, $this->domain,Q($this->user->data['username']));
}

-
- $this->db->query($sql, Q($this->user->data['username']), $this->subject, $this->body, $this->domain,Q($this->user->data['username']));

Discussion

  • Peter Ajamian

    Peter Ajamian - 2010-10-18

    Any response on this?

     
  • Peter Ajamian

    Peter Ajamian - 2010-10-18
    • assigned_to: nobody --> jaspersl
     

Log in to post a comment.