Exemple #1
0
 public function testPgsqlQuoteIdentifier()
 {
     $db = new Pgsql(array('dsn' => 'pgsql:host=127.0.0.1;dbname=foobar'));
     $tests = array('foobar' => '"foobar"', 'foo.bar' => '"foo"."bar"');
     foreach ($tests as $identifier => $expect) {
         $this->assertEquals($expect, $db->quoteIdentifier($identifier));
     }
 }
Exemple #2
0
 public function testPgArray()
 {
     $this->assertNull(Pgsql::encodeArray(NULL));
     $this->assertNull(Pgsql::encodeArray(array()));
     $this->assertSame(array(), Pgsql::decodeArray(''));
     $this->assertSame(array(), Pgsql::decodeArray(NULL));
     $data_set = array(array('1', '2', '3'), array('a', 'b', 'c'), array('a\'', 'b,', 'c"', 'd\\d', 'e'), array('', NULL, 'a'), array('1', NULL, 'c"'));
     $adapter = $this->adapter;
     foreach ($data_set as $data) {
         $expr = Pgsql::encodeArray($data);
         $this->assertInstanceof('\\Lysine\\Service\\DB\\Expr', $expr);
         $pg_array = $adapter->execute("select ({$expr})::varchar[]")->getCol();
         $this->assertInternalType('string', $pg_array);
         $decoded = Pgsql::decodeArray($pg_array);
         $this->assertInternalType('array', $decoded);
         $this->assertSame($data, $decoded);
     }
 }
Exemple #3
0
 public function restore($value, array $attribute)
 {
     if ($value === null) {
         return array();
     }
     return \Lysine\Service\DB\Adapter\Pgsql::decodeHstore($value);
 }