Hi,

I'd like to notify about a little bug in error reporting. CakePHP
reports that theres a "Missing Database Table" when actually theres
"Missing Database Connection".

To reproduce this create some fake database config and attempt to use
some model using that fake config. I tried it on latest 1.2 release:

$ svn co https://svn.cakephp.org/repo/branches/1.2.x.x
$ cat cake/VERSION.txt
///////////////////////////////////////////////////////////////////////////////////////////////////////////
//
+---------------------------------------------------------------------------------------------------
+ //
// + $Id: VERSION.txt 8166 2009-05-04 21:17:19Z gwoo $
// + Last Modified: $Date: 2009-05-05 00:17:19 +0300 (Tue, 05 May
2009) $
// + Modified By: $LastChangedBy: gwoo $
//
+---------------------------------------------------------------------------------------------------
+ //
///////////////////////////////////////////////////////////////////////////////////////////////////////////

1.2.3.8166
$ cat | patch -p0
Index: app/config/routes.php
===================================================================
--- app/config/routes.php       (revision 8263)
+++ app/config/routes.php       (working copy)
@@ -31,9 +31,9 @@
  * its action called 'display', and we pass a param to select the
view file
  * to use (in this case, /app/views/pages/home.ctp)...
  */
-       Router::connect('/', array('controller' => 'pages', 'action' =>
'display', 'home'));
+//     Router::connect('/', array('controller' => 'pages', 'action' =>
'display', 'home'));
 /**
  * ...and connect the rest of 'Pages' controller's urls.
  */
-       Router::connect('/pages/*', array('controller' => 'pages', 'action'
=> 'display'));
-?>
\ No newline at end of file
+//     Router::connect('/pages/*', array('controller' => 'pages',
'action' => 'display'));
+?>
Index: app/config/database.php
===================================================================
--- app/config/database.php     (revision 0)
+++ app/config/database.php     (revision 0)
@@ -0,0 +1,14 @@
+<?php
+class DATABASE_CONFIG {
+
+       var $default = array(
+               'driver' => 'mysql',
+               'persistent' => false,
+               'host' => 'localhost',
+               'login' => 'user',
+               'password' => 'password',
+               'database' => 'database_name',
+               'prefix' => '',
+       );
+}
+?>
Index: app/controllers/index_controller.php
===================================================================
--- app/controllers/index_controller.php        (revision 0)
+++ app/controllers/index_controller.php        (revision 0)
@@ -0,0 +1,7 @@
+<?php
+
+class IndexController extends AppController
+{
+       var $uses = array('Fake');
+       function index() {}
+}
^D


Now CakePHP reports:

  Missing Database Table
  Error: Database table fakes for model Fake was not found.

It actually should be "Missing Database Connection". The following
patch fixes this:

$ cat | patch -p0
Index: cake/libs/model/model.php
===================================================================
--- cake/libs/model/model.php   (revision 42)
+++ cake/libs/model/model.php   (working copy)
@@ -2611,6 +2611,10 @@
                        $this->useDbConfig = $dataSource;
                }
                $db =& ConnectionManager::getDataSource($this->useDbConfig);
+               if (empty($db) || !is_object($db) || !$db->isConnected()) {
+                       return $this->cakeError('missingConnection', array(array
('className' => $this->alias)));
+               }
+
                if (!empty($oldConfig) && isset($db->config['prefix'])) {
                        $oldDb =& ConnectionManager::getDataSource($oldConfig);

@@ -2620,10 +2624,6 @@
                } elseif (isset($db->config['prefix'])) {
                        $this->tablePrefix = $db->config['prefix'];
                }
-
-               if (empty($db) || $db == null || !is_object($db)) {
-                       return $this->cakeError('missingConnection', array(array
('className' => $this->alias)));
-               }
        }
 /**
  * Gets the DataSource to which this model is bound.
@@ -2866,4 +2866,4 @@
 if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
        Overloadable::overload('Model');
 }
-?>
\ No newline at end of file
+?>
^D


Sorry for the noise if this is not the right place to report bugs/
purpose patches.

Giedrius

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to