fixed schemaproc to create indexes and enhanced syntax to create multicolum indexes and unique keys

This commit is contained in:
Ralf Becker 2003-10-21 18:09:58 +00:00
parent f2b0ca5d6d
commit 8d2c4bb7a3
4 changed files with 76 additions and 23 deletions

View File

@ -24,6 +24,7 @@
function schema_proc($dbms)
{
$this->sType = $dbms;
$this->m_oTranslator = CreateObject('phpgwapi.schema_proc_' . $dbms);
$this->m_oDeltaProc = CreateObject('phpgwapi.schema_proc_array');
$this->m_aTables = array();
@ -295,6 +296,7 @@
$sUCSQL = '';
$sPKSQL = '';
$sIXSQL = '';
if(count($aTableDef['pk']) > 0)
{
@ -322,6 +324,19 @@
}
}
if(count($aTableDef['ix']) > 0)
{
if(!$this->_GetIX($aTableDef['ix'], $sIXSQL))
{
if($bOutputHTML)
{
print('<br>Failed getting index<br>');
}
return False;
}
}
if($sPKSQL != '')
{
$sTableSQL .= ",\n" . $sPKSQL;
@ -332,6 +347,11 @@
$sTableSQL .= ",\n" . $sUCSQL;
}
if($sIXSQL != '')
{
$sTableSQL .= ",\n" . $sIXSQL;
}
return True;
}
@ -404,18 +424,7 @@
return True;
}
$sFields = '';
reset($aFields);
while(list($key, $sField) = each($aFields))
{
if($sFields != '')
{
$sFields .= ',';
}
$sFields .= $sField;
}
$sPKSQL = $this->m_oTranslator->GetPKSQL($sFields);
$sPKSQL = $this->m_oTranslator->GetPKSQL(implode(',',$aFields));
return True;
}
@ -427,19 +436,38 @@
{
return True;
}
$sFields = '';
reset($aFields);
while(list($key,$sField) = each($aFields))
foreach($aFields as $mFields)
{
if($sFields != '')
{
$sFields .= ',';
}
$sFields .= $sField;
$aUCSQL[] = $this->m_oTranslator->GetUCSQL(
is_array($mFields) ? implode(',',$mFields) : $mFields);
}
$sUCSQL = implode(",\n",$aUCSQL);
$sUCSQL = $this->m_oTranslator->GetUCSQL($sFields);
return True;
}
function _GetIX($aFields, &$sIXSQL)
{
$sUCSQL = '';
if(count($aFields) < 1)
{
return True;
}
foreach($aFields as $mFields)
{
$options = False;
if (is_array($mFields))
{
if (isset($mFields['options'])) // array sets additional options
{
$options = @$mFields['options'][$this->sType]; // db-specific options, eg. index-type
unset($mFields['options']);
}
$mFields = implode(',',$mFields);
}
$aIXSQL[] = $this->m_oTranslator->GetIXSQL($mFields,$options);
}
$sIXSQL = implode(",\n",$aIXSQL);
return True;
}

View File

@ -194,6 +194,11 @@
return "UNIQUE($sFields)";
}
function GetIXSQL($sFields)
{
return "INDEX($sFields)";
}
function _GetColumns($oProc, $sTableName, &$sColumns, $sDropColumn = '')
{
$sColumns = '';

View File

@ -202,6 +202,21 @@
return "UNIQUE($sFields)";
}
function GetIXSQL($sFields,$options=False)
{
$type = 'INDEX';
$length = '';
if (strtoupper($options) == 'FULLTEXT')
{
$type = 'FULLTEXT';
}
if (is_numeric($options))
{
$length = "($options)";
}
return "$type($sFields $length)";
}
function _GetColumns($oProc, $sTableName, &$sColumns, $sDropColumn = '')
{
$sColumns = '';
@ -223,7 +238,7 @@
/* The rest of this is used only for SQL->array */
$colinfo = explode('(',$oProc->m_odb->f(1));
$prec = ereg_replace(').*','',$colinfo[1]);
$prec = ereg_replace('\).*','',$colinfo[1]);
$scales = explode(',',$prec);
if($colinfo[0] == 'enum')

View File

@ -180,6 +180,11 @@
return "UNIQUE($sFields)";
}
function GetIXSQL($sFields)
{
return "INDEX($sFields)";
}
function _GetColumns($oProc, $sTableName, &$sColumns, $sDropColumn = '', $sAlteredColumn = '', $sAlteredColumnType = '')
{
$sdb = $oProc->m_odb;