summaryrefslogtreecommitdiff
path: root/datadict/datadict-postgres.inc.php
diff options
context:
space:
mode:
authorDamien Regad <dregad@mantisbt.org>2013-09-20 00:17:35 +0200
committerDamien Regad <dregad@mantisbt.org>2013-09-20 00:17:35 +0200
commit66823f33c419d2e0ba707af95e63d39d202eaed0 (patch)
tree09324b6a35132549017d71ec75ce8ecb82d07283 /datadict/datadict-postgres.inc.php
parent612ab2587db5d70f3d4ab912c99dc9b31d6deb72 (diff)
downloadadodb-66823f33c419d2e0ba707af95e63d39d202eaed0.tar.gz
adodb-66823f33c419d2e0ba707af95e63d39d202eaed0.tar.bz2
adodb-66823f33c419d2e0ba707af95e63d39d202eaed0.zip
Reduce number of string concatenations
Simplify the code by setting $alter to include $colname
Diffstat (limited to 'datadict/datadict-postgres.inc.php')
-rw-r--r--datadict/datadict-postgres.inc.php24
1 files changed, 13 insertions, 11 deletions
diff --git a/datadict/datadict-postgres.inc.php b/datadict/datadict-postgres.inc.php
index 0331b565..888d642a 100644
--- a/datadict/datadict-postgres.inc.php
+++ b/datadict/datadict-postgres.inc.php
@@ -205,6 +205,7 @@ class ADODB2_postgres extends ADODB_DataDict {
if (preg_match('/^([^ ]+) .*DEFAULT (\'[^\']+\'|\"[^\"]+\"|[^ ]+)/',$v,$matches)) {
$existing = $this->MetaColumns($tabname);
list(,$colname,$default) = $matches;
+ $alter .= $colname;
if ($this->connection) {
$old_coltype = $this->connection->MetaType($existing[strtoupper($colname)]);
}
@@ -216,20 +217,20 @@ class ADODB2_postgres extends ADODB_DataDict {
// Type change from bool to int
if ( $old_coltype == 'L' && $t == 'INTEGER' ) {
- $sql[] = $alter . $colname . ' DROP DEFAULT';
- $sql[] = $alter . $colname . " TYPE $t USING ($colname::BOOL)::INT";
- $sql[] = $alter . $colname . " SET DEFAULT $default";
+ $sql[] = $alter . ' DROP DEFAULT';
+ $sql[] = $alter . " TYPE $t USING ($colname::BOOL)::INT";
+ $sql[] = $alter . " SET DEFAULT $default";
}
// Type change from int to bool
else if ( $old_coltype == 'I' && $t == 'BOOLEAN' ) {
- $sql[] = $alter . $colname . ' DROP DEFAULT';
- $sql[] = $alter . $colname . " TYPE $t USING CASE WHEN $colname = 0 THEN false ELSE true END";
- $sql[] = $alter . $colname . " SET DEFAULT " . $this->connection->qstr($default);
+ $sql[] = $alter . ' DROP DEFAULT';
+ $sql[] = $alter . " TYPE $t USING CASE WHEN $colname = 0 THEN false ELSE true END";
+ $sql[] = $alter . " SET DEFAULT " . $this->connection->qstr($default);
}
// Any other column types conversion
else {
- $sql[] = $alter . $colname . " TYPE $t";
- $sql[] = $alter . $colname . " SET DEFAULT $default";
+ $sql[] = $alter . " TYPE $t";
+ $sql[] = $alter . " SET DEFAULT $default";
}
}
@@ -237,17 +238,18 @@ class ADODB2_postgres extends ADODB_DataDict {
// drop default?
preg_match ('/^\s*(\S+)\s+(.*)$/',$v,$matches);
list (,$colname,$rest) = $matches;
- $sql[] = $alter . $colname . ' TYPE ' . $rest;
+ $alter .= $colname;
+ $sql[] = $alter . ' TYPE ' . $rest;
}
# list($colname) = explode(' ',$v);
if ($not_null) {
// this does not error out if the column is already not null
- $sql[] = $alter . $colname . ' SET NOT NULL';
+ $sql[] = $alter . ' SET NOT NULL';
}
if ($set_null) {
// this does not error out if the column is already null
- $sql[] = $alter . $colname . ' DROP NOT NULL';
+ $sql[] = $alter . ' DROP NOT NULL';
}
}
return $sql;