diff --git a/core/attributedef.class.inc.php b/core/attributedef.class.inc.php index c299b7cfe..2d3ce055d 100644 --- a/core/attributedef.class.inc.php +++ b/core/attributedef.class.inc.php @@ -213,6 +213,11 @@ abstract class AttributeDefinition return true; } + public function GetMaxSize() + { + return null; + } + public function MakeValue() { $sComputeFunc = $this->Get("compute_func"); @@ -636,6 +641,11 @@ class AttributeString extends AttributeDBField } } + public function GetMaxSize() + { + return 255; + } + public function GetBasicFilterOperators() { return array( @@ -844,6 +854,11 @@ class AttributePassword extends AttributeString public function GetEditClass() {return "Password";} protected function GetSQLCol() {return "VARCHAR(64)";} + public function GetMaxSize() + { + return 64; + } + public function GetFilterDefinitions() { // Note: due to this, you will get an error if a password is being declared as a search criteria (see ZLists) @@ -887,6 +902,11 @@ class AttributeEncryptedString extends AttributeString protected function GetSQLCol() {return "TINYBLOB";} + public function GetMaxSize() + { + return 255; + } + public function GetFilterDefinitions() { // Note: due to this, you will get an error if a an encrypted field is declared as a search criteria (see ZLists) @@ -936,6 +956,13 @@ class AttributeText extends AttributeString public function GetEditClass() {return "Text";} protected function GetSQLCol() {return "TEXT";} + public function GetMaxSize() + { + // Is there a way to know the current limitation for mysql? + // See mysql_field_len() + return 65535; + } + public function GetAsHTML($sValue) { return str_replace("\n", "
\n", parent::GetAsHTML($sValue)); @@ -2082,6 +2109,10 @@ class AttributeTable extends AttributeText public function GetEditClass() {return "Text";} protected function GetSQLCol() {return "TEXT";} + public function GetMaxSize() + { + return null; + } // Facilitate things: allow the user to Set the value from a string public function MakeRealValue($proposedValue) diff --git a/core/dbobject.class.php b/core/dbobject.class.php index 9e587542e..ae10c3130 100644 --- a/core/dbobject.class.php +++ b/core/dbobject.class.php @@ -636,7 +636,15 @@ abstract class DBObject return "Value not allowed [$toCheck]"; } } - elseif (!$oAtt->CheckFormat($toCheck)) + if (!is_null($iMaxSize = $oAtt->GetMaxSize())) + { + $iLen = strlen($toCheck); + if ($iLen > $iMaxSize) + { + return "String too long (found $iLen, limited to $iMaxSize)"; + } + } + if (!$oAtt->CheckFormat($toCheck)) { return "Wrong format [$toCheck]"; }