Browse Source

Tweak fixture library to work with mysql and postgres

Timothy J. Warren 4 years ago
parent
commit
38d62f331c
1 changed files with 14 additions and 2 deletions
  1. 14
    2
      application/third_party/CIUnit/libraries/Fixture.php

+ 14
- 2
application/third_party/CIUnit/libraries/Fixture.php View File

@@ -31,7 +31,7 @@ class Fixture {
31 31
 		
32 32
 		// $fixt is supposed to be an associative array
33 33
 		// E.g. outputted by spyc from reading a YAML file
34
-		$this->CI->db->simple_query('TRUNCATE TABLE ' . $table . ' CASCADE;');
34
+		$this->truncate($table);
35 35
 
36 36
 		if ( ! empty($fixt))
37 37
 		{
@@ -49,7 +49,7 @@ class Fixture {
49 49
 		$this->_assign_db();
50 50
 
51 51
 		//$Q = TRUE;
52
-		$Q = $this->CI->db->simple_query('TRUNCATE TABLE ' . $table . ' CASCADE;');
52
+		$Q = $this->truncate($table);
53 53
 		
54 54
 		if (!$Q) {
55 55
 			echo $this->CI->db->call_function('error', $this->CI->db->conn_id);
@@ -78,6 +78,18 @@ class Fixture {
78 78
 		}
79 79
 	}
80 80
 
81
+	private function truncate($table)
82
+	{
83
+		$sql = 'TRUNCATE TABLE ' . $table;
84
+
85
+		if (getenv('DB') !== 'mysql')
86
+		{
87
+			$sql .= ' CASCADE';
88
+		}
89
+
90
+		return $this->CI->db->simple_query($sql);
91
+	}
92
+
81 93
 }
82 94
 
83 95
 /* End of file Fixture.php */