Hi Phil,
First of all, great work, and great support.
I just switched over to DMZ for a project, and now I’m getting some strange behavior re: escaping of SQL functions. A bit of code using select_max() worked using DM but now is borked. I saw your last post on this topic (http://ellislab.com/forums/viewreply/699007/) and tried to implement the $this->func(‘FUNCNAME’, ‘@columnname’), but with no luck.
Here’s what I had at first, and the generated SQL:
class Measurement extends DataMapper
{
...
function get_max_timestamp($unix_timestamp = TRUE)
{
$this->select_max('timestamp')->get();
$this->load->helper('date');
return $unix_timestamp ? mysql_to_unix($this->timestamp) : $this->timestamp;
}
}
//SQL
SELECT `MAX(`measurements`.`timestamp`)` AS timestamp FROM (`measurements`)
//and got the error:
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 '`.`timestamp`)` AS timestamp FROM (`measurements`)' at line 1
I changed the select_max() to use select_func() but get:
$this->select_func('MAX', '@timestamp')->get();
//SQL
SELECT MAX() AS @timestamp FROM (`measurements`)
I also tried:
$this->select_func('MAX', 'timestamp')->get();
//SQL
SELECT MAX() AS timestamp FROM (`measurements`)
and finally:
$this->select_func('MAX(\'timestamp\')', 'timestamp')->get();
//SQL
SELECT MAX('timestamp')() AS timestamp FROM (`measurements`)
I ended up just using:
$this->select('MAX(`timestamp`)')->get();
but this seems less than preferable. Am I missing something obvious here?
Thanks!
Spike B