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

Commit f5eda17

Browse files
committed
Sync master, Refactor
1 parent 1518395 commit f5eda17

File tree

4 files changed

+212
-270
lines changed

4 files changed

+212
-270
lines changed

config.m4

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ if test "$PHP_SWOOLE_POSTGRESQL" != "no"; then
8282

8383
PHP_ADD_LIBRARY(pthread, 1, SWOOLE_POSTGRESQL_SHARED_LIBADD)
8484

85-
swoole_source_file="swoole_postgresql_coro.cc"
85+
swoole_source_file="swoole_postgresql.cc"
8686

8787
PHP_NEW_EXTENSION(swoole_postgresql, $swoole_source_file, $ext_shared,,, cxx)
8888

examples/timeout.php

+21
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+
$result = $pg->query('select pg_sleep(5)');
13+
if (!$result) {
14+
var_dump($pg->error);
15+
return;
16+
}
17+
$arr = $pg->fetchAll($result);
18+
var_dump($arr);
19+
});
20+
21+
Event::wait();

swoole_postgresql_coro.h renamed to php_swoole_postgresql.h

+5-39
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
| [email protected] so we can mail you a copy immediately. |
1212
+----------------------------------------------------------------------+
1313
| Author: Zhenyu Wu <[email protected]> |
14+
| Tianfeng Han <[email protected]> |
1415
+----------------------------------------------------------------------+
1516
*/
1617
#ifndef SWOOLE_POSTGRESQL_H_
@@ -20,10 +21,10 @@
2021
#include "ext/swoole/ext-src/php_swoole_cxx.h"
2122
#include "config.h"
2223

23-
#define PHP_SWOOLE_EXT_POSTGRESQL_VERSION "4.7.0"
24-
#define PHP_SWOOLE_EXT_POSTGRESQL_VERSION_ID 40700
24+
#define PHP_SWOOLE_EXT_PLUS_VERSION "4.7.0"
25+
#define PHP_SWOOLE_EXT_PLUS_VERSION_ID 40700
2526

26-
#if SWOOLE_API_VERSION_ID < 0x202107a
27+
#if SWOOLE_API_VERSION_ID < 0x202108a
2728
#error "Ext version does not match the Swoole version"
2829
#endif
2930

@@ -35,41 +36,6 @@
3536
#include <postgresql/libpq-fe.h>
3637
#endif
3738

38-
enum pg_query_type
39-
{
40-
NORMAL_QUERY, META_DATA, PREPARE
41-
};
42-
43-
struct pg_object {
44-
PGconn *conn;
45-
swoole::network::Socket *socket;
46-
swoole::Coroutine *co;
47-
PGresult *result;
48-
zval *object;
49-
zval _object;
50-
ConnStatusType status;
51-
enum pg_query_type request_type;
52-
int row;
53-
bool connected;
54-
double timeout;
55-
bool ignore_notices;
56-
bool log_notices;
57-
swoole::TimerNode *timer;
58-
};
59-
60-
#define PGSQL_ASSOC 1<<0
61-
#define PGSQL_NUM 1<<1
62-
#define PGSQL_BOTH (PGSQL_ASSOC|PGSQL_NUM)
63-
64-
/* from postgresql/src/include/catalog/pg_type.h */
65-
#define BOOLOID 16
66-
#define BYTEAOID 17
67-
#define INT2OID 21
68-
#define INT4OID 23
69-
#define INT8OID 20
70-
#define TEXTOID 25
71-
#define OIDOID 26
72-
#define FLOAT4OID 700
73-
#define FLOAT8OID 701
39+
#include <zend_portability.h>
7440

7541
#endif

0 commit comments

Comments
 (0)