Topic: 5.17 PostgreSQL AlterColumnSQL incorrect SQL generated
author: dregad
created: 18-06-2012 12:10:13 PM
|
With 5.17, the following call
$dict->AlterColumnSQL('mantis_user_pref_table', "redirect_delay I NOTNULL DEFAULT 0" ) );
Generates this SQL:
ALTER TABLE mantis_user_pref_table ALTER COLUMN redirect_delay TYPE INTEGER
ALTER TABLE mantis_user_pref_table ALTER COLUMN redirect_delay SET DEFAULT 0
ALTER TABLE mantis_user_pref_table ALTER COLUMN INTEGER SET NOT NULL
ERROR: column "integer" of relation "mantis_user_pref_table" does not exist
This is apparently due to line 216 of ./datadict/datadict-postgres.inc.php
list($colname) = explode(' ',$v);
As $colname is already assigned earlier in the code, I think this statement should simply be removed, which seems to be confirmed by author of the patch (see http ://phplens.com/lens/lensforum/msgs.php?id=16822)
diff --git a/library/adodb/datadict/datadict-postgres.inc.php b/library/adodb/datadict/datadict-post
index 7c98ebc..e316b77 100644
--- a/library/adodb/datadict/datadict-postgres.inc.php
+++ b/library/adodb/datadict/datadict-postgres.inc.php
@@ -213,7 +213,6 @@ class ADODB2_postgres extends ADODB_DataDict {
$sql[] = $alter . $colname . ' TYPE ' . $rest;
}
- list($colname) = explode(' ',$v);
if ($not_null) {
// this does not error out if the column is already not null
$sql[] = 'ALTER TABLE '.$tabname.' ALTER COLUMN '.$colname.' SET NOT NULL';
@@ -445,4 +444,4 @@ CREATE [ UNIQUE ] INDEX index_name ON table
return $ftype;
}
}
After this change, correct SQL is generated:
ALTER TABLE mantis_user_pref_table ALTER COLUMN redirect_delay TYPE INTEGER
ALTER TABLE mantis_user_pref_table ALTER COLUMN redirect_delay SET DEFAULT 0
ALTER TABLE mantis_user_pref_table ALTER COLUMN redirect_delay SET NOT NULL |
|
Topic: Re:5.17 PostgreSQL AlterColumnSQL incorrect SQL generated
author: dregad
created: 18-06-2012 12:27:03 PM
|
You can disregard the second (partial) diff in the above patch - there was a whitespace difference (missing newline at end of file) which my editor corrected automatically. |
|
Topic: Re:5.17 PostgreSQL AlterColumnSQL incorrect SQL generated
author: John Lim
created: 20-06-2012 06:53:25 AM
|
Thanks will add this patch in 5.18. TQ, John |
|
Topic: Re:5.17 PostgreSQL AlterColumnSQL incorrect SQL generated
author: dregad
created: 20-06-2012 07:05:32 AM
|
Thanks ! |
|
|