Welcome Guest, Not a member yet? Register   Sign In
UPDATE being performed after INSERT, bug?
#1

[eluser]M52 Studios[/eluser]
Hello everyone!

I have the strangest problem that I haven't ran across before.

I even separated what was once in the single "engine" function into three separate once, but still to no avail. Basically, I have to mark instances as deleted in the database before inserting new ones. But what the code in fact does, is INSERTS first, and only then UPDATES, which marks the new insertions as deleted. I am able to see this in the database, as I have created timestamped and then I timestamp the deletion, as well, and they are usually one millisecond apart.

Has anyone seen this before? This has been breaking my head for about 4 hours now. I've tried caching the query, starting and ending transaction, but nothing worked. It still inserts first, even though it's clear that insertion is after updating in the code.

Code:
public function engine($id, $post)
{
// First, mark all occurrences in the database deleted
$this->delete($id);

// Now let's insert 'new' affiliations
if(!empty($post['affiliate']))
{
  $this->insert($id, $post['affiliate']);
}
}


public function delete($id)
{
$this->db->set("deleted", "CURRENT_TIMESTAMP", FALSE);
$this->db->where("entity", $id);
$this->db->where("deleted", NULL);
$this->db->update("table");
}


public function insert($id, $vars)
{
foreach($vars as $row)
{
  $this->db->set("entity", $id);
  $this->db->set("affiliate", $row);
  $this->db->insert("table");
}
}

Thank you in advance for your help!!!

EDIT: grammatical errors
#2

[eluser]M52 Studios[/eluser]
Something else that is interesting:

When I'm running profiler, the insertion doesn't even appear in the Queries list, even though it is clearly happening in the database...




Theme © iAndrew 2016 - Forum software by © MyBB