From 7ec67517162cd3ca70381e194f91191d2eb329ce Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 5 Sep 2021 15:42:11 +0000 Subject: [PATCH] refactored the sqlite databse hack for foreign keys support --- codepot/src/system/database/DB_driver.php | 15 ++++++++++++++- .../system/database/drivers/oci8/oci8_driver.php | 7 +++++++ .../system/database/drivers/pdo/pdo_driver.php | 11 +++++++++++ .../database/drivers/sqlite/sqlite_driver.php | 9 ++++++++- 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/codepot/src/system/database/DB_driver.php b/codepot/src/system/database/DB_driver.php index a9b0a643..96907786 100644 --- a/codepot/src/system/database/DB_driver.php +++ b/codepot/src/system/database/DB_driver.php @@ -150,7 +150,9 @@ class CI_DB_driver { return FALSE; } - return TRUE; + // HYUNG-HWAN + //return TRUE; + // END HYUNG-HWAN } } @@ -161,9 +163,20 @@ class CI_DB_driver { $this->_execute('PRAGMA foreign_keys=ON'); } + // HYUNG-HWAN + $this->db_post_initialize (); + // END HYUNG-HWAN + return TRUE; } + // HYUNG-HWAN + function db_post_initialize () + { + return TRUE; + } + // END HYUNG-HWAN + // -------------------------------------------------------------------- /** diff --git a/codepot/src/system/database/drivers/oci8/oci8_driver.php b/codepot/src/system/database/drivers/oci8/oci8_driver.php index 0728a779..73bcce0f 100644 --- a/codepot/src/system/database/drivers/oci8/oci8_driver.php +++ b/codepot/src/system/database/drivers/oci8/oci8_driver.php @@ -141,6 +141,13 @@ class CI_DB_oci8_driver extends CI_DB { return TRUE; } + // HYUNG-HWAN + function db_post_initialize () + { + $this->query ("ALTER SESSION SET NLS_TIMESTAMP_FORMAT='YYYY-MM-DD HH24:MI:SS.FF'"); + } + // END HYUNG-HWAN + // -------------------------------------------------------------------- /** diff --git a/codepot/src/system/database/drivers/pdo/pdo_driver.php b/codepot/src/system/database/drivers/pdo/pdo_driver.php index cebea198..29b2cd01 100644 --- a/codepot/src/system/database/drivers/pdo/pdo_driver.php +++ b/codepot/src/system/database/drivers/pdo/pdo_driver.php @@ -237,6 +237,17 @@ class CI_DB_pdo_driver extends CI_DB { return TRUE; } + + // HYUNG-HWAN - hack to enable foreign keys support in sqlite + function db_post_initialize () + { + if (preg_match("/^sqlite/", $this->hostname)) + { + $this->_execute('PRAGMA foreign_keys=ON'); + } + } + // END HYUNG-HWAN + // -------------------------------------------------------------------- /** diff --git a/codepot/src/system/database/drivers/sqlite/sqlite_driver.php b/codepot/src/system/database/drivers/sqlite/sqlite_driver.php index 26230138..bc259dfa 100644 --- a/codepot/src/system/database/drivers/sqlite/sqlite_driver.php +++ b/codepot/src/system/database/drivers/sqlite/sqlite_driver.php @@ -143,6 +143,13 @@ class CI_DB_sqlite_driver extends CI_DB { return TRUE; } + // HYUNG-HWAN - hack to enable foreign keys support in sqlite + function db_post_initialize () + { + $this->_execute('PRAGMA foreign_keys=ON'); + } + // END HYUNG-HWAN + // -------------------------------------------------------------------- /** @@ -656,4 +663,4 @@ class CI_DB_sqlite_driver extends CI_DB { /* End of file sqlite_driver.php */ -/* Location: ./system/database/drivers/sqlite/sqlite_driver.php */ \ No newline at end of file +/* Location: ./system/database/drivers/sqlite/sqlite_driver.php */