Skip to content
Permalink
Browse files

Fixing bug in getEncoding/setEncoding for PostgreSQL.

Fixes #2028

Signed-off-by: mark_story <mark@mark-story.com>
  • Loading branch information...
kaz29 authored and markstory committed Oct 4, 2011
1 parent 924e283 commit 5eb4c5c6da57248f91870933084ec7a61dda1fa9
@@ -769,10 +769,7 @@ public function boolean($data, $quote = false) {
* @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 @@ public function setEncoding($enc) {
* @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 @@ public function testAlteringTwoTables() {
$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) ;
}
}

0 comments on commit 5eb4c5c

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