Monday, July 18, 2005

Let's Play Spot The Error


function save() {
global $db;

ob_start();

$args = array();

print 'UPDATE tbl_property';
print ' SET ';

if ($this->getAddress() !== null) {
$param[] = "add_id = ?";
$args[] = $this->getAddress();
}

if ($this->getZoneEffect() !== null) {
$param[] = "ppt_zone_effect = ?";
$args[] = $this->getZoneEffect();
}

if ($this->getZone() !== null) {
$param[] = "ppt_zone = ?";
$args[] = $this->getZone();
}

if ($this->getParent() !== null) {
$param[] = "ppt_parent_id = ?";
$args[] = $this->getParent();
}

if ($this->getLGA() !== null) {
$param[] = "lga_id = ?";
$args[] = $this->getLGA();
}

if ($this->getPT() !== null) {
$param[] = "pt_id = ?";
$args[] = $this->getPT();
}

if ($this->getAreaType() !== null) {
$param[] = "areatype_id = ?";
$args[] = $this->getAreaType();
}

if ($this->getArea() !== null) {
$param[] = "ppt_area = ?";
$args[] = $this->getArea();
}

if ($this->getCTFolio() !== null) {
$param[] = "ppt_ct_folio = ?";
$args[] = $this->getCTFolio();
}

if ($this->getCTVolume() !== null) {
$param[] = "ppt_ct_volume = ?";
$args[] = $this->getCTVolume();
}

if ($this->getLotNumber() !== null) {
$param[] = "ppt_lot_no = ?";
$args[] = $this->getLotNumber();
}

if ($this->getLocation() !== null) {
$param[] = "ppt_location = ?";
$args[] = $this->getLocation();
}

if ($this->getDimensions() !== null) {
$param[] = "ppt_dimensions = ?";
$args[] = $this->getDimensions();
}

if ($this->getIdentifiedBy() !== null) {
$param[] = "ppt_identified_by = ?";
$args[] = $this->getIdentifiedBy();
}

if ($this->getDepositedPlanNumber() !== null) {
$param[] = "ppt_deposited_plan_no = ?";
$args[] = $this->getDepositedPlanNumber();
}

if ($this->getNeighbourhoodDescription() !== null) {
$param[] = "ppt_neighbourhood_description = ?";
$args[] = $this->getNeighbourhoodDescription();
}

if ($this->getZoneInstrument() !== null)
$param[] = "ppt_zone_instrument = ?";
$args[] = $this->getZoneInstrument();


if ($this->getSiteDescription() !== null) {
$param[] = "ppt_site_description = ?";
$args[] = $this->getSiteDescription();
}


//glue together array pieces.
print implode(', ',@$param);

print ' WHERE ppt_id = ?';
$args[] = $this->getID();

$query = ob_get_clean();

if (count(@$param) > 0) {
$db->query($query, $args);
}

return true;
}




It's producing:
$args[0] = int
$args[1] = null
$args[2] = int

when it should produce:
$args[0] = int
$args[1] = int

Time wasted by me before spotting this error:
27 minutes.

Foolishness level:
High

Lesson learned:
Don't be stupid and use a different font in your text editor.

1 comment:

Anonymous said...

I concur!