From a8b3ebe8f62c3888b216d827c1c5dcba8a47d4e1 Mon Sep 17 00:00:00 2001 From: wei <> Date: Sun, 26 Nov 2006 22:15:58 +0000 Subject: Adding active record implementation. --- .../Vendor/TSqliteMetaDataInspector.php | 85 ++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 framework/Data/ActiveRecord/Vendor/TSqliteMetaDataInspector.php (limited to 'framework/Data/ActiveRecord/Vendor/TSqliteMetaDataInspector.php') diff --git a/framework/Data/ActiveRecord/Vendor/TSqliteMetaDataInspector.php b/framework/Data/ActiveRecord/Vendor/TSqliteMetaDataInspector.php new file mode 100644 index 00000000..07fa3187 --- /dev/null +++ b/framework/Data/ActiveRecord/Vendor/TSqliteMetaDataInspector.php @@ -0,0 +1,85 @@ + + * @version $Id$ + * @package System.Data.ActiveRecord.Vendor + */ + +Prado::using('System.Data.ActiveRecord.Vendor.TDbMetaDataInspector'); +Prado::using('System.Data.ActiveRecord.Vendor.TSqliteColumnMetaData'); +Prado::using('System.Data.ActiveRecord.Vendor.TSqliteMetaData'); + +/** + * Table meta data inspector for Sqlite database. + * + * @author Wei Zhuo + * @version $Id$ + * @package System.Data.ActiveRecord.Vendor + * @since 3.1 + */ +class TSqliteMetaDataInspector extends TDbMetaDataInspector +{ + /** + * Create a new instance of meta data. + * @param string table name + * @param array column meta data + * @param array primary key meta data + * @param array foreign key meta data. + * @return TDbMetaData table meta data. + */ + protected function createMetaData($table, $columns, $primary, $foreign) + { + $pks = array(); + foreach($columns as $name=>$column) + if($column->getIsPrimaryKey()) + $pks[] = $name; + return new TSqliteMetaData($table,$columns,$pks); + } + + /** + * Get the column definitions for given table. + * @param string table name. + * @return array column name value pairs of column meta data. + */ + protected function getColumnDefinitions($table) + { + $conn=$this->getDbConnection(); + $conn->setActive(true); + $table = $conn->quoteString($table); + $command = $conn->createCommand("PRAGMA table_info({$table})"); + $command->prepare(); + $cols = array(); + foreach($command->query() as $col) + $cols[$col['name']] = $this->getColumnMetaData($col); + return $cols; + } + + /** + * Returns the column details. + * @param array column details. + * @return TPgsqlColumnMetaData column meta data. + */ + protected function getColumnMetaData($col) + { + $name = '"'.$col['name'].'"'; //quote the column names! + $type = $col['type']; + + $notNull = $col['notnull']==='99'; + $primary = $col['pk']==='1'; + $autoIncrement = strtolower($type)==='integer' && $primary; + $default = $col['dflt_value']; + return new TSqliteColumnMetaData($name,$type,$notNull,$autoIncrement,$default,$primary); + } + + /** + * Not implemented, sqlite does not have foreign key constraints. + */ + protected function getConstraintKeys($table) + { + return array('primary'=>array(), 'foreign'=>array()); + } +} + +?> \ No newline at end of file -- cgit v1.2.3