From d29068556c28e382039f6e8249a8af416fa5413e Mon Sep 17 00:00:00 2001
From: Morton Jonuschat <m.jonuschat@mojocode.de>
Date: Sun, 14 Jun 2015 20:58:12 +0200
Subject: [PATCH] [BUGFIX] ADOdb: support NOT NULL/DEFAULT field attributes on
 BLOB/TEXT fields

Instead of globally disallowing NOT NULL and DEFAULT field attributes
make these attributes configurable per DBMS system.

Data dictionaries for PostgreSQL and MySQL are adjusted to match
the supported options.

Resolves: #67442
Releases: master
Change-Id: Ic0fb7a07ef4db9fc854489165ebc079382c2f011
Reviewed-on: http://review.typo3.org/40398
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
---
 typo3/sysext/adodb/Documentation/Index.rst    |  5 +-
 .../adodb/Documentation/typo3-adodb.diff      | 53 +++++++++++++++++++
 .../sysext/adodb/adodb/adodb-datadict.inc.php |  6 ++-
 .../adodb/datadict/datadict-mysql.inc.php     |  1 +
 .../adodb/datadict/datadict-postgres.inc.php  |  2 +
 5 files changed, 64 insertions(+), 3 deletions(-)

diff --git a/typo3/sysext/adodb/Documentation/Index.rst b/typo3/sysext/adodb/Documentation/Index.rst
index 8548a99d06fe..ae7b4c1ec10d 100644
--- a/typo3/sysext/adodb/Documentation/Index.rst
+++ b/typo3/sysext/adodb/Documentation/Index.rst
@@ -12,7 +12,7 @@ The currently used ADOdb version is 5.19 [1]_.
 Our changes
 ===========
 
-This is a list of changes we made in ADOdb and may must re-applied if EXT:adodb is
+This is a list of changes we made in ADOdb that must re-applied if EXT:adodb is
 updated to upstream.
 
 - ADOdb: Invalid override method signature (48034_) (Solved in 5.20-dev [2]_)
@@ -22,8 +22,10 @@ updated to upstream.
 - ADOdb: mssqlnative driver fails to create sequences (66678_)
 - ADOdb: mssqlnative driver is not properly initialized (66830_)
 - ADOdb: mssqlnative driver does not properly define the port (63070_)
+- ADOdb: Allow setting NOT NULL/DEFAULT on blob and text columns (67442_) (Upstream pull request: [3]_)
 
 .. [2] https://github.com/ADOdb/ADOdb/commit/85f05a98974ea85ecae943faf230a27afdbaa746
+.. [3] https://github.com/ADOdb/ADOdb/pull/118
 .. _48034: https://forge.typo3.org/issues/48034
 .. _61738: https://forge.typo3.org/issues/61738
 .. _63659: https://forge.typo3.org/issues/63659
@@ -31,6 +33,7 @@ updated to upstream.
 .. _66678: https://forge.typo3.org/issues/66678
 .. _66830: https://forge.typo3.org/issues/66830
 .. _63070: https://forge.typo3.org/issues/63070
+.. _67442: https://forge.typo3.org/issues/67442
 
 
 Diff
