Skip to content

Commit b4ba97c

Browse files
authored
兼容 TDengine 3.0 (#10)
* 尝试适配 tdengine 3.0 * 修复 * 修复 * 修复 * 修复 * 修复 * 修复 * test * test * test * 修复 3.0 兼容 * 修复 * 支持更多字段类型 * 修复 * 修复 * 修复 * 修复
1 parent 053c201 commit b4ba97c

File tree

13 files changed

+137
-46
lines changed

13 files changed

+137
-46
lines changed

.github/script/build-tdengine.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ call "C:\Program Files (x86)\Microsoft Visual Studio\%VS_VERSION%\Enterprise\VC\
1111

1212
cmake .. -G "NMake Makefiles" -DBUILD_JDBC=false -DTD_BUILD_HTTP=false -DTD_BUILD_LUA=false
1313

14+
nmake
15+
1416
nmake install
1517

1618
copy "C:\TDengine\driver\taos.dll" "C:\Windows\System32"

.github/script/build-tdengine.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
cd /tmp && \
33
git clone --recurse -b ver-${TDENGINE_VERSION} --depth=1 https://github.com/taosdata/TDengine.git && \
44
cd TDengine && \
5-
mkdir release && cd release && cmake -DCMAKE_BUILD_TYPE=Release .. && cmake --build . && make install && \
5+
mkdir debug && cd debug && cmake .. -DBUILD_JDBC=false -DBUILD_TOOLS=false && make -j && make install && \
66
systemctl start taosd

.github/workflows/ci.yml

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,21 @@ jobs:
1111
fail-fast: false
1212
matrix:
1313
php: [7.4, '8.0', 8.1]
14-
swoole: ['4.8.10']
14+
swoole: ['5.0.0', '4.8.10']
1515
tdengine: ['2.4.0.18']
16+
exclude:
17+
- php: 7.4
18+
swoole: '5.0.0'
1619

1720
env:
1821
TDENGINE_VERSION: ${{ matrix.tdengine }}
1922

2023
steps:
2124
- uses: actions/checkout@v2
2225

26+
- name: Prepare
27+
run: sudo apt update && sudo apt install -y gcc cmake build-essential git libssl-dev
28+
2329
- name: Build TDengine
2430
run: sudo -E bash .github/script/build-tdengine.sh
2531

@@ -43,16 +49,16 @@ jobs:
4349
- name: Test
4450
run: ./run-tests.sh
4551

46-
test-tdengine:
52+
test-tdengine-linux:
4753
name: Linux PHP-${{ matrix.php }} TDengine-${{ matrix.tdengine }} Swoole-${{ matrix.swoole }}
4854
runs-on: ubuntu-20.04
4955

5056
strategy:
5157
fail-fast: false
5258
matrix:
5359
php: [8.1]
54-
swoole: ['4.8.10']
55-
tdengine: ['2.6.0.1']
60+
swoole: ['5.0.0']
61+
tdengine: ['3.0.0.1', '2.6.0.1']
5662

5763
env:
5864
TDENGINE_VERSION: ${{ matrix.tdengine }}
@@ -61,7 +67,7 @@ jobs:
6167
- uses: actions/checkout@v2
6268

6369
- name: Prepare
64-
run: sudo apt update && sudo apt install -y valgrind
70+
run: sudo apt update && sudo apt install -y gcc cmake build-essential git libssl-dev
6571

6672
- name: Build TDengine
6773
run: sudo -E bash .github/script/build-tdengine.sh
@@ -131,11 +137,58 @@ jobs:
131137
ext-path: .
132138
tools-path: C:\tools\phpdev
133139
ext-name: tdengine
140+
enable-extension: 1
141+
- name: Test
142+
run: |
143+
php -m
144+
php --ri tdengine
145+
146+
test-tdengine-windows:
147+
name: Windows PHP-${{ matrix.php.version }} TDengine-${{ matrix.tdengine }}
148+
runs-on: ${{ matrix.php.runs-on }}
149+
150+
strategy:
151+
fail-fast: false
152+
matrix:
153+
php:
154+
- version: 8.1
155+
runs-on: windows-2019
156+
vs: 2019
157+
tdengine: ['3.0.0.1', '2.6.0.1']
158+
159+
env:
160+
TDENGINE_VERSION: ${{ matrix.tdengine }}
161+
VS_VERSION: ${{ matrix.php.vs }}
162+
163+
steps:
164+
- uses: actions/checkout@v2
165+
166+
- name: Download TDengine
167+
run: .github\script\download-tdengine.ps1
168+
169+
- name: Build TDengine
170+
shell: cmd
171+
run: .github\script\build-tdengine.bat
172+
173+
- name: Setup PHP
174+
uses: shivammathur/setup-php@v2
175+
with:
176+
php-version: ${{ matrix.php.version }}
177+
tools: pecl
178+
extensions: >
179+
:xdebug
180+
openssl, mbstring, json, sockets,
134181
135-
# Windows 上无法运行 TDengine
136-
# Docker 也无法运行在 WSL2 下
137-
# - name: Test
138-
# run: ./run-tests.ps1
182+
- name: Build extension
183+
uses: ./.github/workflows/winext
184+
with:
185+
ext-path: .
186+
tools-path: C:\tools\phpdev
187+
ext-name: tdengine
188+
- name: Test
189+
run: |
190+
php -m
191+
php --ri tdengine
139192
140193
# test-macos:
141194
# name: MacOS PHP-${{ matrix.php }} TDengine-${{ matrix.tdengine }} Swoole-${{ matrix.swoole }}

.github/workflows/winext/action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ inputs:
4949
description: 'fix pickle.h definitions duplicates'
5050
required: false
5151
default: "1"
52+
enable-extension:
53+
description: 'enable extension'
54+
required: false
55+
default: "1"
5256
outputs:
5357
vcver:
5458
description: 'max retry for downloading things'
@@ -155,5 +159,6 @@ runs:
155159
run: |
156160
IF 1==${{ inputs.install }} ( powershell ${{github.action_path}}\install.ps1 ^
157161
-ExtPath ${{ inputs.ext-path }} ^
162+
-Enable ${{ inputs.enable-extension }} ^
158163
-ExtName tdengine ) || EXIT /b 1
159164
ECHO ::endgroup::

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,9 @@ $stmt->close();
178178
| `TDengine\TSDB_DATA_TYPE_UINT` | uint |
179179
| `TDengine\TSDB_DATA_TYPE_UBIGINT` | ubigint |
180180
| `TDengine\TSDB_DATA_TYPE_JSON` | json |
181+
| `TDengine\TSDB_DATA_TYPE_VARBINARY` | varbinary |
182+
| `TDengine\TSDB_DATA_TYPE_DECIMAL` | decimal |
183+
| `TDengine\TSDB_DATA_TYPE_BLOB` | blob |
184+
| `TDengine\TSDB_DATA_TYPE_MEDIUMBLOB` | mediumblob |
185+
| `TDengine\TSDB_DATA_TYPE_BINARY` | binary |
186+
| `TDengine\TSDB_DATA_TYPE_MAX` | max |

config.m4

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ if test "$PHP_TDENGINE" != "no"; then
113113
-L$TDENGINE_LIBDIR
114114
])
115115

