SQLiteTableInfo Class Reference

Inheritance diagram for SQLiteTableInfo:

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 SQLite).


Detailed Description

Definition at line 31 of file SQLiteTableInfo.php.


Member Function Documentation

SQLiteTableInfo::initColumns (  )  [protected]

Loads the columns for this table.

Reimplemented from TableInfo.

Definition at line 34 of file SQLiteTableInfo.php.

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

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

00035     {
00036         
00037         include_once 'creole/metadata/ColumnInfo.php';
00038         include_once 'creole/metadata/PrimaryKeyInfo.php';
00039         include_once 'creole/drivers/sqlite/SQLiteTypes.php';                
00040         
00041         // To get all of the attributes we need, we'll actually do 
00042         // two separate queries.  The first gets names and default values
00043         // the second will fill in some more details.
00044         
00045         $sql = 'PRAGMA table_info('.$this->name.')';
00046                 
00047         $res = sqlite_query($this->conn->getResource(), $sql);
00048         
00049         
00050         while($row = sqlite_fetch_array($res, SQLITE_ASSOC)) {
00051         
00052             $name = $row['name'];
00053             
00054             $fulltype = $row['type'];            
00055             $size = null;
00056             $precision = null;
00057             $scale = null;
00058             
00059             if (preg_match('/^([^\(]+)\(\s*(\d+)\s*,\s*(\d+)\s*\)$/', $fulltype, $matches)) {
00060                 $type = $matches[1];
00061                 $precision = $matches[2];
00062                 $scale = $matches[3]; // aka precision    
00063             } elseif (preg_match('/^([^\(]+)\(\s*(\d+)\s*\)$/', $fulltype, $matches)) {
00064                 $type = $matches[1];
00065                 $size = $matches[2];
00066             } else {
00067                 $type = $fulltype;
00068             }
00069             
00070             $not_null = $row['notnull'];
00071             $is_nullable = !$not_null;
00072             
00073             $default_val = $row['dflt_value'];
00074             
00075             $this->columns[$name] = new ColumnInfo($this, $name, SQLiteTypes::getType($type), $type, $size, $precision, $scale, $is_nullable, $default_val);
00076             
00077             if (($row['pk'] == 1) || (strtolower($type) == 'integer primary key')) {
00078                 if ($this->primaryKey === null) {
00079                     $this->primaryKey = new PrimaryKeyInfo($name);
00080                 }
00081                 $this->primaryKey->addColumn($this->columns[ $name ]);
00082             }
00083             
00084         }        
00085                 
00086         $this->colsLoaded = true;
00087     }

SQLiteTableInfo::initForeignKeys (  )  [protected]

Load foreign keys (unsupported in SQLite).

Reimplemented from TableInfo.

Definition at line 125 of file SQLiteTableInfo.php.

References initColumns().

00125                                          {
00126         
00127         // columns have to be loaded first
00128         if (!$this->colsLoaded) $this->initColumns();        
00129         
00130         // No fkeys in SQLite
00131         
00132         $this->fksLoaded = true;
00133     }

SQLiteTableInfo::initIndexes (  )  [protected]

Loads the indexes for this table.

Reimplemented from TableInfo.

Definition at line 99 of file SQLiteTableInfo.php.

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

00099                                      {
00100     
00101         include_once 'creole/metadata/IndexInfo.php';        
00102 
00103         // columns have to be loaded first
00104         if (!$this->colsLoaded) $this->initColumns();        
00105 
00106         $sql = 'PRAGMA index_list('.$this->name.')';
00107         $res = sqlite_query($this->conn->getResource(), $sql);
00108         
00109         while($row = sqlite_fetch_array($res, SQLITE_ASSOC)) {        
00110             $name = $row['name'];
00111             $this->indexes[$name] = new IndexInfo($name);
00112             
00113             // get columns for that index
00114             $res2 = sqlite_query($this->conn->getResource(), 'PRAGMA index_info('.$name.')');
00115             while($row2 = sqlite_fetch_array($res2, SQLITE_ASSOC)) {
00116                 $colname = $row2['name'];
00117                 $this->indexes[$name]->addColumn($this->columns[ $colname ]);
00118             }
00119         }        
00120                 
00121         $this->indexesLoaded = true;
00122     }

SQLiteTableInfo::initPrimaryKey (  )  [protected]

Loads the primary key information for this table.

Reimplemented from TableInfo.

Definition at line 90 of file SQLiteTableInfo.php.

References initColumns().

00091     {        
00092         // columns have to be loaded first
00093         if (!$this->colsLoaded) $this->initColumns();                        
00094         // keys are loaded by initColumns() in this class.
00095         $this->pkLoaded = true;
00096     }


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