Tweak fixture library to work with mysql and postgres

This commit is contained in:
Timothy Warren 2014-08-13 11:55:50 -04:00
parent 8400ee2a5c
commit 38d62f331c

View File

@ -31,7 +31,7 @@ class Fixture {
// $fixt is supposed to be an associative array
// E.g. outputted by spyc from reading a YAML file
$this->CI->db->simple_query('TRUNCATE TABLE ' . $table . ' CASCADE;');
$this->truncate($table);
if ( ! empty($fixt))
{
@ -49,7 +49,7 @@ class Fixture {
$this->_assign_db();
//$Q = TRUE;
$Q = $this->CI->db->simple_query('TRUNCATE TABLE ' . $table . ' CASCADE;');
$Q = $this->truncate($table);
if (!$Q) {
echo $this->CI->db->call_function('error', $this->CI->db->conn_id);
@ -78,6 +78,18 @@ class Fixture {
}
}
private function truncate($table)
{
$sql = 'TRUNCATE TABLE ' . $table;
if (getenv('DB') !== 'mysql')
{
$sql .= ' CASCADE';
}
return $this->CI->db->simple_query($sql);
}
}
/* End of file Fixture.php */