public function testSelectGeneral() { $oDB = new \LibPostgres\LibPostgresDriver(array('host' => getenv('TEST_HOST') ?: 'localhost', 'port' => getenv('TEST_PORT') ?: 5432, 'user_name' => getenv('TEST_USER_NAME'), 'user_password' => getenv('TEST_PASSWORD'), 'db_name' => getenv('TEST_DB_NAME'))); // selectField and ?d $iMin = 100; $iMax = 200; $iResult = $oDB->selectField("\n SELECT max(t)\n FROM generate_series(?d, ?d) AS t;\n ", $iMin, $iMax); $this->assertEquals($iResult, $iMax); // selectRecord and ?w $aResult = $oDB->selectRecord("\n SELECT ?w || t::varchar AS field, md5(?w || t::varchar) AS md5\n FROM generate_series(1, 10) AS t\n ORDER BY t DESC\n LIMIT 1\n ", "STR'ING", "STR'ING"); $this->assertEquals($aResult['field'], "STR'ING10"); $this->assertEquals($aResult['md5'], md5("STR'ING10")); // selectColumn and ?h $aColumn = $oDB->selectColumn("\n WITH hs AS (\n SELECT ?h || ('count => ' || t)::hstore AS h\n FROM generate_series(0, 10) AS t\n )\n SELECT (h->'field')::varchar || (h->'\"foo\"')::varchar || (h->'baz')::varchar || (h->'count')::varchar\n FROM hs\n ORDER BY (h->'count')::integer;\n ", array('field' => '"FIELD"', '"foo"' => '\\"bar\\"', 'baz' => "\n\t", 'normal' => str_repeat('1', 100))); $this->assertEquals($aColumn[3], '"FIELD"\\"bar\\"' . "\n\t" . '3'); // selectField and ?j / ?jb $sString1 = "é"; $sString2 = "bla'bla\"? абв"; $sResult = $oDB->selectField("\n SELECT (?jb->>'first') || (?j->>'second')\n ", array('first' => $sString1), array('second' => $sString2)); $this->assertEquals($sResult, $sString1 . $sString2); }
public function testPgPconnectGeneral() { // pg_pconnect $oDB1 = new \LibPostgres\LibPostgresDriver(array('host' => getenv('TEST_HOST') ?: 'localhost', 'port' => getenv('TEST_PORT') ?: 5432, 'user_name' => getenv('TEST_USER_NAME'), 'user_password' => getenv('TEST_PASSWORD'), 'db_name' => getenv('TEST_DB_NAME'), 'persistance' => 1)); $iMin = 105; $iMax = 201; $iResult = $oDB1->selectField("\n SELECT sum(t)\n FROM generate_series(?d, ?d) AS t;\n ", $iMin, $iMax); $this->assertEquals($iResult, ($iMax + $iMin) * (($iMax - $iMin + 1) / 2)); // pg_pconnect(..., PGSQL_CONNECT_FORCE_NEW) $oDB2 = new \LibPostgres\LibPostgresDriver(array('host' => getenv('TEST_HOST') ?: 'localhost', 'port' => getenv('TEST_PORT') ?: 5432, 'user_name' => getenv('TEST_USER_NAME'), 'user_password' => getenv('TEST_PASSWORD'), 'db_name' => getenv('TEST_DB_NAME'), 'persistance' => PGSQL_CONNECT_FORCE_NEW)); $iMin = 405; $iMax = 1201; $iResult = $oDB2->selectField("\n SELECT sum(t)\n FROM generate_series(?d, ?d) AS t;\n ", $iMin, $iMax); $this->assertEquals($iResult, ($iMax + $iMin) * (($iMax - $iMin + 1) / 2)); }