From 3081b0a05a02592bae7d70295312257fb48206f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Gordo=20Romero?= Date: Thu, 18 Oct 2007 04:29:16 +0000 Subject: [PATCH] ORA - Fixed schema creation (indexes, triggers and secuences): Indexes: The solution of put the index name of the first columnt dont't work because duplicates, create instead a hash of the large name (PHP 5 >= 5.1.2, PECL hash:1.1-1.5) with an fixed char at beginning (Oracle objects names can't start with a number) Secuences & triggers: create a a hash of the large name. --- .../inc/adodb/datadict/datadict-oci8.inc.php | 14 +++--- phpgwapi/inc/class.schema_proc.inc.php | 48 +++++++++++-------- 2 files changed, 35 insertions(+), 27 deletions(-) diff --git a/phpgwapi/inc/adodb/datadict/datadict-oci8.inc.php b/phpgwapi/inc/adodb/datadict/datadict-oci8.inc.php index e6faa49075..0634b2f3a3 100644 --- a/phpgwapi/inc/adodb/datadict/datadict-oci8.inc.php +++ b/phpgwapi/inc/adodb/datadict/datadict-oci8.inc.php @@ -197,12 +197,14 @@ end; $trigname = $this->trigPrefix.$seqname; } - if (strlen($seqname) > 30) { - $seqname = $this->seqPrefix.uniqid(''); - } // end if - if (strlen($trigname) > 30) { - $trigname = $this->trigPrefix.uniqid(''); - } // end if + if (strlen($seqname) > 30) + { + $seqname = "s".substr(hash('md5', $seqname),0,29); + } + if (strlen($trigname) > 30) + { + $trigname = "t".substr(hash('md5', $trigname),0,29); + } if (isset($tableoptions['REPLACE'])) $sql[] = "DROP SEQUENCE $seqname"; $seqCache = ''; diff --git a/phpgwapi/inc/class.schema_proc.inc.php b/phpgwapi/inc/class.schema_proc.inc.php index 944abbfa48..da4487733f 100644 --- a/phpgwapi/inc/class.schema_proc.inc.php +++ b/phpgwapi/inc/class.schema_proc.inc.php @@ -867,27 +867,27 @@ function _index_name($sTableName,$aColumnNames) { // this code creates extrem short index-names, eg. for MaxDB - if (isset($this->max_index_length[$this->sType]) && $this->max_index_length[$this->sType] <= 32) - { - static $existing_indexes=array(); - - if (!isset($existing_indexes[$sTableName]) && method_exists($this->adodb,'MetaIndexes')) - { - $existing_indexes[$sTableName] = $this->adodb->MetaIndexes($sTableName); - } - $i = 0; - $firstCol = is_array($aColumnNames) ? $aColumnNames[0] : $aColumnNames; - do - { - ++$i; - $name = $firstCol . ($i > 1 ? '_'.$i : ''); - } - while (isset($existing_indexes[$sTableName][$name]) || isset($existing_indexes[strtoupper($sTableName)][strtoupper($name)])); - - $existing_indexes[$sTableName][$name] = True; // mark it as existing now - - return $name; - } +// if (isset($this->max_index_length[$this->sType]) && $this->max_index_length[$this->sType] <= 32) +// { +// static $existing_indexes=array(); +// +// if (!isset($existing_indexes[$sTableName]) && method_exists($this->adodb,'MetaIndexes')) +// { +// $existing_indexes[$sTableName] = $this->adodb->MetaIndexes($sTableName); +// } +// $i = 0; +// $firstCol = is_array($aColumnNames) ? $aColumnNames[0] : $aColumnNames; +// do +// { +// ++$i; +// $name = $firstCol . ($i > 1 ? '_'.$i : ''); +// } +// while (isset($existing_indexes[$sTableName][$name]) || isset($existing_indexes[strtoupper($sTableName)][strtoupper($name)])); +// +// $existing_indexes[$sTableName][$name] = True; // mark it as existing now +// +// return $name; +// } // This code creates longer index-names incl. the table-names and the used columns $table = str_replace(array('phpgw_','egw_'),'',$sTableName); // if the table-name or a part of it is repeated in the column-name, remove it there @@ -903,6 +903,12 @@ $aColumnNames = str_replace($remove,'',$aColumnNames); $name = $sTableName.'_'.(is_array($aColumnNames) ? implode('_',$aColumnNames) : $aColumnNames); + + // this code creates a fixed short index-names (30 chars) from the long and unique name, eg. for MaxDB or Oracle + if (isset($this->max_index_length[$this->sType]) && $this->max_index_length[$this->sType] <= 32 && strlen($name) > 30) + { + $name = "i".substr(hash ('md5', $name),0,29); + } return $name; }