mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Fixing bug in getEncoding/setEncoding for PostgreSQL.
Fixes #2028 Signed-off-by: mark_story <mark@mark-story.com>
This commit is contained in:
parent
924e283012
commit
5eb4c5c6da
2 changed files with 25 additions and 5 deletions
|
@ -769,10 +769,7 @@ class Postgres extends DboSource {
|
|||
* @return boolean True on success, false on failure
|
||||
*/
|
||||
public function setEncoding($enc) {
|
||||
if ($this->_execute("SET NAMES '?'", array($enc))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return $this->_execute('SET NAMES ' . $this->value($enc)) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -781,7 +778,11 @@ class Postgres extends DboSource {
|
|||
* @return string The database encoding
|
||||
*/
|
||||
public function getEncoding() {
|
||||
$cosa = $this->_execute('SHOW client_encoding')->fetch();
|
||||
$result = $this->_execute('SHOW client_encoding')->fetch();
|
||||
if ($result === false) {
|
||||
return false;
|
||||
}
|
||||
return (isset($result['client_encoding'])) ? $result['client_encoding'] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -832,4 +832,23 @@ class PostgresTest extends CakeTestCase {
|
|||
$this->assertEqual(2, substr_count($result, 'field_two'), 'Too many fields');
|
||||
$this->assertFalse(strpos(';ALTER', $result), 'Too many semi colons');
|
||||
}
|
||||
|
||||
/**
|
||||
* test encoding setting.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEncoding() {
|
||||
$result = $this->Dbo->setEncoding('utf8');
|
||||
$this->assertTrue($result) ;
|
||||
|
||||
$result = $this->Dbo->getEncoding();
|
||||
$this->assertEqual('utf8', $result) ;
|
||||
|
||||
$result = $this->Dbo->setEncoding('EUC-JP');
|
||||
$this->assertTrue($result) ;
|
||||
|
||||
$result = $this->Dbo->getEncoding();
|
||||
$this->assertEqual('EUC-JP', $result) ;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue