Skip to content
This repository was archived by the owner on Sep 28, 2022. It is now read-only.

Commit bd8272a

Browse files
committed
Add prepare tests
1 parent 2c87b4d commit bd8272a

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

examples/parpare.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
use Swoole\Event;
4+
5+
go(function () {
6+
$pg = new Swoole\Coroutine\PostgreSQL();
7+
$conn = $pg->connect("host=127.0.0.1;port=5432;dbname=test;user=postgres;password=postgres");
8+
if (!$conn) {
9+
var_dump($pg->error);
10+
return;
11+
}
12+
13+
$prepare_result = $pg->prepare('key', "INSERT INTO weather(city, temp_lo, temp_hi, prcp, date)
14+
VALUES ($1, $2, $3, $4, $5) RETURNING id");
15+
var_dump($prepare_result);
16+
$execute_result = $pg->execute('key', ['Beijing', rand(1000, 99999), 10, 0.75, '1993-11-23']);
17+
18+
var_dump($execute_result);
19+
});
20+
21+
Event::wait();

tests/unit/PostgreSQLTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ public function testInsert()
3535
});
3636
}
3737

38+
public function testPrepare()
39+
{
40+
run(function () {
41+
$pg = $this->getConn();
42+
$prepare_result = $pg->prepare('key', "INSERT INTO weather(city, temp_lo, temp_hi, prcp, date)
43+
VALUES ($1, $2, $3, $4, $5) RETURNING id");
44+
$this->assertNotFalse($prepare_result, (string) $pg->error);
45+
$execute_result = $pg->execute('key', ['Beijing', rand(1000, 99999), 10, 0.75, '1993-11-23']);
46+
$this->assertNotFalse($execute_result, (string) $pg->error);
47+
});
48+
}
49+
3850
public function testQuery()
3951
{
4052
run(function () {

0 commit comments

Comments
 (0)