original_string: function AddColumnSQL($tabname, $flds)
  	{
  		$tabname = $this->TableName ($tabname);
  		$sql = array();
  		$not_null = false;
  		list($lines,$pkey) = $this->_GenFields($flds);
  		$alter = 'ALTER TABLE ' . $tabname . $this->addCol . ' ';
  		foreach($lines as $v) {
  			if (($not_null = preg_match('/NOT NULL/i',$v))) {
  				$v = preg_replace('/NOT NULL/i','',$v);
  			}
  			if (preg_match('/^([^ ]+) .*DEFAULT (\'[^\']+\'|\"[^\"]+\"|[^ ]+)/',$v,$matches)) {
  				list(,$colname,$default) = $matches;
  				$sql[] = $alter . str_replace('DEFAULT '.$default,'',$v);
  				$sql[] = 'UPDATE '.$tabname.' SET '.$colname.'='.$default;
  				$sql[] = 'ALTER TABLE '.$tabname.' ALTER COLUMN '.$colname.' SET DEFAULT ' . $default;
  			} else {
  				$sql[] = $alter . $v;
  			}
  			if ($not_null) {
  				list($colname) = explode(' ',$v);
  				$sql[] = 'ALTER TABLE '.$tabname.' ALTER COLUMN '.$colname.' SET NOT NULL';
  			}
  		}
  		return $sql;
  	}
code: function AddColumnSQL($tabname, $flds)
  	{
  		$tabname = $this->TableName ($tabname);
  		$sql = array();
  		$not_null = false;
  		list($lines,$pkey) = $this->_GenFields($flds);
  		$alter = 'ALTER TABLE ' . $tabname . $this->addCol . ' ';
  		foreach($lines as $v) {
  			if (($not_null = preg_match('/NOT NULL/i',$v))) {
  				$v = preg_replace('/NOT NULL/i','',$v);
  			}
  			if (preg_match('/^([^ ]+) .*DEFAULT (\'[^\']+\'|\"[^\"]+\"|[^ ]+)/',$v,$matches)) {
  				list(,$colname,$default) = $matches;
  				$sql[] = $alter . str_replace('DEFAULT '.$default,'',$v);
  				$sql[] = 'UPDATE '.$tabname.' SET '.$colname.'='.$default;
  				$sql[] = 'ALTER TABLE '.$tabname.' ALTER COLUMN '.$colname.' SET DEFAULT ' . $default;
  			} else {
  				$sql[] = $alter . $v;
  			}
  			if ($not_null) {
  				list($colname) = explode(' ',$v);
  				$sql[] = 'ALTER TABLE '.$tabname.' ALTER COLUMN '.$colname.' SET NOT NULL';
  			}
  		}
  		return $sql;
  	}
code_tokens: function AddColumnSQL ( $ tabname , $ flds ) { $ tabname = $ this -> TableName ( $ tabname ) ; $ sql = array ( ) ; $ not_null = false ; list ( $ lines , $ pkey ) = $ this -> _GenFields ( $ flds ) ; $ alter = 'ALTER TABLE ' . $ tabname . $ this -> addCol . ' ' ; foreach ( $ lines as $ v ) { if ( ( $ not_null = preg_match ( '/NOT NULL/i' , $ v ) ) ) { $ v = preg_replace ( '/NOT NULL/i' , '' , $ v ) ; } if ( preg_match ( '/^([^ ]+) .*DEFAULT (\'[^\']+\'|\"[^\"]+\"|[^ ]+)/' , $ v , $ matches ) ) { list ( , $ colname , $ default ) = $ matches ; $ sql [ ] = $ alter . str_replace ( 'DEFAULT ' . $ default , '' , $ v ) ; $ sql [ ] = 'UPDATE ' . $ tabname . ' SET ' . $ colname . '=' . $ default ; $ sql [ ] = 'ALTER TABLE ' . $ tabname . ' ALTER COLUMN ' . $ colname . ' SET DEFAULT ' . $ default ; } else { $ sql [ ] = $ alter . $ v ; } if ( $ not_null ) { list ( $ colname ) = explode ( ' ' , $ v ) ; $ sql [ ] = 'ALTER TABLE ' . $ tabname . ' ALTER COLUMN ' . $ colname . ' SET NOT NULL' ; } } return $ sql ; }
docstring: Adding a new Column
  
  reimplementation of the default function as postgres does NOT allow to set the default in the same statement
  
  @param string $tabname table-name
  @param string $flds column-names and types for the changed columns
  @return array with SQL strings
docstring_tokens: Adding a new Column