diff --git a/test.php b/test.php new file mode 100644 index 0000000..ca17c26 --- /dev/null +++ b/test.php @@ -0,0 +1,56 @@ +getPgsqlHost()} dbname={$c->getPgsqlDatabase()} " + . "user={$c->getPgsqlUser()} password={$c->getPgsqlPassword()}"; + $conn = pg_connect($connStr); + + if (!$conn) { + throw new Exception('Failed to connect to PostgreSQL'); + } + + createPgsqlTestTable($conn); + return $conn; +} + +function createPgsqlTestTable(Connection $conn): void +{ + $sql = "CREATE TABLE Users ( + user_id SERIAL PRIMARY KEY, + name VARCHAR(50) NOT NULL, + dob DATE NOT NULL, + weight REAL NOT NULL, + isDisabled BOOLEAN NOT NULL, + uuid bytea NULL + )"; + + if (!pg_query($conn, $sql)) { + throw new Exception('Failed to create PostgreSQL test table: ' . pg_last_error($conn)); + } +} diff --git a/test/DbTestCase.php b/test/DbTestCase.php index 8422519..f521687 100644 --- a/test/DbTestCase.php +++ b/test/DbTestCase.php @@ -62,6 +62,7 @@ public function testTransactions(PeachySql $peachySql): void ]; $id = $peachySql->insertRow($this->table, $colVals)->id; + // this won't work with pgsql $sql = "SELECT user_id, isDisabled FROM {$this->table} WHERE user_id = ?"; $result = $peachySql->query($sql, [$id]); @@ -134,6 +135,7 @@ public function testIteratorQuery(PeachySql $peachySql): void $this->assertSame($colVals, $colValsCompare); // use a prepared statement to update both of the rows + // this won't work with pgsql $sql = "UPDATE {$this->table} SET name = ? WHERE user_id = ?"; $_id = $_name = null; $stmt = $peachySql->prepare($sql, [&$_name, &$_id]); @@ -240,6 +242,7 @@ public function testSelectFromBinding(PeachySql $peachySql): void $row = ['name' => 'Test User', 'dob' => '2000-01-01', 'weight' => 123, 'isDisabled' => true]; $id = $peachySql->insertRow($this->table, $row)->id; + // this won't work with pgsql $result = $peachySql->select(new SqlParams("SELECT name, ? AS bound FROM {$this->table}", ['value'])) ->where(['user_id' => $id])->query()->getFirst(); diff --git a/test/src/Config.php b/test/src/Config.php index 68dd972..2fe874c 100644 --- a/test/src/Config.php +++ b/test/src/Config.php @@ -29,6 +29,26 @@ public function getMysqlDatabase(): string return 'PeachySQL'; } + public function getPgsqlHost(): string + { + return 'localhost'; + } + + public function getPgsqlDatabase(): string + { + return 'PeachySQL'; + } + + public function getPgsqlUser(): string + { + return 'postgres'; + } + + public function getPgsqlPassword(): string + { + return ''; + } + public function getSqlsrvServer(): string { return '(local)\SQLEXPRESS';