Fixing bug in getEncoding/setEncoding for PostgreSQL.

Fixes #2028

Signed-off-by: mark_story <mark@mark-story.com>
This commit is contained in:
kaz29 2011-10-04 17:18:52 +09:00 committed by mark_story
parent 924e283012
commit 5eb4c5c6da
2 changed files with 25 additions and 5 deletions

View file

@ -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;
}
/**

View file

@ -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) ;
}
}