mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Merge remote branch 'upstream/2.0' into 2.0
This commit is contained in:
commit
37b98ff1a6
4 changed files with 27 additions and 14 deletions
|
@ -148,14 +148,14 @@ class DboMysql extends DboSource {
|
|||
$flags[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES ' . $config['encoding'];
|
||||
}
|
||||
$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['password'],
|
||||
$flags
|
||||
);
|
||||
$this->connected = true;
|
||||
} catch (PDOException $e) {
|
||||
$this->errors[] = $e->getMessage();
|
||||
throw new MissingConnectionException(array('class' => $e->getMessage()));
|
||||
}
|
||||
|
||||
$this->_useAlias = (bool)version_compare($this->getVersion(), "4.1", ">=");
|
||||
|
@ -238,7 +238,7 @@ class DboMysql extends DboSource {
|
|||
foreach ($this->map as $col => $meta) {
|
||||
list($table, $column, $type) = $meta;
|
||||
$resultRow[$table][$column] = $row[$col];
|
||||
if ($type == 'boolean') {
|
||||
if ($type == 'boolean' && !is_null($row[$col])) {
|
||||
$resultRow[$table][$column] = $this->boolean($resultRow[$table][$column]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -130,7 +130,7 @@ class DboPostgres extends DboSource {
|
|||
$this->_execute('SET search_path TO ' . $config['schema']);
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
$this->errors[] = $e->getMessage();
|
||||
throw new MissingConnectionException(array('class' => $e->getMessage()));
|
||||
}
|
||||
|
||||
return $this->connected;
|
||||
|
@ -707,7 +707,7 @@ class DboPostgres extends DboSource {
|
|||
|
||||
switch ($type) {
|
||||
case 'bool':
|
||||
$resultRow[$table][$column] = $this->boolean($row[$index]);
|
||||
$resultRow[$table][$column] = is_null($row[$index]) ? null : $this->boolean($row[$index]);
|
||||
break;
|
||||
case 'binary':
|
||||
case 'bytea':
|
||||
|
|
|
@ -114,9 +114,8 @@ class DboSqlite extends DboSource {
|
|||
$this->_connection = new PDO('sqlite:' . $config['database'], null, null, $flags);
|
||||
$this->_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$this->connected = true;
|
||||
}
|
||||
catch(PDOException $e) {
|
||||
$this->errors[] = $e->getMessage();
|
||||
} catch(PDOException $e) {
|
||||
throw new MissingConnectionException(array('class' => $e->getMessage()));
|
||||
}
|
||||
return $this->connected;
|
||||
}
|
||||
|
@ -285,7 +284,7 @@ class DboSqlite extends DboSource {
|
|||
// so try to figure it out based on the querystring
|
||||
$querystring = $results->queryString;
|
||||
if (stripos($querystring, 'SELECT') === 0) {
|
||||
$last = stripos($querystring, 'FROM');
|
||||
$last = strripos($querystring, 'FROM');
|
||||
if ($last !== false) {
|
||||
$selectpart = substr($querystring, 7, $last - 8);
|
||||
$selects = explode(',', $selectpart);
|
||||
|
@ -335,9 +334,9 @@ class DboSqlite extends DboSource {
|
|||
if ($row = $this->_result->fetch()) {
|
||||
$resultRow = array();
|
||||
foreach ($this->map as $col => $meta) {
|
||||
list($table, $column, $tpye) = $meta;
|
||||
list($table, $column, $type) = $meta;
|
||||
$resultRow[$table][$column] = $row[$col];
|
||||
if ($type === 'boolean') {
|
||||
if ($type == 'boolean' && !is_null($row[$col])) {
|
||||
$resultRow[$table][$column] = $this->boolean($resultRow[$table][$column]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -178,19 +178,19 @@ class DboMysqlTest extends CakeTestCase {
|
|||
|
||||
$this->assertTrue((bool)$this->model->save(array('bool' => 5, 'small_int' => 5)));
|
||||
$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->model->deleteAll(true);
|
||||
|
||||
$this->assertTrue((bool)$this->model->save(array('bool' => 0, 'small_int' => 100)));
|
||||
$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->model->deleteAll(true);
|
||||
|
||||
$this->assertTrue((bool)$this->model->save(array('bool' => true, 'small_int' => 0)));
|
||||
$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->model->deleteAll(true);
|
||||
|
||||
|
@ -3367,4 +3367,18 @@ class DboMysqlTest extends CakeTestCase {
|
|||
$this->assertTrue(Set::matches('/Comment[id=2]', $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'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue