First of all, what version of CakePHP are you using? I assume this is CakePHP 1.2 +.
Problem
I am not familiar with SQL Server 2005 (as well as any other versions), but after some research, I think the problem is with the DboMssql::listSources() method, which selects the available table names from INFORMATION_SCHEMA.TABLES , and therefore it isnβt " see "any available views.
Decision
Modify DboMssql::listSources() to select available table names from sys.tables or, if I am mistaken about sys.tables , to additionally select names from INFORMATION_SCHEMA.VIEWS .
Thus, in order not to get confused with the main CakePHP files, you need to create your own data source that extends DboMssql and cancels the ::listSources() method. For this you need:
Create <path/to/app>/models/datasources/dbo/dbo_custom_mssql.php :
<?php App::import('Datasource', 'DboMssql'); class DboCustomMssql extends DboMssql { public function listSources() { $cache = DboSource::listSources(); if ($cache != null) { return $cache; } $result = $this->fetchAll('SELECT TABLE_NAME FROM SYS.TABLES', false); if (!$result || empty($result)) { return array(); } else { $tables = array(); foreach ($result as $table) { $tables[] = $table[0]['TABLE_NAME']; } DboSource::listSources($tables); return $tables; } } }
- Change
config/database.php config: 'driver' => 'custom_mssql' - Test
NB: Worst of all, the interface DboMssql::listSources() is incorrect (without the additional argument $data (for example, Datasource::listSources() declares)) and does not provide any extension point, therefore, to have the source list cached, we forced to call DboSource::listSources() instead of the broken parent::listSources() .
ljank source share