mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Use String::tokenize() to split up fields.
It is slightly more intelligent than explode() Solves basic problems in Sqlite with virtualFields. Fixes #2163
This commit is contained in:
parent
010abd9e18
commit
43df8d34e7
2 changed files with 22 additions and 1 deletions
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
|
||||
App::uses('DboSource', 'Model/Datasource');
|
||||
App::uses('String', 'Utility');
|
||||
|
||||
/**
|
||||
* DBO implementation for the SQLite3 DBMS.
|
||||
|
@ -281,7 +282,7 @@ class Sqlite extends DboSource {
|
|||
$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('Model', 'Model');
|
|||
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 @@ class SqliteTest extends CakeTestCase {
|
|||
*
|
||||
*/
|
||||
public function tearDown() {
|
||||
parent::tearDown();
|
||||
Configure::write('Cache.disable', false);
|
||||
}
|
||||
|
||||
|
@ -318,4 +322,20 @@ class SqliteTest extends CakeTestCase {
|
|||
$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']);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue