MySQLiTableInfo Class Reference

Inheritance diagram for MySQLiTableInfo:

TableInfo

List of all members.

Protected Member Functions

 initColumns ()
 Loads the columns for this table.
 initPrimaryKey ()
 Loads the primary key information for this table.
 initIndexes ()
 Loads the indexes for this table.
 initForeignKeys ()
 Load foreign keys (unsupported in MySQL).


Detailed Description

Definition at line 31 of file MySQLiTableInfo.php.


Member Function Documentation

MySQLiTableInfo::initColumns (  )  [protected]

Loads the columns for this table.

Reimplemented from TableInfo.

Definition at line 33 of file MySQLiTableInfo.php.

References TableInfo::$name, and MySQLTypes::getType().

Referenced by initForeignKeys(), initIndexes(), and initPrimaryKey().

00034     {
00035         require_once 'creole/metadata/ColumnInfo.php';
00036         require_once 'creole/drivers/mysql/MySQLTypes.php';
00037 
00038         // To get all of the attributes we need, we use
00039         // the MySQL "SHOW COLUMNS FROM $tablename" SQL.
00040         $res = mysqli_query($this->conn->getResource(), "SHOW COLUMNS FROM " . $this->name);
00041 
00042         $defaults = array();
00043         $nativeTypes = array();
00044         $precisions = array();
00045 
00046         while($row = mysqli_fetch_assoc($res)) {
00047             $name = $row['Field'];
00048             $default = $row['Default'];
00049             $is_nullable = ($row['Null'] == 'YES');
00050 
00051             $size = null;
00052             $precision = null;
00053             $scale = null;
00054 
00055             if (preg_match('/^(\w+)[\(]?([\d,]*)[\)]?( |$)/', $row['Type'], $matches)) {
00056                 //            colname[1]   size/precision[2]
00057                 $nativeType = $matches[1];
00058                 if ($matches[2]) {
00059                     if ( ($cpos = strpos($matches[2], ',')) !== false) {
00060                         $size = (int) substr($matches[2], 0, $cpos);
00061                         $precision = $size;
00062                         $scale = (int) substr($matches[2], $cpos + 1);
00063                     } else {
00064                         $size = (int) $matches[2];
00065                     }
00066                 }
00067             } elseif (preg_match('/^(\w+)\(/', $row['Type'], $matches)) {
00068                 $nativeType = $matches[1];
00069             } else {
00070                 $nativeType = $row['Type'];
00071             }
00072 
00073             $this->columns[$name] = new ColumnInfo($this, $name, MySQLTypes::getType($nativeType), $nativeType, $size, $precision, $scale, $is_nullable, $default);
00074         }
00075 
00076         $this->colsLoaded = true;
00077     }

MySQLiTableInfo::initForeignKeys (  )  [protected]

Load foreign keys (unsupported in MySQL).

Reimplemented from TableInfo.

Definition at line 134 of file MySQLiTableInfo.php.

References initColumns().

00134                                          {
00135         // columns have to be loaded first
00136         if (!$this->colsLoaded) {
00137             $this->initColumns();
00138         }
00139 
00140         // Foreign keys are not supported in mysql.
00141         $this->fksLoaded = true;
00142     }

MySQLiTableInfo::initIndexes (  )  [protected]

Loads the indexes for this table.

Reimplemented from TableInfo.

Definition at line 107 of file MySQLiTableInfo.php.

References TableInfo::$name, TableInfo::indexesLoaded(), and initColumns().

00107                                      {
00108         require_once 'creole/metadata/IndexInfo.php';
00109 
00110         // columns have to be loaded first
00111         if (!$this->colsLoaded) {
00112             $this->initColumns();
00113         }
00114         
00115         // Indexes
00116         $res = mysqli_query($this->conn->getResource(), "SHOW INDEX FROM " . $this->name);
00117 
00118         // Loop through the returned results, grouping the same key_name together
00119         // adding each column for that key.
00120         while($row = mysqli_fetch_assoc($res)) {
00121             $name = $row["Column_name"];
00122 
00123             if (!isset($this->indexes[$name])) {
00124                 $this->indexes[$name] = new IndexInfo($name);
00125             }
00126 
00127             $this->indexes[$name]->addColumn($this->columns[ $name ]);
00128         }
00129 
00130         $this->indexesLoaded = true;
00131     }

MySQLiTableInfo::initPrimaryKey (  )  [protected]

Loads the primary key information for this table.

Reimplemented from TableInfo.

Definition at line 80 of file MySQLiTableInfo.php.

References TableInfo::$name, and initColumns().

00081     {
00082         require_once 'creole/metadata/PrimaryKeyInfo.php';
00083 
00084         // columns have to be loaded first
00085         if (!$this->colsLoaded) {
00086             $this->initColumns();
00087         }
00088 
00089         // Primary Keys
00090         $res = mysqli_query($this->conn->getResource(), "SHOW KEYS FROM " . $this->name);
00091 
00092         // Loop through the returned results, grouping the same key_name together
00093         // adding each column for that key.
00094         while($row = mysqli_fetch_assoc($res)) {
00095             $name = $row["Column_name"];
00096             if (!isset($this->primaryKey)) {
00097                 $this->primaryKey = new PrimaryKeyInfo($name);
00098             }
00099 
00100             $this->primaryKey->addColumn($this->columns[ $name ]);
00101         }
00102 
00103         $this->pkLoaded = true;
00104     }


The documentation for this class was generated from the following file:

Generated on Wed May 6 23:10:50 2009 for fareofficelib by  doxygen 1.5.8