Skip to content
Permalink
Browse files

Fix method signatures of database drivers.

They were incompatible with Datasource.
Add tests for MySQL and SQLite as their implementation changed a bit.
Update docs for Postgres.

Fixes #2100
  • Loading branch information...
markstory committed Oct 15, 2011
1 parent 6bf6d79 commit 6d9b709c7a5d140c6f44ad372825d849de626174
@@ -292,19 +292,21 @@ public function getCharsetName($name) {
/**
* Returns an array of the fields in given table name.
*
* @param Model $model Name of database table to inspect or model instance
* @param Model|string $model Name of database table to inspect or model instance
* @return array Fields in table. Keys are name and type
* @throws CakeException
*/
public function describe(Model $model) {
public function describe($model) {
$cache = parent::describe($model);
if ($cache != null) {
return $cache;
}
$table = $this->fullTableName($model);
$fields = false;
$cols = $this->_execute('SHOW FULL COLUMNS FROM ' . $this->fullTableName($model));
$cols = $this->_execute('SHOW FULL COLUMNS FROM ' . $table);
if (!$cols) {
throw new CakeException(__d('cake_dev', 'Could not describe table for %s', $model->name));
throw new CakeException(__d('cake_dev', 'Could not describe table for %s', $table));
}
foreach ($cols as $column) {
@@ -184,7 +184,7 @@ public function listSources($data = null) {
/**
* Returns an array of the fields in given table name.
*
* @param Model $model Name of database table to inspect
* @param Model|string $model Name of database table to inspect
* @return array Fields in table. Keys are name and type
*/
public function describe($model) {
@@ -156,16 +156,17 @@ public function listSources($data = null) {
/**
* Returns an array of the fields in given table name.
*
* @param Model $model
* @param Model|string $model Either the model or table name you want described.
* @return array Fields in table. Keys are name and type
*/
public function describe(Model $model) {
public function describe($model) {
$cache = parent::describe($model);
if ($cache != null) {
return $cache;
}
$table = $this->fullTableName($model);
$fields = array();
$result = $this->_execute('PRAGMA table_info(' . $model->tablePrefix . $model->table . ')');
$result = $this->_execute('PRAGMA table_info(' . $table . ')');
foreach ($result as $column) {
$column = (array) $column;
@@ -187,7 +188,7 @@ public function describe(Model $model) {
}
$result->closeCursor();
$this->_cacheDescription($model->tablePrefix . $model->table, $fields);
$this->_cacheDescription($table, $fields);
return $fields;
}
@@ -195,11 +195,11 @@ public function listSources($data = null) {
/**
* Returns an array of the fields in given table name.
*
* @param Model $model Model object to describe
* @param Model|string $model Model object to describe, or a string table name.
* @return array Fields in table. Keys are name and type
* @throws CakeException
*/
public function describe(Model $model) {
public function describe($model) {
$cache = parent::describe($model);
if ($cache != null) {
return $cache;
@@ -219,7 +219,7 @@ public function describe(Model $model) {
WHERE TABLE_NAME = '" . $table . "'"
);
if (!$cols) {
throw new CakeException(__d('cake_dev', 'Could not describe table for %s', $model->name));
throw new CakeException(__d('cake_dev', 'Could not describe table for %s', $table));
}
foreach ($cols as $column) {
@@ -761,6 +761,26 @@ public function testVirtualFieldSeparators() {
$this->assertEqual($expected, $result);
}

/**
* Test describe() on a fixture.
*
* @return void
*/
public function testDescribe() {
$this->loadFixtures('Apple');

$model = new Apple();
$result = $this->Dbo->describe($model);

$this->assertTrue(isset($result['id']));
$this->assertTrue(isset($result['color']));

$result = $this->Dbo->describe($model->useTable);

$this->assertTrue(isset($result['id']));
$this->assertTrue(isset($result['color']));
}

/**
* test that a describe() gets additional fieldParameters
*
@@ -292,7 +292,10 @@ public function testDescribe() {
'length' => null,
)
);
$this->assertEqual($expected, $result);
$this->assertEquals($expected, $result);
$result = $this->Dbo->describe($Model->useTable);
$this->assertEquals($expected, $result);
}
/**

0 comments on commit 6d9b709

Please sign in to comment.
You can’t perform that action at this time.