mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-01-11 16:38:39 +01:00
See line 218 - possible fix for DropColumn() to ensure dropped column name is not in the sql
This commit is contained in:
parent
c483096849
commit
6674d23cd1
@ -204,6 +204,8 @@
|
||||
}
|
||||
$query .= ' ORDER BY a.attnum';
|
||||
|
||||
// echo '_GetColumns: ' . $query;
|
||||
|
||||
$oProc->m_odb->query($query);
|
||||
while($oProc->m_odb->next_record())
|
||||
{
|
||||
@ -213,7 +215,11 @@
|
||||
}
|
||||
|
||||
$sFieldName = $oProc->m_odb->f(0);
|
||||
/* Failsafe in case the query still includes the column to be dropped */
|
||||
if($sFieldName != $sDropColumn)
|
||||
{
|
||||
$sColumns .= $sFieldName;
|
||||
}
|
||||
if($sAlteredColumn == $sFieldName && $sAlteredColumnType != '')
|
||||
{
|
||||
$sColumns .= '::' . $sAlteredColumnType;
|
||||
@ -290,7 +296,7 @@
|
||||
$sdc->next_record();
|
||||
if($sdc->f(0))
|
||||
{
|
||||
if (ereg('nextval',$sdc->f(0)))
|
||||
if(strstr($sdc->f(0),'nextval'))
|
||||
{
|
||||
$default = '';
|
||||
$nullcomma = '';
|
||||
@ -306,7 +312,7 @@
|
||||
$default = '';
|
||||
$nullcomma = '';
|
||||
}
|
||||
$default = ereg_replace("''","'",$default);
|
||||
$default = str_replace("''","'",$default);
|
||||
|
||||
$this->sCol[] = "\t\t\t\t'" . $colname . "' => array(" . $type . ',' . $null . $nullcomma . $default . '),' . "\n";
|
||||
}
|
||||
@ -349,13 +355,13 @@
|
||||
/* ugly as heck, but is here to chop the trailing comma on the last element (for php3) */
|
||||
$this->sCol[count($this->sCol) - 1] = substr($this->sCol[count($this->sCol) - 1],0,-2) . "\n";
|
||||
|
||||
return false;
|
||||
return False;
|
||||
}
|
||||
|
||||
function _CopyAlteredTable($oProc, &$aTables, $sSource, $sDest)
|
||||
{
|
||||
$oDB = $oProc->m_odb;
|
||||
$oProc->m_odb->query("select * from $sSource");
|
||||
$oProc->m_odb->query("SELECT * FROM $sSource");
|
||||
while($oProc->m_odb->next_record())
|
||||
{
|
||||
$sSQL = "INSERT INTO $sDest (";
|
||||
@ -395,7 +401,7 @@
|
||||
$sSQL .= "'" . $oProc->m_odb->db_addslashes($oProc->m_odb->f($name)) . "'";
|
||||
break;
|
||||
default:
|
||||
$sSQL .= intval($oProc->m_odb->f($name));
|
||||
$sSQL .= (int)$oProc->m_odb->f($name);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -414,8 +420,7 @@
|
||||
|
||||
function GetSequenceForTable($oProc,$table,&$sSequenceName)
|
||||
{
|
||||
global $DEBUG;
|
||||
if($DEBUG) { echo '<br>GetSequenceForTable: ' . $table; }
|
||||
if($GLOBALS['DEBUG']) { echo '<br>GetSequenceForTable: ' . $table; }
|
||||
|
||||
$oProc->m_odb->query("SELECT relname FROM pg_class WHERE NOT relname ~ 'pg_.*' AND relname LIKE 'seq_$table' AND relkind='S' ORDER BY relname",__LINE__,__FILE__);
|
||||
$oProc->m_odb->next_record();
|
||||
@ -428,8 +433,8 @@
|
||||
|
||||
function GetSequenceFieldForTable($oProc,$table,&$sField)
|
||||
{
|
||||
global $DEBUG;
|
||||
if($DEBUG) { echo '<br>GetSequenceFieldForTable: You rang?'; }
|
||||
if($GLOBALS['DEBUG']) { echo '<br>GetSequenceFieldForTable: You rang?'; }
|
||||
|
||||
$oProc->m_odb->query("SELECT a.attname FROM pg_attribute a, pg_class c, pg_attrdef d WHERE c.relname='$table' AND c.oid=d.adrelid AND d.adsrc LIKE '%seq_$table%' AND a.attrelid=c.oid AND d.adnum=a.attnum");
|
||||
$oProc->m_odb->next_record();
|
||||
if($oProc->m_odb->f('attname'))
|
||||
@ -441,8 +446,7 @@
|
||||
|
||||
function DropSequenceForTable($oProc,$table)
|
||||
{
|
||||
global $DEBUG;
|
||||
if($DEBUG) { echo '<br>DropSequenceForTable: ' . $table; }
|
||||
if($GLOBALS['DEBUG']) { echo '<br>DropSequenceForTable: ' . $table; }
|
||||
|
||||
$this->GetSequenceForTable($oProc,$table,$sSequenceName);
|
||||
if($sSequenceName)
|
||||
@ -462,6 +466,11 @@
|
||||
|
||||
function DropColumn($oProc, &$aTables, $sTableName, $aNewTableDef, $sColumnName, $bCopyData = true)
|
||||
{
|
||||
if($GLOBALS['DEBUG'])
|
||||
{
|
||||
echo '<br>DropColumn: table=' . $sTableName . ', column=' . $sColumnName;
|
||||
}
|
||||
|
||||
if($bCopyData)
|
||||
{
|
||||
$oProc->m_odb->query("SELECT * INTO $sTableName" . "_tmp FROM $sTableName");
|
||||
@ -489,13 +498,15 @@
|
||||
|
||||
function RenameTable($oProc, &$aTables, $sOldTableName, $sNewTableName)
|
||||
{
|
||||
global $DEBUG;
|
||||
if ($DEBUG) { echo '<br>RenameTable(): Fetching old sequence for: ' . $sOldTableName; }
|
||||
if($GLOBALS['DEBUG']) { echo '<br>RenameTable(): Fetching old sequence for: ' . $sOldTableName; }
|
||||
$this->GetSequenceForTable($oProc,$sOldTableName,$sSequenceName);
|
||||
if ($DEBUG) { echo ' - ' . $sSequenceName; }
|
||||
if ($DEBUG) { echo '<br>RenameTable(): Fetching sequence field for: ' . $sOldTableName; }
|
||||
|
||||
if($GLOBALS['DEBUG']) { echo ' - ' . $sSequenceName; }
|
||||
|
||||
if($GLOBALS['DEBUG']) { echo '<br>RenameTable(): Fetching sequence field for: ' . $sOldTableName; }
|
||||
$this->GetSequenceFieldForTable($oProc,$sOldTableName,$sField);
|
||||
if ($DEBUG) { echo ' - ' . $sField; }
|
||||
|
||||
if($GLOBALS['DEBUG']) { echo ' - ' . $sField; }
|
||||
|
||||
if($sSequenceName)
|
||||
{
|
||||
@ -503,7 +514,7 @@
|
||||
$oProc->m_odb->next_record();
|
||||
$lastval = $oProc->m_odb->f(0);
|
||||
|
||||
if ($DEBUG) { echo '<br>RenameTable(): dropping old sequence: ' . $sSequenceName . ' used on field: ' . $sField; }
|
||||
if($GLOBALS['DEBUG']) { echo '<br>RenameTable(): dropping old sequence: ' . $sSequenceName . ' used on field: ' . $sField; }
|
||||
$this->DropSequenceForTable($oProc,$sOldTableName);
|
||||
|
||||
if($lastval)
|
||||
@ -511,9 +522,9 @@
|
||||
$lastval = ' start ' . $lastval;
|
||||
}
|
||||
$this->GetSequenceSQL($sNewTableName,$sSequenceSQL);
|
||||
if ($DEBUG) { echo '<br>RenameTable(): Making new sequence using: ' . $sSequenceSQL . $lastval; }
|
||||
if($GLOBALS['DEBUG']) { echo '<br>RenameTable(): Making new sequence using: ' . $sSequenceSQL . $lastval; }
|
||||
$oProc->m_odb->query($sSequenceSQL . $lastval,__LINE__,__FILE__);
|
||||
if ($DEBUG) { echo '<br>RenameTable(): Altering column default for: ' . $sField; }
|
||||
if($GLOBALS['DEBUG']) { echo '<br>RenameTable(): Altering column default for: ' . $sField; }
|
||||
$oProc->m_odb->query("ALTER TABLE $sOldTableName ALTER $sField SET DEFAULT nextval('seq_" . $sNewTableName . "')",__LINE__,__FILE__);
|
||||
}
|
||||
|
||||
@ -632,13 +643,12 @@
|
||||
|
||||
function CreateTable($oProc, $aTables, $sTableName, $aTableDef, $bCreateSequence = true)
|
||||
{
|
||||
global $DEBUG;
|
||||
if($oProc->_GetTableSQL($sTableName, $aTableDef, $sTableSQL, $sSequenceSQL))
|
||||
{
|
||||
/* create sequence first since it will be needed for default */
|
||||
if($bCreateSequence && $sSequenceSQL != '')
|
||||
{
|
||||
if ($DEBUG) { echo '<br>Making sequence using: ' . $sSequenceSQL; }
|
||||
if($GLOBALS['DEBUG']) { echo '<br>Making sequence using: ' . $sSequenceSQL; }
|
||||
$oProc->m_odb->query($sSequenceSQL);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user