From 54c90d0102515ad58a882a6b3f4ac623fc9d50ed Mon Sep 17 00:00:00 2001 From: wei <> Date: Sat, 31 Mar 2007 06:42:15 +0000 Subject: Add changes by ezar for IBM Db2 Active Record support. --- .../Scaffold/InputBuilder/TIbmScaffoldInput.php | 51 ++++++++++++++++++++++ .../Scaffold/InputBuilder/TScaffoldInputBase.php | 3 ++ .../ActiveRecord/Vendor/TIbmColumnMetaData.php | 10 ++++- .../Data/ActiveRecord/Vendor/TIbmMetaData.php | 33 ++++++++++++++ .../ActiveRecord/Vendor/TIbmMetaDataInspector.php | 4 +- 5 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 framework/Data/ActiveRecord/Scaffold/InputBuilder/TIbmScaffoldInput.php (limited to 'framework') diff --git a/framework/Data/ActiveRecord/Scaffold/InputBuilder/TIbmScaffoldInput.php b/framework/Data/ActiveRecord/Scaffold/InputBuilder/TIbmScaffoldInput.php new file mode 100644 index 00000000..ada2091e --- /dev/null +++ b/framework/Data/ActiveRecord/Scaffold/InputBuilder/TIbmScaffoldInput.php @@ -0,0 +1,51 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2007 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +Prado::using('System.Data.ActiveRecord.Scaffold.InputBuilder.TScaffoldInputCommon'); + +class TIbmScaffoldInput extends TScaffoldInputCommon +{ + protected function createControl($container, $column, $record) + { + switch(strtolower($column->getType())) + { + case 'date': + return $this->createDateControl($container, $column, $record); + case 'time': + return $this->createTimeControl($container, $column, $record); + case 'timestamp': + return $this->createDateTimeControl($container, $column, $record); + case 'smallint': case 'integer': case 'bigint': + return $this->createIntegerControl($container, $column, $record); + case 'decimal': case 'numeric': case 'real': case 'float': case 'double': + return $this->createFloatControl($container, $column, $record); + case 'char': case 'varchar': + return $this->createMultiLineControl($container, $column, $record); + default: + return $this->createDefaultControl($container,$column, $record); + } + } + + protected function getControlValue($container, $column, $record) + { + switch(strtolower($column->getType())) + { + case 'date': + return $container->findControl(self::DEFAULT_ID)->getDate(); + case 'time': + return $this->getTimeValue($container, $column, $record); + case 'timestamp': + return $this->getDateTimeValue($container, $column, $record); + default: + return $this->getDefaultControlValue($container,$column, $record); + } + } +} + +?> \ No newline at end of file diff --git a/framework/Data/ActiveRecord/Scaffold/InputBuilder/TScaffoldInputBase.php b/framework/Data/ActiveRecord/Scaffold/InputBuilder/TScaffoldInputBase.php index c06f2fb6..05e83157 100644 --- a/framework/Data/ActiveRecord/Scaffold/InputBuilder/TScaffoldInputBase.php +++ b/framework/Data/ActiveRecord/Scaffold/InputBuilder/TScaffoldInputBase.php @@ -27,6 +27,9 @@ class TScaffoldInputBase case 'pgsql': require_once(dirname(__FILE__).'/TPgsqlScaffoldInput.php'); return new TPgsqlScaffoldInput($conn); + case 'ibm': + require_once(dirname(__FILE__).'/TIbmScaffoldInput.php'); + return new TIbmScaffoldInput($conn); default: throw new TConfigurationException( 'scaffold_invalid_database_driver',$driver); diff --git a/framework/Data/ActiveRecord/Vendor/TIbmColumnMetaData.php b/framework/Data/ActiveRecord/Vendor/TIbmColumnMetaData.php index 65e40a59..eafadae5 100644 --- a/framework/Data/ActiveRecord/Vendor/TIbmColumnMetaData.php +++ b/framework/Data/ActiveRecord/Vendor/TIbmColumnMetaData.php @@ -45,7 +45,7 @@ class TIbmColumnMetaData extends TComponent */ public function __construct($name,$type,$length,$notNull,$autoIncrement,$default,$primary) { - $this->_property = $name; + $this->_property=$name; $this->_name=$name; $this->_type=$type; $this->_length=$length; @@ -63,6 +63,14 @@ class TIbmColumnMetaData extends TComponent return $this->_name; } + /** + * @return integer length. + */ + public function getLength() + { + return $this->_length; + } + /** * @return string active record property name */ diff --git a/framework/Data/ActiveRecord/Vendor/TIbmMetaData.php b/framework/Data/ActiveRecord/Vendor/TIbmMetaData.php index 4f923406..eeaea851 100644 --- a/framework/Data/ActiveRecord/Vendor/TIbmMetaData.php +++ b/framework/Data/ActiveRecord/Vendor/TIbmMetaData.php @@ -76,5 +76,38 @@ class TIbmMetaData extends TDbMetaDataCommon $data[$k] = $this->postQueryRow($v); return $data; } + + public function getSearchRegExpCriteria($fields, $keywords) + { + if(strlen(trim($keywords)) == 0) return ''; + $words = array(); + preg_match_all('/([a-zA-Z0-9-+]+)/', $keywords, $words); + $result = array(); + foreach($fields as $field) + { + $column = $this->getColumn($field); + if($this->isSearchableColumn($column)) + $result[] = $this->getLikeCriteriaStr($column->getName(), $words[0]); + } + $a = '('.implode(' OR ', $result).')'; + error_log($a); + return '('.implode(' OR ', $result).')'; + } + + protected function isSearchableColumn($column) + { + $type = strtolower($column->getType()); + return $type === 'char' || $type === 'varchar'; + } + + protected function getLikeCriteriaStr($column, $words) + { + $result=array(); + foreach($words as $word) + $result[] = "{$column} LIKE '%{$word}%'"; + return '('.implode(' AND ', $result).')'; + } + + } ?> \ No newline at end of file diff --git a/framework/Data/ActiveRecord/Vendor/TIbmMetaDataInspector.php b/framework/Data/ActiveRecord/Vendor/TIbmMetaDataInspector.php index 0ccc05ae..3920ac39 100644 --- a/framework/Data/ActiveRecord/Vendor/TIbmMetaDataInspector.php +++ b/framework/Data/ActiveRecord/Vendor/TIbmMetaDataInspector.php @@ -78,8 +78,8 @@ class TIbmMetaDataInspector extends TDbMetaDataInspector $name = strtolower($col['COLNAME']); $type = $col['TYPENAME']; $length = $col['LENGTH']; - $notNull = $col['NULLS']==='N'; - $autoIncrement=$col['IDENTITY']==='N'; + $notNull = $col['NULLS']==='N'?1:0; + $autoIncrement=$col['IDENTITY']==='Y'?1:0; $default = $col['DEFAULT']; $primaryKey = $col['KEYSEQ']?1:0; return new TIbmColumnMetaData($name,$type,$length,$notNull,$autoIncrement,$default,$primaryKey); -- cgit v1.2.3