File: 20-reinit_static_variable_when_switching_db_in_tests.patch

package info (click to toggle)
php-codeigniter-framework 3.1.13%2Bdfsg1-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,228 kB
  • sloc: php: 37,178; xml: 205; makefile: 138; python: 66; sh: 65
file content (30 lines) | stat: -rw-r--r-- 1,018 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Description: Reinitialize static variable when switching database
 In the tests, we run each test on the three supported DBMS (database systems)
 namely pgsql, mysql & sqlite3.
 .
 Codeigniter stores the escape characters in a static variable which never
 changes even when switching driver and hence use another DBMS. So it would
 use the escape character of the 1st DBMS with all subsequent engines.
 .
 This will reset the static variable when in testing environment and when
 the DBMS changed.
Author: Fab Stz <fabstz-it@yahoo.fr>
Last-Update: 2025-02-02

--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -1417,6 +1417,14 @@
 
 		static $preg_ec = array();
 
+		static $local_dbdriver = NULL;
+		if (ENVIRONMENT === 'testing' && $this->dbdriver !== $local_dbdriver)
+		{
+			$local_dbdriver = $this->dbdriver;
+			// Reinitialize static variable when switching to another database driver.
+			$preg_ec = array();
+		}
+
 		if (empty($preg_ec))
 		{
 			if (is_array($this->_escape_char))