From a457a516383ca97d21fb5c9076eaa2d3457af5e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Laverr=C3=A9?= Date: Tue, 10 Sep 2019 21:46:44 +0200 Subject: [PATCH 1/7] Insensitive search string --- src/Mysqli/MysqliImporter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mysqli/MysqliImporter.php b/src/Mysqli/MysqliImporter.php index 0e0d9ef50..79a8cfc6c 100644 --- a/src/Mysqli/MysqliImporter.php +++ b/src/Mysqli/MysqliImporter.php @@ -298,7 +298,7 @@ protected function getColumnSql(\SimpleXMLElement $field) else { // TODO Don't quote numeric values. - if (strpos($fDefault, 'CURRENT') !== false) + if (stristr($fDefault, 'CURRENT') !== false) { $sql .= ' NOT NULL DEFAULT CURRENT_TIMESTAMP()'; } From 56b2dc577d78aed608181cb0cc9dae0d7c632996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Laverr=C3=A9?= Date: Wed, 11 Sep 2019 10:24:04 +0200 Subject: [PATCH 2/7] Insensitive search current --- src/Mysql/MysqlImporter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mysql/MysqlImporter.php b/src/Mysql/MysqlImporter.php index 3fc416fcb..3a2fcad2b 100644 --- a/src/Mysql/MysqlImporter.php +++ b/src/Mysql/MysqlImporter.php @@ -259,7 +259,7 @@ protected function getColumnSql(\SimpleXMLElement $field) else { // TODO Don't quote numeric values. - if (strpos($fDefault, 'CURRENT') !== false) + if (stristr($fDefault, 'CURRENT') !== false) { $sql .= ' NOT NULL DEFAULT CURRENT_TIMESTAMP()'; } From a3d74ab4c47844118bdf697423be2cba423d530a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Laverr=C3=A9?= Date: Wed, 11 Sep 2019 20:59:22 +0200 Subject: [PATCH 3/7] Insert null integer fields --- src/Mysql/MysqlDriver.php | 6 ++++++ src/Mysqli/MysqliDriver.php | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/Mysql/MysqlDriver.php b/src/Mysql/MysqlDriver.php index 84ef4be64..ca960dd4c 100644 --- a/src/Mysql/MysqlDriver.php +++ b/src/Mysql/MysqlDriver.php @@ -649,6 +649,12 @@ public function insertObject($table, &$object, $key = null) continue; } + // Ignore null integer fields. + if (stristr($tableColumns[$k], 'int') !== FALSE && $v === '') + { + continue; + } + // Prepare and sanitize the fields and values for the database query. $fields[] = $this->quoteName($k); $values[] = $this->quote($v); diff --git a/src/Mysqli/MysqliDriver.php b/src/Mysqli/MysqliDriver.php index 33815e7b4..e21a0ad27 100644 --- a/src/Mysqli/MysqliDriver.php +++ b/src/Mysqli/MysqliDriver.php @@ -749,6 +749,12 @@ public function insertObject($table, &$object, $key = null) continue; } + // Ignore null integer fields. + if (stristr($tableColumns[$k], 'int') !== FALSE && $v === '') + { + continue; + } + // Prepare and sanitize the fields and values for the database query. $fields[] = $this->quoteName($k); $values[] = $this->quote($v); From a3d9842ba4d88133235d4ab3525c0b085a8b624f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Laverr=C3=A9?= Date: Wed, 11 Sep 2019 21:47:33 +0200 Subject: [PATCH 4/7] Keep default cast values --- src/Pgsql/PgsqlDriver.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Pgsql/PgsqlDriver.php b/src/Pgsql/PgsqlDriver.php index 8bb5f82e7..9d7401d51 100644 --- a/src/Pgsql/PgsqlDriver.php +++ b/src/Pgsql/PgsqlDriver.php @@ -253,12 +253,6 @@ public function getTableColumns($table, $typeOnly = true) $field->Default = null; } - // Normalise default values like datetime - if (preg_match('/^\'(.*)\'::.*/', $field->Default, $matches)) - { - $field->Default = $matches[1]; - } - // Do some dirty translation to MySQL output. // @todo: Come up with and implement a standard across databases. $result[$field->column_name] = (object) [ From 132bb1b0fba49de36cc5e165c4986df47b849ee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Laverr=C3=A9?= Date: Wed, 11 Sep 2019 22:22:33 +0200 Subject: [PATCH 5/7] Test: add cast for datetime --- Tests/Pgsql/PgsqlDriverTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Pgsql/PgsqlDriverTest.php b/Tests/Pgsql/PgsqlDriverTest.php index 65b35452b..68efbf055 100644 --- a/Tests/Pgsql/PgsqlDriverTest.php +++ b/Tests/Pgsql/PgsqlDriverTest.php @@ -379,7 +379,7 @@ public function testGetTableColumns() $end_date->Type = 'timestamp without time zone'; $end_date->null = 'NO'; $end_date->Null = 'NO'; - $end_date->Default = '1970-01-01 00:00:00'; + $end_date->Default = "'1970-01-01 00:00:00'::timestamp without time zone"; $end_date->comments = ''; $description = new \stdClass; From a2fa8143025a5455e5474fa5793bd6eae0658b88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Laverr=C3=A9?= Date: Sun, 20 Oct 2019 20:25:57 +0200 Subject: [PATCH 6/7] Remove postgreSQL Fix. Normalise default values like timestamp (Pgsql). --- Tests/Pgsql/PgsqlDriverTest.php | 2 +- src/Pgsql/PgsqlDriver.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Tests/Pgsql/PgsqlDriverTest.php b/Tests/Pgsql/PgsqlDriverTest.php index 68efbf055..65b35452b 100644 --- a/Tests/Pgsql/PgsqlDriverTest.php +++ b/Tests/Pgsql/PgsqlDriverTest.php @@ -379,7 +379,7 @@ public function testGetTableColumns() $end_date->Type = 'timestamp without time zone'; $end_date->null = 'NO'; $end_date->Null = 'NO'; - $end_date->Default = "'1970-01-01 00:00:00'::timestamp without time zone"; + $end_date->Default = '1970-01-01 00:00:00'; $end_date->comments = ''; $description = new \stdClass; diff --git a/src/Pgsql/PgsqlDriver.php b/src/Pgsql/PgsqlDriver.php index 9d7401d51..8bb5f82e7 100644 --- a/src/Pgsql/PgsqlDriver.php +++ b/src/Pgsql/PgsqlDriver.php @@ -253,6 +253,12 @@ public function getTableColumns($table, $typeOnly = true) $field->Default = null; } + // Normalise default values like datetime + if (preg_match('/^\'(.*)\'::.*/', $field->Default, $matches)) + { + $field->Default = $matches[1]; + } + // Do some dirty translation to MySQL output. // @todo: Come up with and implement a standard across databases. $result[$field->column_name] = (object) [ From 95a00f0eec6172f540486878c1ad19dd22adf0df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Laverr=C3=A9?= Date: Sun, 20 Oct 2019 20:43:13 +0200 Subject: [PATCH 7/7] false must be lowercase (Travis) --- src/Mysql/MysqlDriver.php | 2 +- src/Mysqli/MysqliDriver.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Mysql/MysqlDriver.php b/src/Mysql/MysqlDriver.php index ca960dd4c..ff244b061 100644 --- a/src/Mysql/MysqlDriver.php +++ b/src/Mysql/MysqlDriver.php @@ -650,7 +650,7 @@ public function insertObject($table, &$object, $key = null) } // Ignore null integer fields. - if (stristr($tableColumns[$k], 'int') !== FALSE && $v === '') + if (stristr($tableColumns[$k], 'int') !== false && $v === '') { continue; } diff --git a/src/Mysqli/MysqliDriver.php b/src/Mysqli/MysqliDriver.php index e21a0ad27..bff89a1fe 100644 --- a/src/Mysqli/MysqliDriver.php +++ b/src/Mysqli/MysqliDriver.php @@ -750,7 +750,7 @@ public function insertObject($table, &$object, $key = null) } // Ignore null integer fields. - if (stristr($tableColumns[$k], 'int') !== FALSE && $v === '') + if (stristr($tableColumns[$k], 'int') !== false && $v === '') { continue; }