2 /** @package verysimple::DB::Reflection */
3 require_once('verysimple/Phreeze/FieldMap.php');
6 * DBcolumn is an object representation of column
8 * @package verysimple::DB::Reflection
10 * @copyright 1997-2007 VerySimple, Inc.
11 * @license http://www.gnu.org/licenses/lgpl.html LGPL
26 public $NameWithoutPrefix; // populated by DBTable if there is a prefix
28 public $Keys = array ();
29 public $Constraints = array ();
32 * Instantiate new DBColumn
35 * @param DBTable $table
37 * result from "describe table" statement
39 function __construct($table, $row)
41 // typical type is something like varchar(40)
42 $typesize = explode("(", $row ["Type"]);
44 $tmp = isset($typesize [1]) ?
str_replace(")", "", $typesize [1]) : "";
45 $sizesign = explode(" ", $tmp);
47 $this->Table
= & $table;
48 $this->Name
= $row ["Field"];
49 $this->NameWithoutPrefix
= $row ["Field"];
50 $this->Type
= $typesize [0];
51 $this->Unsigned
= isset($sizesign [1]);
52 $this->Null = $row ["Null"];
53 $this->Key
= $row ["Key"];
54 $this->Default = $row ["Default"];
55 $this->Extra
= $row ["Extra"];
57 // enums are a little different because they contain a list of legal values instead of a size limit
58 if ($this->IsEnum()) {
59 // enum size is in the format 'val1','val2',...
60 $this->Size
= explode("','", substr($sizesign [0], 1, - 1));
63 $this->Size
= $sizesign [0];
64 // size may be saved for decimals as "n,n" so we need to convert that to an int
65 $tmp = explode(",", $this->Size
);
66 $this->MaxSize
= count($tmp) > 1 ?
($tmp [0] +
$tmp [1]) : $this->Size
;
69 // if ($this->Key == "MUL") print " ########################## " . print_r($row,1) . " ########################## ";
73 * Return true if this column is an enum type
79 return $this->Type
== 'enum';
83 * Return the enum values if this column type is an enum
87 function GetEnumValues()
89 return $this->IsEnum() ?
$this->Size
: array ();
93 * Return the Phreeze column constant that most closely matches this column type
97 function GetPhreezeType()
99 return FieldMap
::GetConstantFromType($this->Type
);
103 * Return the PHP variable type that most closely matches this column type
107 function GetPhpType()
110 switch ($this->Type
) {
138 * Get the SQLite type that most closely matches this column type
142 function GetSqliteType()
145 switch ($this->Type
) {
190 * Return the AS3/Flex type that most closely matches this column type
194 function GetFlexType()
197 switch ($this->Type
) {
205 $rt = $this->MaxSize
> 1 ?
"int" : "Boolean";