Welcome Guest, Not a member yet? Register   Sign In
SQL WHERE LIKE is being ignored in an ActiveRecord update??
#1

[eluser]Zoon[/eluser]
I've enabled profiling (and have it in a hidden DIV, which I toggle() usin jquery) and I'm running the following SQL query.

Code:
$this->db->select("netaddress, AddressId, NetCidr");
$this->db->from("net_ips");
$this->db->limit(10);
$query = $this->db->get();
        
if ($query->num_rows() > 0 )
{
    $result = $query->result_array();
    foreach ($result as $row)
    {
        $iprangeEx = explode('.', $row["netaddress"]);
        $update = array("netips_id" => $row["AddressId"]);
        $this->db->like("ip", "$iprangeEx[0].$iprangeEx[1].$iprangeEx[2]", "after");
        $this->db->where("NetID", $row["NetCidr"]);
        $this->db->update("addresses", $update);
    }
    return "Success";
}
The LIKE line is not being generated, example:

Code:
0.0001      SELECT `netaddress`, `AddressId`, `NetCidr`
FROM (`net_ips`)
LIMIT 10
0.2824      UPDATE `addresses` SET `netips_id` = '1' WHERE `NetID` = '1'
0.2730      UPDATE `addresses` SET `netips_id` = '2' WHERE `NetID` = '1'
0.2722      UPDATE `addresses` SET `netips_id` = '3' WHERE `NetID` = '1'
0.2847      UPDATE `addresses` SET `netips_id` = '4' WHERE `NetID` = '1'
0.2785      UPDATE `addresses` SET `netips_id` = '5' WHERE `NetID` = '1'
0.2694      UPDATE `addresses` SET `netips_id` = '6' WHERE `NetID` = '1'
0.2705      UPDATE `addresses` SET `netips_id` = '7' WHERE `NetID` = '1'
0.2696      UPDATE `addresses` SET `netips_id` = '8' WHERE `NetID` = '1'
0.2684      UPDATE `addresses` SET `netips_id` = '9' WHERE `NetID` = '1'
0.2696      UPDATE `addresses` SET `netips_id` = '10' WHERE `NetID` = '1'

If I change it from like to where
Code:
$iprangeEx = explode('.', $row["netaddress"]);
$update = array("netips_id" => $row["AddressId"]);
$this->db->where("ip", "$iprangeEx[0].$iprangeEx[1].$iprangeEx[2]", "after");
$this->db->where("NetID", $row["NetCidr"]);
$this->db->update("addresses", $update);
it is rendered, although that obviously doesn't do what I want it to do anyway.

Code:
0.0002      SELECT `netaddress`, `AddressId`, `NetCidr`
FROM (`net_ips`)
LIMIT 10
0.0004      UPDATE `addresses` SET `netips_id` = '1' WHERE `ip` = '172.24.0' AND `NetID` = '1'
0.0002      UPDATE `addresses` SET `netips_id` = '2' WHERE `ip` = '172.24.1' AND `NetID` = '1'
0.0002      UPDATE `addresses` SET `netips_id` = '3' WHERE `ip` = '172.24.2' AND `NetID` = '1'
0.0002      UPDATE `addresses` SET `netips_id` = '4' WHERE `ip` = '172.24.3' AND `NetID` = '1'
0.0002      UPDATE `addresses` SET `netips_id` = '5' WHERE `ip` = '172.24.4' AND `NetID` = '1'
0.0002      UPDATE `addresses` SET `netips_id` = '6' WHERE `ip` = '172.24.5' AND `NetID` = '1'
0.0002      UPDATE `addresses` SET `netips_id` = '7' WHERE `ip` = '172.24.6' AND `NetID` = '1'
0.0002      UPDATE `addresses` SET `netips_id` = '8' WHERE `ip` = '172.24.7' AND `NetID` = '1'
0.0001      UPDATE `addresses` SET `netips_id` = '9' WHERE `ip` = '172.24.8' AND `NetID` = '1'
0.0002      UPDATE `addresses` SET `netips_id` = '10' WHERE `ip` = '172.24.9' AND `NetID` = '1'

(This code is for a DB convertor, I'm writing an application which has to be data-compatible with an existing open source product we use, which doesn't have useful things like unique keys on half its tables, or any kind of relationship model to string it together.)

I could override this with a standard SQL query, but I prefer to use ActiveRecord...

What's going on? Sad


Messages In This Thread
SQL WHERE LIKE is being ignored in an ActiveRecord update?? - by El Forum - 09-24-2010, 04:13 AM



Theme © iAndrew 2016 - Forum software by © MyBB