Helix Installation   Getting Started   Reference Documentation   Global Functions   Quick Start
ModulesClassesFunctions
 

Class Reference

class mysql_column extends obj implements dbi_column

Hide Inherited MembersHelix Core
Description
No description.
 
Constants
No constants.
 
Properties
public_default[ mysql_column ]
protected_dirty[ obj ]
public_extra[ mysql_column ]
public_field[ mysql_column ]
public_in_relationship[ mysql_column ]
public_is_boolean[ mysql_column ]
public_key[ mysql_column ]
public_mysql[ mysql_column ]
public_null[ mysql_column ]
publicproperty_objects_array[ obj ]
public_referenced_column_name[ mysql_column ]
public_referenced_table_name[ mysql_column ]
public_referenced_table_schema[ mysql_column ]
public_type[ mysql_column ]
 
Methods
publicadd ( )[ mysql_column ]
Parameters
No parameters for this method
Code
060  public function add(){}
publicalter ( )[ mysql_column ]
Parameters
No parameters for this method
Code
062  public function alter(){}
public__construct ( tablename , columnname , database )[ mysql_column ]
Parameters
requiredtablename
requiredcolumnname
requireddatabase
Code
017  public function __construct($__tablename, $__columnname, $__database)
018  {
019      $db = new db;
020     
021      $tp = explode("_",$__tablename);
022      if (count($tp)==3 && !preg_match('/_(ext|cus|type)$/i',$__tablename))
023      {
024          $this->in_relationship = true;
025      }
026      else
027      {
028          $this->in_relationship = false;
029      }
030     
031      $q = "SHOW COLUMNS FROM $__tablename FROM $__dbname where `field`='$__columnname'";
032      $db->query($q);       
033      if ($db->next_record() && $db->num_rows() == 1)
034      {
035          $this->_field=$db->f("Field");
036          $this->_type=$db->f("Type");
037          $this->_null=$db->f("Null");
038          $this->_key=$db->f("Key");
039          $this->_default=$db->f("Default");
040          $this->_extra=$db->f("Extra");
041      }
042     
043      $q = "SELECT * from information_schema.KEY_COLUMN_USAGE";
044      $q .= " WHERE TABLE_SCHEMA='$__dbname'";
045      $q .= " AND TABLE_NAME='$__tablename'";
046      $q .= " AND COLUMN_NAME='$__columnname'";
047      $q .= " AND REFERENCED_TABLE_NAME IS NOT NULL";
048     
049      $db->query($q);       
050      if ($db->next_record() && $db->num_rows() == 1)
051      {
052          $this->_referenced_table_schema=$db->f("REFERENCED_TABLE_SCHEMA");
053          $this->_referenced_table_name=$db->f("REFERENCED_TABLE_NAME");
054          $this->_referenced_column_name=$db->f("REFERENCED_COLUMN_NAME");
055      }
056     
057      $this->_is_boolean = preg_match('/tinyint\(1\)/i',$this->_type) ? true : false;
058  }
publicdrop ( enforce_constraints [true] )[ mysql_column ]
Parameters
optionalenforce_constraints [true]
Code
064  public function drop($__enforce_constraints=true)
065  {
066      if(!$__enforce_constraints)
067      {
068          $q = array();
069          $q[] = "SET SQL_MODE='';";
070          $q[] = "SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;";
071          $q[] = "SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO';";
072          $q[] = "alter table ".$this->tablename." drop column ".$this->columnname.";";
073          $q[] = "SET SQL_MODE=@OLD_SQL_MODE;";
074          $q[] = "SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;";
075      }
076      else
077      {
078          $q= "alter table {$le}{$__tablename}{$re} drop column {$le}$__columnname{$re};";
079      }
080     
081      return true;}
public__get ( p )[ obj ]
Parameters
requiredp
Code
007  public function __get($p)
008  {
009      $methods = get_class_methods($this);
010      $properties = get_object_vars($this);
011      if (in_array("get_$p",$methods))
012      {
013          return $this->{"get_$p"}();
014      }
015      else if (array_key_exists("_$p",$properties))
016      {
017          return $this->{"_$p"};
018      }
019      else if (in_array("get_" . substr($p,strpos($p,"_")+1), $methods))
020      {
021          return $this->{"get_" . substr($p,strpos($p,"_")+1)}(substr($p,0,strpos($p,"_")));
022      }
023      else
024      {
025          trigger_error("This object [" . get_class($this) . ":$this->id] has no private property '_$p' for the requested public property '$p'",E_USER_WARNING);
026          return null;
027      }
028  }
publicget_array ( )[ obj ]
Parameters
No parameters for this method
Code
096  public function get_array()
097  {
098      return get_object_vars($this);
099  }
publicget_classname ( )[ obj ]
Parameters
No parameters for this method
Code
086  public function get_classname()
087  {
088      return get_class($this);
089  }
publicget_dirty ( )[ obj ]
Parameters
No parameters for this method
Code
063  public function get_dirty()
064  {
065      if ($this->id === 0)
066      {
067          $this->_dirty = true;
068      }
069      else
070      {
071          foreach (get_object_vars($this) as $k=>$v)
072          {
073              if ($this->_dirty)
074              {
075                  break;
076              }
077              if (preg_match('/_dirty$/',$k))
078              {
079                  $this->_dirty = $this->_dirty || $v;
080              }
081          }
082      }
083      return $this->_dirty;
084  }
publicget_is_primary ( )[ mysql_column ]
Parameters
No parameters for this method
Code
101  public function get_is_primary()
102  {
103      return ($this->key==="PRI");
104  }
publicget_is_unique ( )[ mysql_column ]
Parameters
No parameters for this method
Code
106  public function get_is_unique()
107  {
108      return ($this->key==="UNI");
109  }
publicget_json ( )[ obj ]
Parameters
No parameters for this method
Code
101  public function get_json()
102  {
103      $class = new ReflectionClass($this->classname);
104      $methods = $class->getMethods();
105      usort($methods,"sort_reflection_objects");
106      $accessors = array();
107      foreach ($methods as $index=>$method)
108      {
109          $declarer = $method->getDeclaringClass()->name;
110          if (preg_match('/^(get|set|)_(.+)$/',$method->name,$matches))
111          {
112              $accessor = $matches[2];
113              $getset = $matches[1];
114              eval("\$accessors[\$accessor] = \$this->".$accessor.";");
115          }
116      }
117      //return json_encode($this->get_array());
118      return json_encode($accessors);
119  }
publicget_mssql_create_string ( )[ mysql_column ]
Parameters
No parameters for this method
Code
111  public function get_mssql_create_string()
112  {
113      /*
114       id int IDENTITY(1,1) NOT NULL,
115        "name" text,
116        description text,
117        mdate datetime DEFAULT NULL,
118        cdate datetime DEFAULT NULL,
119        deleted tinyint DEFAULT '0' -- ,
120        -- PRIMARY KEY (id)*/
121      $type = $this->type;
122      $type = (stristr($type,"tinyint"))?"tinyint":$type; //drop widths off the tinyints
123      $type = (stristr($type,"int"))?"int":$type; //drop widths off the ints
124      $type = (stristr($type,"bit"))?"tinyint":$type; //drop widths off the ints
125      $type = ($type=="date")?"smalldatetime":$type;
126      $type = ($type=="time")?"smalldatetime":$type;
127      /*$type = ($type=="mediumtext")?"text":$type;
128      $type = ($type=="longtext")?"text":$type;*/
129      $type = (stristr($type,"text"))?"varchar(2048)":$type; //convert any text fields to varchar
130      //this crappy, but '=' doesn't work on text in mssql
131      //Yes, this may truncate some data, we know, we know
132     
133      $create_string = "[".$this->field."] " .$type;
134     
135      if(stristr($this->extra,"auto_increment"))
136      {
137          $create_string .= " IDENTITY(1,1) ";
138      }
139      if(!is_null($this->default))
140      {
141          $create_string .= " DEFAULT " . $this->default;
142      }
143      if($this->null==="NO")
144      {
145          $create_string .= " NOT NULL";
146      }
147      return $create_string;
148  }
publicget_nice_name ( )[ mysql_column ]
Parameters
No parameters for this method
Code
083  public function get_nice_name()
084  {
085      if (preg_match('/^(parent|child)_/i',$this->field))
086      {
087          return preg_replace('/_[a-z]+_id$/i','',$this->field) . "_id";
088      }
089      else if ($this->in_relationship && $this->is_primary && $this->field!="id")
090      {
091          $tmp = explode("_",$this->referenced_table_name);
092          array_shift($tmp);
093          return implode("_",$tmp) . "_id";
094      }
095      else
096      {
097          return $this->field;
098      }
099  }
publicget_properties ( )[ obj ]
Parameters
No parameters for this method
Code
121  public function get_properties()
122  {
123      return array_keys($this->array);
124  }
protectedget_string ( )[ obj ]
Parameters
No parameters for this method
Code
091  protected function get_string()
092  {
093      return method_exists($this,"__toString") ? $this->__toString() : null;
094  }
public__set ( p , v )[ obj ]
Parameters
requiredp
requiredv
Code
030  public function __set($p,$v)
031  {
032      $methods = get_class_methods($this);
033      $properties = get_object_vars($this);
034      if (in_array("set_$p",$methods))
035      {
036          $this->{"set_$p"}($v);
037      }
038      else if (array_key_exists("_$p",$properties))
039      {
040          if (!preg_match('/_dirty$/',$p) && property_exists($this,"_{$p}_dirty"))
041          {
042              if (is_object($this->{"_$p"}))
043              {
044                  $this->{"_$p"}->dirty = true;
045              }
046              else
047              {
048                  $this->{"_{$p}_dirty"} = $this->{$p}==$v ? false : true;
049              }
050          }
051          $this->{"_$p"} = $v;
052      }
053      else if (in_array("set_" . substr($p,strpos($p,"_")+1), $methods))
054      {
055          $this->{"set_" . substr($p,strpos($p,"_")+1)}($v,substr($p,0,strpos($p,"_")));
056      }
057      else
058      {
059          trigger_error("This object [" . get_class($this) . ":$this->id] has no private property '_$p' for the requested public property '$p'",E_USER_WARNING);
060      }
061  }
public__toString ( )[ mysql_column ]
Parameters
No parameters for this method
Code
150  public function __toString()
151  {
152      return $this->_field;
153  }
 
