[BUGFIX] ADOdb: support NOT NULL/DEFAULT field attributes on BLOB/TEXT fields
[Packages/TYPO3.CMS.git] / typo3 / sysext / adodb / Documentation / typo3-adodb.diff
1 diff --git a/adodb.inc.php b/adodb.inc.php
2 index e9011e9..51d6313 100644
3 --- a/adodb.inc.php
4 +++ b/adodb.inc.php
5 @@ -2037,7 +2037,8 @@ if (!defined('_ADODB_LAYER')) {
6
7 function SetCharSet($charset)
8 {
9 - return false;
10 + $this->charSet = $charset;
11 + return TRUE;
12 }
13
14 function IfNull( $field, $ifNull )
15 diff --git a/datadict/datadict-access.inc.php b/datadict/datadict-access.inc.php
16 index 6a0a2cd..cabcab8 100644
17 --- a/datadict/datadict-access.inc.php
18 +++ b/datadict/datadict-access.inc.php
19 @@ -77,14 +77,14 @@ class ADODB2_access extends ADODB_DataDict {
20 {
21 }
22
23 - function AlterColumnSQL($tabname, $flds)
24 + function AlterColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
25 {
26 if ($this->debug) ADOConnection::outp("AlterColumnSQL not supported");
27 return array();
28 }
29
30
31 - function DropColumnSQL($tabname, $flds)
32 + function DropColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
33 {
34 if ($this->debug) ADOConnection::outp("DropColumnSQL not supported");
35 return array();
36 diff --git a/datadict/datadict-db2.inc.php b/datadict/datadict-db2.inc.php
37 index 5bbca1d..95a693f 100644
38 --- a/datadict/datadict-db2.inc.php
39 +++ b/datadict/datadict-db2.inc.php
40 @@ -58,14 +58,14 @@ class ADODB2_db2 extends ADODB_DataDict {
41 return $suffix;
42 }
43
44 - function AlterColumnSQL($tabname, $flds)
45 + function AlterColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
46 {
47 if ($this->debug) ADOConnection::outp("AlterColumnSQL not supported");
48 return array();
49 }
50
51
52 - function DropColumnSQL($tabname, $flds)
53 + function DropColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
54 {
55 if ($this->debug) ADOConnection::outp("DropColumnSQL not supported");
56 return array();
57 diff --git a/datadict/datadict-generic.inc.php b/datadict/datadict-generic.inc.php
58 index b3736f5..e6336da 100644
59 --- a/datadict/datadict-generic.inc.php
60 +++ b/datadict/datadict-generic.inc.php
61 @@ -49,14 +49,14 @@ class ADODB2_generic extends ADODB_DataDict {
62 }
63 }
64
65 - function AlterColumnSQL($tabname, $flds)
66 + function AlterColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
67 {
68 if ($this->debug) ADOConnection::outp("AlterColumnSQL not supported");
69 return array();
70 }
71
72
73 - function DropColumnSQL($tabname, $flds)
74 + function DropColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
75 {
76 if ($this->debug) ADOConnection::outp("DropColumnSQL not supported");
77 return array();
78 diff --git a/datadict/datadict-ibase.inc.php b/datadict/datadict-ibase.inc.php
79 index 13f028e..e08ae3c 100644
80 --- a/datadict/datadict-ibase.inc.php
81 +++ b/datadict/datadict-ibase.inc.php
82 @@ -49,14 +49,14 @@ class ADODB2_ibase extends ADODB_DataDict {
83 }
84 }
85
86 - function AlterColumnSQL($tabname, $flds)
87 + function AlterColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
88 {
89 if ($this->debug) ADOConnection::outp("AlterColumnSQL not supported");
90 return array();
91 }
92
93
94 - function DropColumnSQL($tabname, $flds)
95 + function DropColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
96 {
97 if ($this->debug) ADOConnection::outp("DropColumnSQL not supported");
98 return array();
99 diff --git a/datadict/datadict-informix.inc.php b/datadict/datadict-informix.inc.php
100 index 1bc6880..76c7585 100644
101 --- a/datadict/datadict-informix.inc.php
102 +++ b/datadict/datadict-informix.inc.php
103 @@ -49,14 +49,14 @@ class ADODB2_informix extends ADODB_DataDict {
104 }
105 }
106
107 - function AlterColumnSQL($tabname, $flds)
108 + function AlterColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
109 {
110 if ($this->debug) ADOConnection::outp("AlterColumnSQL not supported");
111 return array();
112 }
113
114
115 - function DropColumnSQL($tabname, $flds)
116 + function DropColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
117 {
118 if ($this->debug) ADOConnection::outp("DropColumnSQL not supported");
119 return array();
120 diff --git a/datadict/datadict-mssql.inc.php b/datadict/datadict-mssql.inc.php
121 index 6610fc4..3374ebd 100644
122 --- a/datadict/datadict-mssql.inc.php
123 +++ b/datadict/datadict-mssql.inc.php
124 @@ -137,7 +137,7 @@ class ADODB2_mssql extends ADODB_DataDict {
125 }
126 */
127
128 - function DropColumnSQL($tabname, $flds)
129 + function DropColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
130 {
131 $tabname = $this->TableName ($tabname);
132 if (!is_array($flds))
133 diff --git a/datadict/datadict-oci8.inc.php b/datadict/datadict-oci8.inc.php
134 index 0f03389..b8bd4cf 100644
135 --- a/datadict/datadict-oci8.inc.php
136 +++ b/datadict/datadict-oci8.inc.php
137 @@ -116,6 +116,7 @@ class ADODB2_oci8 extends ADODB_DataDict {
138
139 function AddColumnSQL($tabname, $flds)
140 {
141 + $tabname = $this->TableName ($tabname);
142 $f = array();
143 list($lines,$pkey) = $this->_GenFields($flds);
144 $s = "ALTER TABLE $tabname ADD (";
145 @@ -128,8 +129,9 @@ class ADODB2_oci8 extends ADODB_DataDict {
146 return $sql;
147 }
148
149 - function AlterColumnSQL($tabname, $flds)
150 + function AlterColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
151 {
152 + $tabname = $this->TableName ($tabname);
153 $f = array();
154 list($lines,$pkey) = $this->_GenFields($flds);
155 $s = "ALTER TABLE $tabname MODIFY(";
156 @@ -141,8 +143,9 @@ class ADODB2_oci8 extends ADODB_DataDict {
157 return $sql;
158 }
159
160 - function DropColumnSQL($tabname, $flds)
161 + function DropColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
162 {
163 + $tabname = $this->TableName ($tabname);
164 if (!is_array($flds)) $flds = explode(',',$flds);
165 foreach ($flds as $k => $v) $flds[$k] = $this->NameQuote($v);
166
167 diff --git a/datadict/datadict-sapdb.inc.php b/datadict/datadict-sapdb.inc.php
168 index aaa4820..8241b20 100644
169 --- a/datadict/datadict-sapdb.inc.php
170 +++ b/datadict/datadict-sapdb.inc.php
171 @@ -100,7 +100,7 @@ class ADODB2_sapdb extends ADODB_DataDict {
172 return array( 'ALTER TABLE ' . $tabname . ' ADD (' . implode(', ',$lines) . ')' );
173 }
174
175 - function AlterColumnSQL($tabname, $flds)
176 + function AlterColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
177 {
178 $tabname = $this->TableName ($tabname);
179 $sql = array();
180 @@ -108,7 +108,7 @@ class ADODB2_sapdb extends ADODB_DataDict {
181 return array( 'ALTER TABLE ' . $tabname . ' MODIFY (' . implode(', ',$lines) . ')' );
182 }
183
184 - function DropColumnSQL($tabname, $flds)
185 + function DropColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
186 {
187 $tabname = $this->TableName ($tabname);
188 if (!is_array($flds)) $flds = explode(',',$flds);
189 diff --git a/datadict/datadict-sqlite.inc.php b/datadict/datadict-sqlite.inc.php
190 index 81fb016..5ff76b9 100644
191 --- a/datadict/datadict-sqlite.inc.php
192 +++ b/datadict/datadict-sqlite.inc.php
193 @@ -67,13 +67,13 @@ class ADODB2_sqlite extends ADODB_DataDict {
194 return $suffix;
195 }
196
197 - function AlterColumnSQL($tabname, $flds)
198 + function AlterColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
199 {
200 if ($this->debug) ADOConnection::outp("AlterColumnSQL not supported natively by SQLite");
201 return array();
202 }
203
204 - function DropColumnSQL($tabname, $flds)
205 + function DropColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
206 {
207 if ($this->debug) ADOConnection::outp("DropColumnSQL not supported natively by SQLite");
208 return array();
209 diff --git a/drivers/adodb-mssqlnative.inc.php b/drivers/adodb-mssqlnative.inc.php
210 index b10d555..21cfc69 100644
211 --- a/drivers/adodb-mssqlnative.inc.php
212 +++ b/drivers/adodb-mssqlnative.inc.php
213 @@ -209,10 +209,10 @@ class ADODB_mssqlnative extends ADOConnection {
214 switch($this->mssql_version){
215 case 9:
216 case 10:
217 - return $this->GenID2008();
218 + return $this->GenID2008($seq, $start);
219 break;
220 case 11:
221 - return $this->GenID2012();
222 + return $this->GenID2012($seq, $start);
223 break;
224 }
225 }
226 @@ -225,10 +225,10 @@ class ADODB_mssqlnative extends ADOConnection {
227 switch($this->mssql_version){
228 case 9:
229 case 10:
230 - return $this->CreateSequence2008();
231 + return $this->CreateSequence2008($seq, $start);
232 break;
233 case 11:
234 - return $this->CreateSequence2012();
235 + return $this->CreateSequence2012($seq, $start);
236 break;
237 }
238
239 @@ -287,7 +287,7 @@ class ADODB_mssqlnative extends ADOConnection {
240 }
241 $num = $this->GetOne("select id from $seq");
242 sqlsrv_commit($this->_connectionID);
243 - return true;
244 + return $num;
245 }
246 /**
247 * Only available to Server 2012 and up
248
249 @@ -311,7 +311,7 @@ class ADODB_mssqlnative extends ADOConnection {
250 }
251 if (!is_array($this->sequences)
252 || is_array($this->sequences) && !in_array($seq,$this->sequences)){
253 - $this->CreateSequence2012($seq='adodbseq',$start=1);
254 + $this->CreateSequence2012($seq, $start);
255
256 }
257 $num = $this->GetOne("SELECT NEXT VALUE FOR $seq");
258
259 @@ -459,7 +459,7 @@ class ADODB_mssqlnative extends ADOConnection {
260 $this->_errorMsg .= "Message: ".$arrError[ 'message']."\n";
261 }
262 } else {
263 - $this->_errorMsg = "No errors found";
264 + $this->_errorMsg = '';
265 }
266 return $this->_errorMsg;
267 }
268
269 @@ -476,10 +476,26 @@ class ADODB_mssqlnative extends ADOConnection {
270 function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
271 {
272 if (!function_exists('sqlsrv_connect')) return null;
273 + // Port is always given as part of $argHostname but
274 + // 1) should only be set if using an IP/hostname and not a named instance
275 + // 2) must use a comma instead of a colon
276 + list ($hostname, $port) = explode(':', $argHostname, 2);
277 + if (strpos($hostname, '\\') === false) {
278 + $argHostname = $hostname . ',' . $port;
279 + } else {
280 + $argHostname = $hostname;
281 + }
282 $connectionInfo = $this->connectionInfo;
283 - $connectionInfo["Database"]=$argDatabasename;
284 - $connectionInfo["UID"]=$argUsername;
285 - $connectionInfo["PWD"]=$argPassword;
286 + $connectionInfo['Database'] = $argDatabasename;
287 + if (!empty($argUsername)) {
288 + $connectionInfo['UID'] = $argUsername;
289 + }
290 + if (!empty($argPassword)) {
291 + $connectionInfo['PWD'] = $argPassword;
292 + }
293 + if (!empty($this->charSet)) {
294 + $connectionInfo['CharacterSet'] = $this->charSet;
295 + }
296 if ($this->debug) error_log("<hr>connecting... hostname: $argHostname params: ".var_export($connectionInfo,true));
297 //if ($this->debug) error_log("<hr>_connectionID before: ".serialize($this->_connectionID));
298 if(!($this->_connectionID = sqlsrv_connect($argHostname,$connectionInfo))) {
299
300 diff --git a/adodb-datadict.inc.php b/adodb-datadict.inc.php
301 index b8b881e..f2b17f3 100644
302 --- a/adodb-datadict.inc.php
303 +++ b/adodb-datadict.inc.php
304 @@ -178,6 +178,8 @@ class ADODB_DataDict {
305 var $autoIncrement = false;
306 var $dataProvider;
307 var $invalidResizeTypes4 = array('CLOB','BLOB','TEXT','DATE','TIME'); // for changetablesql
308 + var $blobNotNull = false; // dbms supports NOT NULL for BLOB/TEXT columns
309 + var $blobDefaults = false; // dbms supports defaults for BLOB/TEXT columns
310 var $blobSize = 100; /// any varchar/char field this size or greater is treated as a blob
311 /// in other words, we use a text area for editting.
312
313 @@ -717,12 +719,12 @@ class ADODB_DataDict {
314
315 $ftype = $this->_GetSize($ftype, $ty, $fsize, $fprec);
316
317 - if ($ty == 'X' || $ty == 'X2' || $ty == 'B') $fnotnull = false; // some blob types do not accept nulls
318 + if (($ty == 'X' || $ty == 'X2' || $ty == 'B') && $this->blobNotNull !== true) $fnotnull = false; // some blob types do not accept nulls
319
320 if ($fprimary) $pkey[] = $fname;
321
322 // some databases do not allow blobs to have defaults
323 - if ($ty == 'X') $fdefault = false;
324 + if ($ty == 'X' && $this->blobDefaults !== true) $fdefault = false;
325
326 // build list of indexes
327 if ($findex != '') {
328 diff --git a/datadict/datadict-mysql.inc.php b/datadict/datadict-mysql.inc.php
329 index 773aa0c..701fa66 100644
330 --- a/datadict/datadict-mysql.inc.php
331 +++ b/datadict/datadict-mysql.inc.php
332 @@ -21,6 +21,7 @@ class ADODB2_mysql extends ADODB_DataDict {
333
334 var $dropIndex = 'DROP INDEX %s ON %s';
335 var $renameColumn = 'ALTER TABLE %s CHANGE COLUMN %s %s %s'; // needs column-definition!
336 + var $blobNotNull = true;
337
338 function MetaType($t,$len=-1,$fieldobj=false)
339 {
340 diff --git a/datadict/datadict-postgres.inc.php b/datadict/datadict-postgres.inc.php
341 index 965314d..3556825 100644
342 --- a/datadict/datadict-postgres.inc.php
343 +++ b/datadict/datadict-postgres.inc.php
344 @@ -22,6 +22,8 @@ class ADODB2_postgres extends ADODB_DataDict {
345 var $quote = '"';
346 var $renameTable = 'ALTER TABLE %s RENAME TO %s'; // at least since 7.1
347 var $dropTable = 'DROP TABLE %s CASCADE';
348 + var $blobNotNull = true;
349 + var $blobDefaults = true;
350
351 function MetaType($t,$len=-1,$fieldobj=false)
352 {