From 82b526ef98979269e9ac8fcc3029b0ec05ee331f Mon Sep 17 00:00:00 2001 From: "Artem A. Naumenko" Date: Tue, 21 Aug 2012 12:54:20 +0400 Subject: [PATCH 1/3] Fixes Cast at MyDialect --- core/DB/MyDialect.class.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/DB/MyDialect.class.php b/core/DB/MyDialect.class.php index f29eaf10f2..c7f6262c98 100644 --- a/core/DB/MyDialect.class.php +++ b/core/DB/MyDialect.class.php @@ -119,6 +119,11 @@ public function fullTextSearch($fields, $words, $logic) .self::prepareFullText($words, $logic) .')'; } + + public static function toCasted($field, $type) + { + return "CAST({$field} AS {$type})"; + } private static function prepareFullText($words, $logic) { @@ -133,4 +138,4 @@ private static function prepareFullText($words, $logic) } } } -?> \ No newline at end of file +?> From 81880f4d4a5bc33e8804db2c57eab5f5f8f2a098 Mon Sep 17 00:00:00 2001 From: "Artem A. Naumenko" Date: Tue, 21 Aug 2012 12:57:17 +0400 Subject: [PATCH 2/3] Fixed whitespaces --- core/DB/MyDialect.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/DB/MyDialect.class.php b/core/DB/MyDialect.class.php index c7f6262c98..db28be9e09 100644 --- a/core/DB/MyDialect.class.php +++ b/core/DB/MyDialect.class.php @@ -120,9 +120,9 @@ public function fullTextSearch($fields, $words, $logic) .')'; } - public static function toCasted($field, $type) - { - return "CAST({$field} AS {$type})"; + public static function toCasted($field, $type) + { + return "CAST({$field} AS {$type})"; } private static function prepareFullText($words, $logic) From 9c4f94d026500b5bb559036ae30e7a275aecceeb Mon Sep 17 00:00:00 2001 From: "Artem A. Naumenko" Date: Tue, 21 Aug 2012 13:40:38 +0400 Subject: [PATCH 3/3] Added unittest for MySQL::castTo() --- test/core/MyDialectTest.class.php | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 test/core/MyDialectTest.class.php diff --git a/test/core/MyDialectTest.class.php b/test/core/MyDialectTest.class.php new file mode 100644 index 0000000000..061cd17246 --- /dev/null +++ b/test/core/MyDialectTest.class.php @@ -0,0 +1,36 @@ + + * @copyright Copyright (c) 2012, Wapstart + */ + final class MyDialectTest extends TestCase + { + public function setUp() + { + if (!extension_loaded('mysql')) + $this->markTestSkipped('Install mysql extension'); + + try { + $link = DB::spawn('MySQL', 'root', '', 'localhost'); + $link->connect(); + DBPool::me()->addLink('test', $link); + } catch (Exception $e) { + $this->markTestSkipped("Can't connect to MySQL on localhost"); + } + } + + public function testCastTo() + { + $result = + DBPool::me()->getLink('test')->queryRow( + OSQL::select()-> + get( + DBValue::create('12')-> + castTo('decimal(5, 3)'), + 'test' + ) + ); + + $this->assertEquals($result['test'], '12.000'); + } + }