Permalink
Browse files

Use String::tokenize() to split up fields.

It is slightly more intelligent than explode()
Solves basic problems in Sqlite with virtualFields.

Fixes #2163
  • Loading branch information...
1 parent 010abd9 commit 43df8d34e7e4d2dce803dda3aa3b54c0f5a08808 @markstory markstory committed Oct 27, 2011
@@ -18,6 +18,7 @@
*/
App::uses('DboSource', 'Model/Datasource');
+App::uses('String', 'Utility');
/**
* DBO implementation for the SQLite3 DBMS.
@@ -281,7 +282,7 @@ public function resultSet($results) {
$last = strripos($querystring, 'FROM');
if ($last !== false) {
$selectpart = substr($querystring, 7, $last - 8);
- $selects = explode(',', $selectpart);
+ $selects = String::tokenize($selectpart, ',', '(', ')');
}
} elseif (strpos($querystring, 'PRAGMA table_info') === 0) {
$selects = array('cid', 'name', 'type', 'notnull', 'dflt_value', 'pk');
@@ -20,6 +20,8 @@
App::uses('AppModel', 'Model');
App::uses('Sqlite', 'Model/Datasource/Database');
+require_once dirname(dirname(dirname(__FILE__))) . DS . 'models.php';
+
/**
* DboSqliteTestDb class
*
@@ -88,6 +90,7 @@ class SqliteTest extends CakeTestCase {
*
*/
public function setUp() {
+ parent::setUp();
Configure::write('Cache.disable', true);
$this->Dbo = ConnectionManager::getDataSource('test');
if (!$this->Dbo instanceof Sqlite) {
@@ -100,6 +103,7 @@ public function setUp() {
*
*/
public function tearDown() {
+ parent::tearDown();
Configure::write('Cache.disable', false);
}
@@ -318,4 +322,20 @@ public function testDescribeWithUuidPrimaryKey() {
$this->assertEqual($result['id'], $expected);
$this->Dbo->query('DROP TABLE ' . $tableName);
}
+
+/**
+ * Test virtualFields with functions.
+ *
+ * @return void
+ */
+ public function testVirtualFieldWithFunction() {
+ $this->loadFixtures('User');
+ $User = ClassRegistry::init('User');
+ $User->virtualFields = array('name' => 'SUBSTR(User.user, 5)');
+
+ $result = $User->find('first', array(
+ 'conditions' => array('User.user' => 'garrett')
+ ));
+ $this->assertEquals('ett', $result['User']['name']);
+ }
}

0 comments on commit 43df8d3

Please sign in to comment.