summaryrefslogtreecommitdiff
path: root/datadict
diff options
context:
space:
mode:
authorDamien Regad <dregad@mantisbt.org>2013-09-20 00:24:24 +0200
committerDamien Regad <dregad@mantisbt.org>2013-09-20 00:24:24 +0200
commit85c5412fb7018c296b018859db1d0c8c13d91568 (patch)
tree4d0fd2f87944dacfb28c04f3d77f501bb5d68d88 /datadict
parent66823f33c419d2e0ba707af95e63d39d202eaed0 (diff)
downloadadodb-85c5412fb7018c296b018859db1d0c8c13d91568.tar.gz
adodb-85c5412fb7018c296b018859db1d0c8c13d91568.tar.bz2
adodb-85c5412fb7018c296b018859db1d0c8c13d91568.zip
PostgreSQL: AlterColumnSQL don't remove default NULL value
The preg_replace statement was doing a global replace of 'NULL' by '', ignoring the fact that a column can be 'DEFAULT NULL', causing the function to generate incorrect SQL.
Diffstat (limited to 'datadict')
-rw-r--r--datadict/datadict-postgres.inc.php5
1 files changed, 4 insertions, 1 deletions
diff --git a/datadict/datadict-postgres.inc.php b/datadict/datadict-postgres.inc.php
index 888d642a..7b0ddb07 100644
--- a/datadict/datadict-postgres.inc.php
+++ b/datadict/datadict-postgres.inc.php
@@ -199,7 +199,10 @@ class ADODB2_postgres extends ADODB_DataDict {
// explicitly ask a column to be null using $flds
else if ($set_null = preg_match('/NULL/i',$v)) {
// if they didn't specify not null, see if they explicitely asked for null
- $v = preg_replace('/\sNULL/i','',$v);
+ // Lookbehind pattern covers the case 'fieldname NULL datatype DEFAULT NULL'
+ // only the first NULL should be removed, not the one specifying
+ // the default value
+ $v = preg_replace('/(?<!DEFAULT)\sNULL/i','',$v);
}
if (preg_match('/^([^ ]+) .*DEFAULT (\'[^\']+\'|\"[^\"]+\"|[^ ]+)/',$v,$matches)) {