diff --git a/typo3/sysext/adodb/Documentation/typo3-adodb.diff b/typo3/sysext/adodb/Documentation/typo3-adodb.diff
index 520c47a510ae..aedda1462976 100644
--- a/typo3/sysext/adodb/Documentation/typo3-adodb.diff
+++ b/typo3/sysext/adodb/Documentation/typo3-adodb.diff
@@ -297,3 +297,56 @@ index b10d555..21cfc69 100644
  		//if ($this->debug) error_log("<hr>_connectionID before: ".serialize($this->_connectionID));
  		if(!($this->_connectionID = sqlsrv_connect($argHostname,$connectionInfo))) {
 
+diff --git a/adodb-datadict.inc.php b/adodb-datadict.inc.php
+index b8b881e..f2b17f3 100644
+--- a/adodb-datadict.inc.php
++++ b/adodb-datadict.inc.php
+@@ -178,6 +178,8 @@ class ADODB_DataDict {
+ 	var $autoIncrement = false;
+ 	var $dataProvider;
+ 	var $invalidResizeTypes4 = array('CLOB','BLOB','TEXT','DATE','TIME'); // for changetablesql
++	var $blobNotNull = false; // dbms supports NOT NULL for BLOB/TEXT columns
++	var $blobDefaults = false; // dbms supports defaults for BLOB/TEXT columns
+ 	var $blobSize = 100; 	/// any varchar/char field this size or greater is treated as a blob
+ 							/// in other words, we use a text area for editting.
+ 
+@@ -717,12 +719,12 @@ class ADODB_DataDict {
+ 
+ 			$ftype = $this->_GetSize($ftype, $ty, $fsize, $fprec);
+ 
+-			if ($ty == 'X' || $ty == 'X2' || $ty == 'B') $fnotnull = false; // some blob types do not accept nulls
++			if (($ty == 'X' || $ty == 'X2' || $ty == 'B') && $this->blobNotNull !== true) $fnotnull = false; // some blob types do not accept nulls
+ 
+ 			if ($fprimary) $pkey[] = $fname;
+ 
+ 			// some databases do not allow blobs to have defaults
+-			if ($ty == 'X') $fdefault = false;
++			if ($ty == 'X' && $this->blobDefaults !== true) $fdefault = false;
+ 
+ 			// build list of indexes
+ 			if ($findex != '') {
+diff --git a/datadict/datadict-mysql.inc.php b/datadict/datadict-mysql.inc.php
+index 773aa0c..701fa66 100644
+--- a/datadict/datadict-mysql.inc.php
++++ b/datadict/datadict-mysql.inc.php
+@@ -21,6 +21,7 @@ class ADODB2_mysql extends ADODB_DataDict {
+ 
+ 	var $dropIndex = 'DROP INDEX %s ON %s';
+ 	var $renameColumn = 'ALTER TABLE %s CHANGE COLUMN %s %s %s';	// needs column-definition!
++	var $blobNotNull = true;
+ 
+ 	function MetaType($t,$len=-1,$fieldobj=false)
+ 	{
+diff --git a/datadict/datadict-postgres.inc.php b/datadict/datadict-postgres.inc.php
+index 965314d..3556825 100644
+--- a/datadict/datadict-postgres.inc.php
++++ b/datadict/datadict-postgres.inc.php
+@@ -22,6 +22,8 @@ class ADODB2_postgres extends ADODB_DataDict {
+ 	var $quote = '"';
+ 	var $renameTable = 'ALTER TABLE %s RENAME TO %s'; // at least since 7.1
+ 	var $dropTable = 'DROP TABLE %s CASCADE';
++	var $blobNotNull = true;
++	var $blobDefaults = true;
+ 
+ 	function MetaType($t,$len=-1,$fieldobj=false)
+ 	{
diff --git a/typo3/sysext/adodb/adodb/adodb-datadict.inc.php b/typo3/sysext/adodb/adodb/adodb-datadict.inc.php
index b8b881e9de6c..f2b17f3dcea4 100644
--- a/typo3/sysext/adodb/adodb/adodb-datadict.inc.php
+++ b/typo3/sysext/adodb/adodb/adodb-datadict.inc.php
@@ -178,6 +178,8 @@ class ADODB_DataDict {
 	var $autoIncrement = false;
 	var $dataProvider;
 	var $invalidResizeTypes4 = array('CLOB','BLOB','TEXT','DATE','TIME'); // for changetablesql
+	var $blobNotNull = false; // dbms supports NOT NULL for BLOB/TEXT columns
+	var $blobDefaults = false; // dbms supports defaults for BLOB/TEXT columns
 	var $blobSize = 100; 	/// any varchar/char field this size or greater is treated as a blob
 							/// in other words, we use a text area for editting.
 
@@ -717,12 +719,12 @@ class ADODB_DataDict {
 
 			$ftype = $this->_GetSize($ftype, $ty, $fsize, $fprec);
 
-			if ($ty == 'X' || $ty == 'X2' || $ty == 'B') $fnotnull = false; // some blob types do not accept nulls
+			if (($ty == 'X' || $ty == 'X2' || $ty == 'B') && $this->blobNotNull !== true) $fnotnull = false; // some blob types do not accept nulls
 
 			if ($fprimary) $pkey[] = $fname;
 
 			// some databases do not allow blobs to have defaults
-			if ($ty == 'X') $fdefault = false;
+			if ($ty == 'X' && $this->blobDefaults !== true) $fdefault = false;
 
 			// build list of indexes
 			if ($findex != '') {
diff --git a/typo3/sysext/adodb/adodb/datadict/datadict-mysql.inc.php b/typo3/sysext/adodb/adodb/datadict/datadict-mysql.inc.php
index 773aa0c79e18..701fa6603020 100644
--- a/typo3/sysext/adodb/adodb/datadict/datadict-mysql.inc.php
+++ b/typo3/sysext/adodb/adodb/datadict/datadict-mysql.inc.php
@@ -21,6 +21,7 @@ class ADODB2_mysql extends ADODB_DataDict {
 
 	var $dropIndex = 'DROP INDEX %s ON %s';
 	var $renameColumn = 'ALTER TABLE %s CHANGE COLUMN %s %s %s';	// needs column-definition!
+	var $blobNotNull = true;
 
 	function MetaType($t,$len=-1,$fieldobj=false)
 	{
diff --git a/typo3/sysext/adodb/adodb/datadict/datadict-postgres.inc.php b/typo3/sysext/adodb/adodb/datadict/datadict-postgres.inc.php
index 965314dbc442..3556825184cf 100644
--- a/typo3/sysext/adodb/adodb/datadict/datadict-postgres.inc.php
+++ b/typo3/sysext/adodb/adodb/datadict/datadict-postgres.inc.php
@@ -22,6 +22,8 @@ class ADODB2_postgres extends ADODB_DataDict {
 	var $quote = '"';
 	var $renameTable = 'ALTER TABLE %s RENAME TO %s'; // at least since 7.1
 	var $dropTable = 'DROP TABLE %s CASCADE';
+	var $blobNotNull = true;
+	var $blobDefaults = true;
 
 	function MetaType($t,$len=-1,$fieldobj=false)
 	{
-- 
GitLab