Tweak fixture library to work with mysql and postgres

This commit is contained in:
Timothy Warren 2014-08-13 11:55:50 -04:00
父節點 8400ee2a5c
當前提交 38d62f331c
共有 1 個檔案被更改,包括 14 行新增2 行删除

查看文件

@ -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 */