Welcome Guest, Not a member yet? Register   Sign In
MySQL ActiveRecord - Protected identifier issue when updating?
#1

[eluser]gRoberts[/eluser]
hey all,

Because the model + active record setup works great for me, I have created a generic Model that all of my models extend.

This generic model exposes the ability to get a single row, all active, and save.

I've come across a problem (probably not related to how I do things) where when updating a record with a column which is a reserved word, it throws an error, yet it allowed me to insert that column in the first place.

For example, I have a column called "Key". This is a reserved word.

Code:
$tmp = new stdClass();
$tmp->SafeColumn = 'test';
$tmp->Key = 'test';
$this->db->insert('table', $tmp);

The above works... Yet:

Code:
$tmp = $this->model->GetSingle(1); // returns a stdClass
$tmp->SafeColumn = 'other value';
$this->db->update('table', $tmp, array('UniqueID' => $tmp->UniqueID));

returns an error

Code:
A Database Error Occurred

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Key = 'test', SafeColumn = 'other value' at line 1

UPDATE `table` SET UniqueID = '1', Key = 'test', SafeColumn = 'other value' WHERE `UniqueID` = '1'

Looking at the code, they both use _protect_identifiers to apparently escape the column names, but as you can see above, it isn't.

Have I simply missed a configuration somewhere that automatically handles this?

I've had a look through the DB_active_rec and mysql_driver files, but to be honest, my head is about to explode Sad

I'd really appreciate someone's input on this?

Cheers

Gavin


Messages In This Thread
MySQL ActiveRecord - Protected identifier issue when updating? - by El Forum - 08-05-2010, 07:22 AM



Theme © iAndrew 2016 - Forum software by © MyBB