summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--framework/Data/ActiveRecord/Vendor/TMysqlColumnMetaData.php41
-rw-r--r--framework/Data/ActiveRecord/Vendor/TSqliteColumnMetaData.php25
-rw-r--r--tests/simple_unit/ActiveRecord/FindByPksTestCase.php10
3 files changed, 72 insertions, 4 deletions
diff --git a/framework/Data/ActiveRecord/Vendor/TMysqlColumnMetaData.php b/framework/Data/ActiveRecord/Vendor/TMysqlColumnMetaData.php
index d659851f..7c841181 100644
--- a/framework/Data/ActiveRecord/Vendor/TMysqlColumnMetaData.php
+++ b/framework/Data/ActiveRecord/Vendor/TMysqlColumnMetaData.php
@@ -26,6 +26,9 @@ class TMysqlColumnMetaData extends TComponent
private $_default;
private $_notNull=true;
private $_property;
+ private $_length;
+
+ private $_typeValues;
private $_isPrimary=null;
@@ -43,11 +46,47 @@ class TMysqlColumnMetaData extends TComponent
{
$this->_property=$property;
$this->_name=$name;
- $this->_type=$type;
+ //$this->_type=$type;
$this->_notNull=$notNull;
$this->_autoIncrement=$autoIncrement;
$this->_default=$default;
$this->_isPrimary=$primary;
+ $this->processType($type);
+ }
+
+ protected function processType($type)
+ {
+ if(is_int($pos=strpos($type, '(')))
+ {
+ $match=array();
+ if(preg_match('/\((.*)\)/', $type, $match))
+ {
+ $this->_type = substr($type,0,$pos);
+ switch(strtolower($this->_type))
+ {
+ case 'set':
+ case 'enum':
+ $this->_typeValues = preg_split('/\s*,\s*|\s+/', preg_replace('/\'|"/', '', $match[1]));
+ break;
+ default:
+ $this->_length=floatval($match[1]);
+ }
+ }
+ else
+ $this->_type = $type;
+ }
+ else
+ $this->_type = $type;
+ }
+
+ public function getTypeValues()
+ {
+ return $this->_typeValues;
+ }
+
+ public function getLength()
+ {
+ return $this->_length;
}
/**
diff --git a/framework/Data/ActiveRecord/Vendor/TSqliteColumnMetaData.php b/framework/Data/ActiveRecord/Vendor/TSqliteColumnMetaData.php
index 92315a1a..8f4ded39 100644
--- a/framework/Data/ActiveRecord/Vendor/TSqliteColumnMetaData.php
+++ b/framework/Data/ActiveRecord/Vendor/TSqliteColumnMetaData.php
@@ -29,16 +29,39 @@ class TSqliteColumnMetaData extends TComponent
private $_default;
private $_primary=false;
private $_property;
+ private $_length;
public function __construct($property,$name,$type,$notNull,$autoIncrement,$default,$primary)
{
$this->_property=$property;
$this->_name=$name;
- $this->_type=$type;
$this->_notNull=$notNull;
$this->_autoIncrement=$autoIncrement;
$this->_default=$default;
$this->_primary=$primary;
+ $this->processType($type);
+ }
+
+ protected function processType($type)
+ {
+ if(is_int($pos=strpos($type, '(')))
+ {
+ $match=array();
+ if(preg_match('/\((.*)\)/', $type, $match))
+ {
+ $this->_length=floatval($match[1]);
+ $this->_type = substr($type,0,$pos);
+ }
+ else
+ $this->_type = $type;
+ }
+ else
+ $this->_type = $type;
+ }
+
+ public function getLength()
+ {
+ return $this->_length;
}
public function getPHPType()
diff --git a/tests/simple_unit/ActiveRecord/FindByPksTestCase.php b/tests/simple_unit/ActiveRecord/FindByPksTestCase.php
index e7f3e3d0..e3ba0358 100644
--- a/tests/simple_unit/ActiveRecord/FindByPksTestCase.php
+++ b/tests/simple_unit/ActiveRecord/FindByPksTestCase.php
@@ -1,5 +1,4 @@
-<?php
-
+<?php
Prado::using('System.Data.ActiveRecord.TActiveRecord');
require_once(dirname(__FILE__).'/records/DepartmentRecord.php');
require_once(dirname(__FILE__).'/records/DepSections.php');
@@ -19,6 +18,13 @@ class FindByPksTestCase extends UnitTestCase
$this->assertEqual($dep->department_id, 1);
}
+ function test_find_by_1pk_array()
+ {
+ $dep = DepartmentRecord::finder()->findByPk(array(1));
+ $this->assertNotNull($dep);
+ $this->assertEqual($dep->department_id, 1);
+ }
+
function test_find_by_pks()
{
$deps = DepartmentRecord::finder()->findAllByPks(1,2,4);