116+
AC_CHECK_TYPES([TAOS_BIND], [
117+
AC_DEFINE(HAVE_TAOS_BIND, 1, [ Have TAOS_BIND ])
118+
], [], [#include <taos.h>])
119+
116120
PHP_ADD_LIBRARY_WITH_PATH(taos, $TDENGINE_LIBDIR, TDENGINE_SHARED_LIBADD)
117121
PHP_SUBST(TDENGINE_SHARED_LIBADD)
118122

config.w32

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ if (PHP_TDENGINE != 'no') {
1717
ARG_WITH('tdengine_dir', 'Include TDengine support (requires TDengine >= 2.0.0)', 'C:\\TDengine');
1818
CHECK_LIB('taos.lib', 'tdengine', PHP_TDENGINE_DIR + '\\driver');
1919
CHECK_HEADER_ADD_INCLUDE('taos.h', 'CFLAGS_TDENGINE', PHP_TDENGINE_DIR + '\\include');
20+
CHECK_FUNC_IN_HEADER('taos.h', 'TAOS_BIND', PHP_TDENGINE_DIR + '\\include')
2021

2122
if (!checkTaosTstrerror())
2223
{

include/ext_taos.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ inline void register_constants(int module_number)
5454
#ifdef TSDB_DATA_TYPE_JSON
5555
REGISTER_NS_LONG_CONSTANT("TDengine", "TSDB_DATA_TYPE_JSON", TSDB_DATA_TYPE_JSON, CONST_CS | CONST_PERSISTENT);
5656
#endif
57+
#ifdef TSDB_DATA_TYPE_VARBINARY
58+
REGISTER_NS_LONG_CONSTANT("TDengine", "TSDB_DATA_TYPE_VARBINARY", TSDB_DATA_TYPE_VARBINARY, CONST_CS | CONST_PERSISTENT);
59+
#endif
60+
#ifdef TSDB_DATA_TYPE_DECIMAL
61+
REGISTER_NS_LONG_CONSTANT("TDengine", "TSDB_DATA_TYPE_DECIMAL", TSDB_DATA_TYPE_DECIMAL, CONST_CS | CONST_PERSISTENT);
62+
#endif
63+
#ifdef TSDB_DATA_TYPE_BLOB
64+
REGISTER_NS_LONG_CONSTANT("TDengine", "TSDB_DATA_TYPE_BLOB", TSDB_DATA_TYPE_BLOB, CONST_CS | CONST_PERSISTENT);
65+
#endif
66+
#ifdef TSDB_DATA_TYPE_MEDIUMBLOB
67+
REGISTER_NS_LONG_CONSTANT("TDengine", "TSDB_DATA_TYPE_MEDIUMBLOB", TSDB_DATA_TYPE_MEDIUMBLOB, CONST_CS | CONST_PERSISTENT);
68+
#endif
69+
#ifdef TSDB_DATA_TYPE_MAX
70+
REGISTER_NS_LONG_CONSTANT("TDengine", "TSDB_DATA_TYPE_MAX", TSDB_DATA_TYPE_MAX, CONST_CS | CONST_PERSISTENT);
71+
#endif
5772
}
5873

5974
#endif /* PHP_EXT_TAOS_H */

include/ext_taos_resource.h

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@
33
#include "ext_taos_connection.h"
44
#include "ext_taos_statement.h"
55

6-
#define check_res(res) \
7-
if (!assert_res(res)) \
8-
{ \
9-
zend_throw_exception_ex(TDengine_Exception_ce, 0, "Invalid res"); \
10-
RETURN_THROWS(); \
11-
}
12-
136
typedef struct {
147
TAOS_RES *res;
158
ConnectionObject *connection;
@@ -22,16 +15,14 @@ typedef struct {
2215
zend_object std;
2316
} ResourceObject;
2417

25-
inline int assert_res(TDengineResource *resource)
26-
{
27-
return resource->res ? 1 : 0;
28-
}
29-
3018
inline void close_resource(TDengineResource *resource)
3119
{
32-
taos_stop_query(resource->res);
33-
taos_free_result(resource->res);
34-
resource->res = nullptr;
20+
if (resource->res)
21+
{
22+
taos_stop_query(resource->res);
23+
taos_free_result(resource->res);
24+
resource->res = nullptr;
25+
}
3526
}
3627

3728
bool fetch_row(zval *zrow, TDengineResource *resource, TAOS_FIELD *fields, int field_count);

include/ext_tdengine.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ END_EXTERN_C()
5858
#ifdef HAVE_SWOOLE
5959
#include "tdengine_swoole.h"
6060
#endif
61+
62+
#if !HAVE_TAOS_BIND
63+
# define TAOS_BIND TAOS_MULTI_BIND
64+
#endif
65+
6166
using namespace std;
6267

6368
#ifdef NO_TSTRERROR

0 commit comments

Comments
 (0)