Project

General

Profile

Actions

Bug #15472

closed

alter table with default value does not work in postgres7

Added by Christian Welzel almost 19 years ago. Updated over 18 years ago.

Status:
Closed
Priority:
Could have
Category:
Database API (Doctrine DBAL)
Target version:
-
Start date:
2006-01-20
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

Hi!
Tested some things with 4.0beta dbal and found out, that installation of realurl does not work properly. the query

ALTER TABLE pages ADD tx_realurl_pathsegment varchar(30) NOT NULL default '';

results in an error

FEHLER: Spalten mit Vorgabewerten hinzuzufügen ist nicht implementiert
HINT: Fügen Sie die Spalte hinzu und verwenden Sie dann ALTER TABLE SET DEFAULT.

(adding columns with default values is not implemented. use alter table set default).

system is debian stable with postgresql 7.4.7, apache 2.0.54 and php 4.3.10.

(issue imported from #M2340)

Actions #1

Updated by Karsten Dambekalns almost 19 years ago

Right, as the error message explains this is not possible. The suggested workaround is not coded into ADOdb, so the last resort is to do this manually.

This should be solved upstream in ADOdb, although in this particular case the default '' could be dropped - it is a noop anyway.

Actions #2

Updated by Christian Welzel almost 19 years ago

This problem seem to happen only on varchar columns.
I tested to install templavoila and the non-varchar columns of templavoila got inserted into tt_content.
the non-varchar columns have their default and not null correctly set.

Actions #3

Updated by Christian Welzel almost 19 years ago

had a closer look at the whole thingy and found out, that someone (dbal or adodb) inserts a additional whitespace char into the sql query after DEFAULT and before the default value. thats why the regexp in AddColumnSQL() does not recognize the default value and does not handle it correctly.
so the solution is to remove the bug that inserts the blank or alter the regexp in datadict-postgres.inc.php from
if (preg_match('/^([^ ]+) .*DEFAULT ([^ ]+)/',$v,$matches)) {
to
if (preg_match('/^([^ ]+) .*DEFAULT \s*([^ ]+)/',$v,$matches)) {
.

after changing that, adding varchar columns works again with default and not null values.

Actions #4

Updated by Christian Welzel almost 19 years ago

Ok, forgot to really check the result of operation so overlooked that the columns were not added. i didnt fixed the str_replace...
so this code piece fixed the problem:

if (preg_match('/^([^ ]+) .*DEFAULT (\s*)([^ ]+)/',$v,$matches)) {
list(,$colname,$space,$default) = $matches;
$sql[] = $alter . str_replace('DEFAULT '.$space.$default,'',$v);

but the cleaner way would be removing the code that inserts the additional blank.

Actions #5

Updated by Karsten Dambekalns almost 19 years ago

Christian, thanks! I didn't even look at this, as I thought ADOdb didn't handle this. I'll see to fix this.

Actions #6

Updated by Karsten Dambekalns over 18 years ago

In class.ux_t3lib_sqlengine.php you find the method compileFieldCfg(). There we have this line (watch the spaces!):
$cfg .= ' " \'\' "';
So it ends up with an additional space, which ADOdb would trim if we would not add NOQUOTE to the config later in the code. Thus the regex fails, as you observed.

Making that line read (one space less!)
$cfg .= ' "\'\'"';
it works (still) in MySQL and works in PostgreSQL, too.

The problem now is: I wrote that line that way, because I had a reason to do so. So I have to find out, what that reason was, if it still exists and if changing this like proposed above breaks other systems.

Actions #7

Updated by Karsten Dambekalns over 18 years ago

Ok, it can be done that way, as the extra space was added to avoid autoquoting. The same thing is enforced by the NOQUOTE that is actually already there, so...

Actions #8

Updated by Karsten Dambekalns over 18 years ago

Fixed in RC2

Actions

Also available in: Atom PDF