Merge remote branch 'upstream/2.0' into 2.0

This commit is contained in:
Jeremy Harris 2011-01-05 19:07:25 -08:00
commit 37b98ff1a6
4 changed files with 27 additions and 14 deletions

View file

@ -148,14 +148,14 @@ class DboMysql extends DboSource {
$flags[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES ' . $config['encoding']; $flags[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES ' . $config['encoding'];
} }
$this->_connection = new PDO( $this->_connection = new PDO(
"mysql:{$config['host']};port={$config['port']};dbname={$config['database']}", "mysql:host={$config['host']};port={$config['port']};dbname={$config['database']}",
$config['login'], $config['login'],
$config['password'], $config['password'],
$flags $flags
); );
$this->connected = true; $this->connected = true;
} catch (PDOException $e) { } catch (PDOException $e) {
$this->errors[] = $e->getMessage(); throw new MissingConnectionException(array('class' => $e->getMessage()));
} }
$this->_useAlias = (bool)version_compare($this->getVersion(), "4.1", ">="); $this->_useAlias = (bool)version_compare($this->getVersion(), "4.1", ">=");
@ -238,7 +238,7 @@ class DboMysql extends DboSource {
foreach ($this->map as $col => $meta) { foreach ($this->map as $col => $meta) {
list($table, $column, $type) = $meta; list($table, $column, $type) = $meta;
$resultRow[$table][$column] = $row[$col]; $resultRow[$table][$column] = $row[$col];
if ($type == 'boolean') { if ($type == 'boolean' && !is_null($row[$col])) {
$resultRow[$table][$column] = $this->boolean($resultRow[$table][$column]); $resultRow[$table][$column] = $this->boolean($resultRow[$table][$column]);
} }
} }

View file

@ -130,7 +130,7 @@ class DboPostgres extends DboSource {
$this->_execute('SET search_path TO ' . $config['schema']); $this->_execute('SET search_path TO ' . $config['schema']);
} }
} catch (PDOException $e) { } catch (PDOException $e) {
$this->errors[] = $e->getMessage(); throw new MissingConnectionException(array('class' => $e->getMessage()));
} }
return $this->connected; return $this->connected;
@ -707,7 +707,7 @@ class DboPostgres extends DboSource {
switch ($type) { switch ($type) {
case 'bool': case 'bool':
$resultRow[$table][$column] = $this->boolean($row[$index]); $resultRow[$table][$column] = is_null($row[$index]) ? null : $this->boolean($row[$index]);
break; break;
case 'binary': case 'binary':
case 'bytea': case 'bytea':

View file

@ -114,9 +114,8 @@ class DboSqlite extends DboSource {
$this->_connection = new PDO('sqlite:' . $config['database'], null, null, $flags); $this->_connection = new PDO('sqlite:' . $config['database'], null, null, $flags);
$this->_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->connected = true; $this->connected = true;
} } catch(PDOException $e) {
catch(PDOException $e) { throw new MissingConnectionException(array('class' => $e->getMessage()));
$this->errors[] = $e->getMessage();
} }
return $this->connected; return $this->connected;
} }
@ -285,7 +284,7 @@ class DboSqlite extends DboSource {
// so try to figure it out based on the querystring // so try to figure it out based on the querystring
$querystring = $results->queryString; $querystring = $results->queryString;
if (stripos($querystring, 'SELECT') === 0) { if (stripos($querystring, 'SELECT') === 0) {
$last = stripos($querystring, 'FROM'); $last = strripos($querystring, 'FROM');
if ($last !== false) { if ($last !== false) {
$selectpart = substr($querystring, 7, $last - 8); $selectpart = substr($querystring, 7, $last - 8);
$selects = explode(',', $selectpart); $selects = explode(',', $selectpart);
@ -335,9 +334,9 @@ class DboSqlite extends DboSource {
if ($row = $this->_result->fetch()) { if ($row = $this->_result->fetch()) {
$resultRow = array(); $resultRow = array();
foreach ($this->map as $col => $meta) { foreach ($this->map as $col => $meta) {
list($table, $column, $tpye) = $meta; list($table, $column, $type) = $meta;
$resultRow[$table][$column] = $row[$col]; $resultRow[$table][$column] = $row[$col];
if ($type === 'boolean') { if ($type == 'boolean' && !is_null($row[$col])) {
$resultRow[$table][$column] = $this->boolean($resultRow[$table][$column]); $resultRow[$table][$column] = $this->boolean($resultRow[$table][$column]);
} }
} }

View file

@ -178,19 +178,19 @@ class DboMysqlTest extends CakeTestCase {
$this->assertTrue((bool)$this->model->save(array('bool' => 5, 'small_int' => 5))); $this->assertTrue((bool)$this->model->save(array('bool' => 5, 'small_int' => 5)));
$result = $this->model->find('first'); $result = $this->model->find('first');
$this->assertIdentical($result['Tinyint']['bool'], '1'); $this->assertIdentical($result['Tinyint']['bool'], true);
$this->assertIdentical($result['Tinyint']['small_int'], '5'); $this->assertIdentical($result['Tinyint']['small_int'], '5');
$this->model->deleteAll(true); $this->model->deleteAll(true);
$this->assertTrue((bool)$this->model->save(array('bool' => 0, 'small_int' => 100))); $this->assertTrue((bool)$this->model->save(array('bool' => 0, 'small_int' => 100)));
$result = $this->model->find('first'); $result = $this->model->find('first');
$this->assertIdentical($result['Tinyint']['bool'], '0'); $this->assertIdentical($result['Tinyint']['bool'], false);
$this->assertIdentical($result['Tinyint']['small_int'], '100'); $this->assertIdentical($result['Tinyint']['small_int'], '100');
$this->model->deleteAll(true); $this->model->deleteAll(true);
$this->assertTrue((bool)$this->model->save(array('bool' => true, 'small_int' => 0))); $this->assertTrue((bool)$this->model->save(array('bool' => true, 'small_int' => 0)));
$result = $this->model->find('first'); $result = $this->model->find('first');
$this->assertIdentical($result['Tinyint']['bool'], '1'); $this->assertIdentical($result['Tinyint']['bool'], true);
$this->assertIdentical($result['Tinyint']['small_int'], '0'); $this->assertIdentical($result['Tinyint']['small_int'], '0');
$this->model->deleteAll(true); $this->model->deleteAll(true);
@ -3367,4 +3367,18 @@ class DboMysqlTest extends CakeTestCase {
$this->assertTrue(Set::matches('/Comment[id=2]', $result)); $this->assertTrue(Set::matches('/Comment[id=2]', $result));
$this->assertFalse(Set::matches('/Comment[id=10]', $result)); $this->assertFalse(Set::matches('/Comment[id=10]', $result));
} }
/**
* @expectedException MissingConnectionException
* @return void
*/
function testExceptionOnBrokenConnection() {
$dbo = new DboMysql(array(
'driver' => 'mysql',
'host' => 'imaginary_host',
'login' => 'mark',
'password' => 'inyurdatabase',
'database' => 'imaginary'
));
}
} }