From 8d2c4bb7a3950c02d505736ec9f0f63c2256b70b Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 21 Oct 2003 18:09:58 +0000 Subject: [PATCH] fixed schemaproc to create indexes and enhanced syntax to create multicolum indexes and unique keys --- phpgwapi/inc/class.schema_proc.inc.php | 72 ++++++++++++++------ phpgwapi/inc/class.schema_proc_mssql.inc.php | 5 ++ phpgwapi/inc/class.schema_proc_mysql.inc.php | 17 ++++- phpgwapi/inc/class.schema_proc_pgsql.inc.php | 5 ++ 4 files changed, 76 insertions(+), 23 deletions(-) diff --git a/phpgwapi/inc/class.schema_proc.inc.php b/phpgwapi/inc/class.schema_proc.inc.php index 2b3e030d04..73aa9af088 100644 --- a/phpgwapi/inc/class.schema_proc.inc.php +++ b/phpgwapi/inc/class.schema_proc.inc.php @@ -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('
Failed getting index
'); + } + + 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; } diff --git a/phpgwapi/inc/class.schema_proc_mssql.inc.php b/phpgwapi/inc/class.schema_proc_mssql.inc.php index d8827175d1..9f9721bc8c 100644 --- a/phpgwapi/inc/class.schema_proc_mssql.inc.php +++ b/phpgwapi/inc/class.schema_proc_mssql.inc.php @@ -194,6 +194,11 @@ return "UNIQUE($sFields)"; } + function GetIXSQL($sFields) + { + return "INDEX($sFields)"; + } + function _GetColumns($oProc, $sTableName, &$sColumns, $sDropColumn = '') { $sColumns = ''; diff --git a/phpgwapi/inc/class.schema_proc_mysql.inc.php b/phpgwapi/inc/class.schema_proc_mysql.inc.php index 76fba42cef..2c17a242a3 100644 --- a/phpgwapi/inc/class.schema_proc_mysql.inc.php +++ b/phpgwapi/inc/class.schema_proc_mysql.inc.php @@ -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') diff --git a/phpgwapi/inc/class.schema_proc_pgsql.inc.php b/phpgwapi/inc/class.schema_proc_pgsql.inc.php index 5f757b1757..749ae17556 100644 --- a/phpgwapi/inc/class.schema_proc_pgsql.inc.php +++ b/phpgwapi/inc/class.schema_proc_pgsql.inc.php @@ -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;