Esempio n. 1
0
 public function testHstore()
 {
     $this->assertEquals('aaa', Pgsql::encodeHstore('aaa'));
     $this->assertNull(Pgsql::encodeHstore(''));
     $this->assertNull(Pgsql::encodeHstore(NULL));
     $this->assertNull(Pgsql::encodeHstore(array()));
     $this->assertSame(array(), Pgsql::decodeHstore(''));
     $this->assertSame(array(), Pgsql::decodeHstore(NULL));
     $data = array('a' => NULL, 'b' => 'b', 'c' => 'a"b', 'd' => 'a\'b', 'e' => 'a\\b', 'f' => 123, 'g' => '', 'h' => 'a"b\'c\\d', 'i' => 'a=>b', 'j' => '"a"=>"b", ', 'k=>' => 'ab', '"l=>' => 'a=>b', 'm' => 'a,b', 'n' => 0);
     $expr = Pgsql::encodeHstore($data);
     $this->assertInstanceof('\\Lysine\\Service\\DB\\Expr', $expr);
     $adapter = $this->adapter;
     $hstore = $adapter->execute('select ' . $expr)->getCol();
     $this->assertInternalType('string', $hstore);
     $decoded = Pgsql::decodeHstore($hstore);
     foreach ($decoded as $key => $val) {
         $this->assertArrayHasKey($key, $data);
         // 恢复回来的数据除NULL外,全部都是字符串类型
         $expect = $data[$key] === NULL ? NULL : (string) $data[$key];
         $this->assertSame($expect, $decoded[$key]);
     }
 }
Esempio n. 2
0
 public function store($value, array $attribute)
 {
     if ($value === array()) {
         return null;
     }
     return \Lysine\Service\DB\Adapter\Pgsql::encodeHstore($value);
 }