Browse Source

#1116 (and #1117): default values for ENUMs must always be expressed as strings.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@3668 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 10 years ago
parent
commit
f19ffaa001
1 changed files with 16 additions and 0 deletions
  1. 16 0
      core/attributedef.class.inc.php

+ 16 - 0
core/attributedef.class.inc.php

@@ -2656,6 +2656,22 @@ class AttributeEnum extends AttributeString
 			return "VARCHAR(255)".($bFullSpec ? " DEFAULT ''" : ""); // ENUM() is not an allowed syntax!
 		}
 	}
+	
+	protected function GetSQLColSpec()
+	{
+		$default = $this->ScalarToSQL($this->GetDefaultValue());
+		if (is_null($default))
+		{
+			$sRet = '';
+		}
+		else
+		{
+			// ENUMs values are strings so the default value must be a string as well,
+			// otherwise MySQL interprets the number as the zero-based index of the value in the list (i.e. the nth value in the list)
+			$sRet = " DEFAULT ".CMDBSource::Quote($default);
+		}
+		return $sRet;
+	}
 
 	public function ScalarToSQL($value)
 	{