Accessors
publicarray[ obj ]
Code
096  public function get_array()
097  {
098      return get_object_vars($this);
099  }
publicclassname[ obj ]
Code
086  public function get_classname()
087  {
088      return get_class($this);
089  }
publicdirty[ obj ]
Code
063  public function get_dirty()
064  {
065      if ($this->id === 0)
066      {
067          $this->_dirty = true;
068      }
069      else
070      {
071          foreach (get_object_vars($this) as $k=>$v)
072          {
073              if ($this->_dirty)
074              {
075                  break;
076              }
077              if (preg_match('/_dirty$/',$k))
078              {
079                  $this->_dirty = $this->_dirty || $v;
080              }
081          }
082      }
083      return $this->_dirty;
084  }
publicis_primary[ mysql_column ]
Code
101  public function get_is_primary()
102  {
103      return ($this->key==="PRI");
104  }
publicis_unique[ mysql_column ]
Code
106  public function get_is_unique()
107  {
108      return ($this->key==="UNI");
109  }
publicjson[ obj ]
Code
101  public function get_json()
102  {
103      $class = new ReflectionClass($this->classname);
104      $methods = $class->getMethods();
105      usort($methods,"sort_reflection_objects");
106      $accessors = array();
107      foreach ($methods as $index=>$method)
108      {
109          $declarer = $method->getDeclaringClass()->name;
110          if (preg_match('/^(get|set|)_(.+)$/',$method->name,$matches))
111          {
112              $accessor = $matches[2];
113              $getset = $matches[1];
114              eval("\$accessors[\$accessor] = \$this->".$accessor.";");
115          }
116      }
117      //return json_encode($this->get_array());
118      return json_encode($accessors);
119  }
publicmssql_create_string[ mysql_column ]
Code
111  public function get_mssql_create_string()
112  {
113      /*
114       id int IDENTITY(1,1) NOT NULL,
115        "name" text,
116        description text,
117        mdate datetime DEFAULT NULL,
118        cdate datetime DEFAULT NULL,
119        deleted tinyint DEFAULT '0' -- ,
120        -- PRIMARY KEY (id)*/
121      $type = $this->type;
122      $type = (stristr($type,"tinyint"))?"tinyint":$type; //drop widths off the tinyints
123      $type = (stristr($type,"int"))?"int":$type; //drop widths off the ints
124      $type = (stristr($type,"bit"))?"tinyint":$type; //drop widths off the ints
125      $type = ($type=="date")?"smalldatetime":$type;
126      $type = ($type=="time")?"smalldatetime":$type;
127      /*$type = ($type=="mediumtext")?"text":$type;
128      $type = ($type=="longtext")?"text":$type;*/
129      $type = (stristr($type,"text"))?"varchar(2048)":$type; //convert any text fields to varchar
130      //this crappy, but '=' doesn't work on text in mssql
131      //Yes, this may truncate some data, we know, we know
132     
133      $create_string = "[".$this->field."] " .$type;
134     
135      if(stristr($this->extra,"auto_increment"))
136      {
137          $create_string .= " IDENTITY(1,1) ";
138      }
139      if(!is_null($this->default))
140      {
141          $create_string .= " DEFAULT " . $this->default;
142      }
143      if($this->null==="NO")
144      {
145          $create_string .= " NOT NULL";
146      }
147      return $create_string;
148  }
publicnice_name[ mysql_column ]
Code
083  public function get_nice_name()
084  {
085      if (preg_match('/^(parent|child)_/i',$this->field))
086      {
087          return preg_replace('/_[a-z]+_id$/i','',$this->field) . "_id";
088      }
089      else if ($this->in_relationship && $this->is_primary && $this->field!="id")
090      {
091          $tmp = explode("_",$this->referenced_table_name);
092          array_shift($tmp);
093          return implode("_",$tmp) . "_id";
094      }
095      else
096      {
097          return $this->field;
098      }
099  }
publicproperties[ obj ]
Code
121  public function get_properties()
122  {
123      return array_keys($this->array);
124  }
publicstring[ obj ]
Code
091  protected function get_string()
092  {
093      return method_exists($this,"__toString") ? $this->__toString() : null;
094  }
Get Helix PHP Framework at SourceForge.net. Fast, secure and Free Open Source software downloads