From 1e9695dbc91dfccaa4bbd4e42d387dfe7b1b616d Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Wed, 15 Sep 2010 13:27:26 +0000 Subject: [PATCH] allow to limit size of index by appending it in brackets after the column name, eg. "column(32)", which is already supported by ADOdb, by was broken by our fix to always quote names, to allow column names which are reserved words, eg. "timestamp" in phpfreechat --- phpgwapi/inc/adodb/adodb-datadict.inc.php | 16 +++++++++++++--- phpgwapi/inc/class.schema_proc.inc.php | 2 ++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/phpgwapi/inc/adodb/adodb-datadict.inc.php b/phpgwapi/inc/adodb/adodb-datadict.inc.php index 898071c397..78f19acb80 100644 --- a/phpgwapi/inc/adodb/adodb-datadict.inc.php +++ b/phpgwapi/inc/adodb/adodb-datadict.inc.php @@ -238,10 +238,20 @@ class ADODB_DataDict { return $quote . $matches[1] . $quote; } - // if name contains special characters, quote it - /*$regex = ($allowBrackets) ? $this->nameRegexBrackets : $this->nameRegex; + // if brackets are allowed, quote only the rest, + // to allow to limit indexes on colums, eg "column(32)" + if ($allowBrackets && preg_match('/^(.*) *(\(\d+\))$/',$name,$matches)) { + return $quote . $matches[1] . $quote . ' '. $matches[2]; + } + return $quote . $name . $quote; + + // not used stock ADOdb code, which only quotes names with special chars, + // which does not help with column names using reserved words, eg. "timestamp" in phpfreechat - if ( !preg_match('/^[' . $regex . ']+$/', $name) )*/ { + // if name contains special characters, quote it + $regex = ($allowBrackets) ? $this->nameRegexBrackets : $this->nameRegex; + + if ( !preg_match('/^[' . $regex . ']+$/', $name) ) { return $quote . $name . $quote; } diff --git a/phpgwapi/inc/class.schema_proc.inc.php b/phpgwapi/inc/class.schema_proc.inc.php index d5ec9ae0fe..5c5320c969 100644 --- a/phpgwapi/inc/class.schema_proc.inc.php +++ b/phpgwapi/inc/class.schema_proc.inc.php @@ -918,6 +918,8 @@ class schema_proc $aColumnNames = str_replace($remove,'',$aColumnNames); $name = $sTableName.'_'.(is_array($aColumnNames) ? implode('_',$aColumnNames) : $aColumnNames); + // remove length limits from column names + $name = preg_replace('/ *\(\d+\)/','',$name); // 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 ||