Skip to content

Commit 6023f44

Browse files
committed
tMerge branch 'master' of github.com:tarantool/tarantool-php
2 parents 7f34892 + 3e20c8c commit 6023f44

File tree

3 files changed

+98
-73
lines changed

3 files changed

+98
-73
lines changed

README.md

Lines changed: 88 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -76,30 +76,70 @@ Place it into project library path in your IDE.
7676

7777
## Usage
7878

79-
1. [Class Tarantool](#class-tarantool)
80-
2. [Predefined Constants](#predefined-constants)
79+
1. [Predefined Constants](#predefined-constants)
80+
2. [Class Tarantool](#class-tarantool)
81+
* [Tarantool::_construct](#tarantool__construct)
8182
3. [Manipulation connection](#manipulation-connection)
82-
* [connect](#connect)
83-
* [disconnect, close](#disconnect-close)
84-
* [authenticate](#authenticate)
85-
* [flushSchema, flush_schema](#flushschema-flush_schema)
86-
* [ping](#ping)
83+
* [Tarantool::connect](#tarantoolconnect)
84+
* [Tarantool::disconnect](#tarantooldisconnect)
85+
* [Tarantool::authenticate](#tarantoolauthenticate)
86+
* [Tarantool::flushSchema](#tarantoolflushschema)
87+
* [Tarantool::ping](#tarantoolping)
8788
4. [Database queries](#database-queries)
88-
* [select](#select)
89-
* [insert, replace](#insert-replace)
90-
* [call](#call)
91-
* [eval, evaluate](#eval-evaluate)
92-
* [delete](#delete)
93-
* [update](#update)
94-
* [upsert](#upsert)
89+
* [Tarantool::select](tarantool#select)
90+
* [Tarantool::insert, replace](#tarantoolinsert-tarantoolreplace)
91+
* [Tarantool::call](#tarantoolcall)
92+
* [Tarantool::evaluate](#tarantoolevaluate)
93+
* [Tarantool::delete](#tarantooldelete)
94+
* [Tarantool::update](#tarantoolupdate)
95+
* [Tarantool::upsert](#tarantoolupsert)
9596

96-
### Class Tarantool
97+
### Predefined Constants
9798

98-
_**Description**_: Creates a Tarantool client
99+
_**Description**_: Available Tarantool Constants
100+
101+
* `TARANTOOL_ITER_EQ` - Equality iterator (ALL)
102+
* `TARANTOOL_ITER_REQ` - Reverse equality iterator
103+
* `TARANTOOL_ITER_ALL` - Get all rows
104+
* `TARANTOOL_ITER_LT` - Less then iterator
105+
* `TARANTOOL_ITER_LE` - Less and equal iterator
106+
* `TARANTOOL_ITER_GE` - Greater and equal iterator
107+
* `TARANTOOL_ITER_GT` - Gtreater then iterator
108+
* `TARANTOOL_ITER_BITSET_ALL_SET` - check if all given bits are set (BITSET only)
109+
* `TARANTOOL_ITER_BITSET_ANY_SET` - check if any given bits are set (BITSET only)
110+
* `TARANTOOL_ITER_BITSET_ALL_NOT_SET` - check if all given bits are not set
111+
(BITSET only)
112+
* `TARANTOOL_ITER_OVERLAPS` - find dots in the n-dimension cube (RTREE only)
113+
* `TARANTOOL_ITER_NEIGHBOR` - find nearest dots (RTREE only)
114+
115+
### Class Tarantool
99116

100117
``` php
101-
tarantool_object = new Tarantool([host = 'localhost'[, port = 3301]])
118+
Tarantool {
119+
public Tarantool::__construct ( [ string $host = 'localhost' [, int $port = 3301 ] ] )
120+
public bool Tarantool::connect ( void )
121+
public bool Tarantool::disconnect ( void )
122+
public Tarantool::authenticate(string $login [, string $password = NULL ] )
123+
public bool Tarantool::flushSchema ( void )
124+
public bool Tarantool::ping ( void )
125+
public array Tarantool::select(mixed $space [, mixed $key = array() [, mixed $index = 0 [, int $limit = PHP_INT_MAX [, int offset = 0 [, iterator = TARANTOOL_ITER_EQ ] ] ] ] ] )
126+
public array Tarantool::insert(mixed $space, array $tuple)
127+
public array Tarantool::replace(mixed $space, array $tuple)
128+
public array Tarantool::call(string $procedure [, mixed args])
129+
public array Tarantool::evaluate(string $expression [, mixed args])
130+
public array Tarantool::delete(mixed $space, mixed $key [, mixed $index])
131+
public array Tarantool::update(mixed $space, mixed $key, array $ops [, number $index] )
132+
public array Tarantool::upsert(mixed $space, mixed $key, array $ops [, number $index] )
133+
}
134+
```
135+
136+
#### Taratnool::__construct
137+
102138
```
139+
public Tarantool::__construct ( [ string $host = 'localhost' [, int $port = 3301 ] ] )
140+
```
141+
142+
_**Description**_: Creates a Tarantool client
103143

104144
_**Parameters**_
105145

@@ -110,38 +150,20 @@ _**Return Value**_
110150

111151
Tarantool class instance
112152

113-
#### *Example*
153+
##### *Example*
114154

115155
``` php
116156
$tnt = new Tarantool(); // -> new Tarantool('localhost', 3301);
117157
$tnt = new Tarantool('tarantool.org'); // -> new Tarantool('tarantool.org', 3301);
118158
$tnt = new Tarantool('localhost', 16847);
119159
```
120160

121-
### Predefined Constants
122-
123-
_**Description**_: Available Tarantool Constants
124-
125-
* `TARANTOOL_ITER_EQ` - Equality iterator (ALL)
126-
* `TARANTOOL_ITER_REQ` - Reverse equality iterator
127-
* `TARANTOOL_ITER_ALL` - Get all rows
128-
* `TARANTOOL_ITER_LT` - Less then iterator
129-
* `TARANTOOL_ITER_LE` - Less and equal iterator
130-
* `TARANTOOL_ITER_GE` - Greater and equal iterator
131-
* `TARANTOOL_ITER_GT` - Gtreater then iterator
132-
* `TARANTOOL_ITER_BITSET_ALL_SET` - check if all given bits are set (BITSET only)
133-
* `TARANTOOL_ITER_BITSET_ANY_SET` - check if any given bits are set (BITSET only)
134-
* `TARANTOOL_ITER_BITSET_ALL_NOT_SET` - check if all given bits are not set
135-
(BITSET only)
136-
* `TARANTOOL_ITER_OVERLAPS` - find dots in the n-dimension cube (RTREE only)
137-
* `TARANTOOL_ITER_NEIGHBOR` - find nearest dots (RTREE only)
138-
139161
## Manipulation connection
140162

141-
### connect
163+
### Tarantool::connect
142164

143165
``` php
144-
$tnt->connect();
166+
public bool Tarantool::connect ( void )
145167
```
146168

147169
_**Description**_: Explicit connect to Tarantool Server. If not used, then connection
@@ -152,11 +174,10 @@ _**Return Value**_
152174
**BOOL**: True on success
153175
Raises `Exception` if can't connect to Tarantool.
154176

155-
### disconnect, close
177+
### Tarantool::disconnect
156178

157179
``` php
158-
$tnt->disconnect();
159-
$tnt->close();
180+
public bool Tarantool::disconnect ( void )
160181
```
161182

162183
_**Description**_: Explicitly close connection to Tarantool Server. If you're
@@ -166,10 +187,10 @@ _**Return Value**_
166187

167188
**BOOL**: True
168189

169-
### authenticate
190+
### Tarantool::authenticate
170191

171192
``` php
172-
$tnt->connect(login, password);
193+
public Tarantool::authenticate(string $login [, string $password = NULL ] )
173194
```
174195

175196
_**Description**_: Authenticate to Tarantool using given login/password
@@ -179,7 +200,7 @@ _**Parameters**_
179200
* `login`: string - user login (mandatory)
180201
* `password`: string - user password (mandatory, but ignored, if user is guest)
181202

182-
_**Return Value**_
203+
_**Return Value**_ NULL
183204

184205
#### *Example*
185206

@@ -193,14 +214,13 @@ $tnt->connect('valdis', 'pelsh')
193214
* - user is 'guest'
194215
* - password is empty and ignored, anyway
195216
*/
196-
$tnt->connect('guest', '')
217+
$tnt->connect('guest')
197218
```
198219

199-
### flushSchema, flush_schema
220+
### Tarantool::flushSchema
200221

201222
``` php
202-
$tnt->flushSchema();
203-
$tnt->flush_schema()
223+
public bool Tarantool::flushSchema ( void )
204224
```
205225

206226
_**Description**_: Remove space/index schema from client.
@@ -209,10 +229,10 @@ _**Return Value**_
209229

210230
**BOOL**: True
211231

212-
### ping
232+
### Tarantool::ping
213233

214234
``` php
215-
$tnt->ping();
235+
public bool Tarantool::ping ( void )
216236
```
217237

218238
_**Description**_: Ping Tarantool server.
@@ -225,10 +245,10 @@ Throws `Exception` on error.
225245

226246
## Database queries
227247

228-
### select
248+
### Tarantool::select
229249

230250
``` php
231-
rv = $tnt->select(space[, key[, index[, limit[, offset[, iterator]]]]]);
251+
public array Tarantool::select(mixed $space [, mixed $key = array() [, mixed $index = 0 [, int $limit = PHP_INT_MAX [, int offset = 0 [, iterator = TARANTOOL_ITER_EQ ] ] ] ] ] )
232252
```
233253

234254
_**Description**_: Execute select query from Tarantool server.
@@ -269,11 +289,11 @@ $tnt->select("test", null, null, 100, 100);
269289
$tnt->select("test", null, null, 100, 100, TARANTOOL_ITER_REQ);
270290
```
271291

272-
### insert, replace
292+
### Tarantool::insert, Tarantool::replace
273293

274294
``` php
275-
rv = $tnt->insert(space, tuple);
276-
rv = $tnt->replace(space, tuple);
295+
public array Tarantool::insert(mixed $space, array $tuple)
296+
public array Tarantool::replace(mixed $space, array $tuple)
277297
```
278298

279299
_**Description**_: Insert (if not exists query with same PK) or Replace tuple.
@@ -301,10 +321,10 @@ $tnt->insert("test", array(1, 3, "smth completely different"));
301321
$tnt->replace("test", array(1, 3, "smth completely different"));
302322
```
303323

304-
### call
324+
### Tarantool::call
305325

306326
``` php
307-
rv = $tnt->call(procedure[, args]);
327+
public array Tarantool::call(string $procedure [, mixed args])
308328
```
309329

310330
_**Description**_: Call stored procedure
@@ -327,17 +347,17 @@ $tnt->call("test_2");
327347
$tnt->call("test_3", array(3, 4));
328348
```
329349

330-
### eval, evaluate
350+
### Tarantool::evaluate
331351

332352
``` php
333-
rv = $tnt->eval(lua_code[, args]);
353+
public array Tarantool::evaluate(string $expression [, mixed args])
334354
```
335355

336356
_**Description**_: Evaluate given lua code (demands current user to have
337357
`'execute'` rights for `'universe'` in Tarantool)
338358

339359
_**Parameters**_
340-
* `procedure`: String, Lua code to evaluate (mandatory)
360+
* `expression`: String, Lua code to evaluate (mandatory)
341361
* `args`: Any value to pass to procdure as arguments (empty by default)
342362

343363
_**Return Value**_
@@ -354,10 +374,10 @@ $tnt->eval("return test_3(...)", array(3, 4));
354374
$tnt->evaluate("return test_3(...)", array(3, 4));
355375
```
356376

357-
### delete
377+
### Tarantool::delete
358378

359379
``` php
360-
rv = $tnt->delete(space, key[, index]);
380+
public array Tarantool::delete(mixed $space, mixed $key [, mixed $index])
361381
```
362382

363383
_**Description**_: Delete record with given key.
@@ -378,14 +398,15 @@ _**Return Value**_
378398
``` php
379399
/* Following code will delete all tuples from space `test` */
380400
$tuples = $tnt->select("test");
381-
foreach($tuples as $value)$
401+
foreach($tuples as $value) {
382402
$tnt->delete("test", Array($value[0]));
403+
}
383404
```
384405

385-
### update
406+
### Tarantool::update
386407

387408
``` php
388-
rv = $tnt->update(space, key, ops[, index]);
409+
public array Tarantool::update(mixed $space, mixed $key, array $ops [, number $index] )
389410
```
390411

391412
_**Description**_: Update record with given key (update in Tarantool is
@@ -535,10 +556,10 @@ $tnt->update("test", 1, array(
535556
));
536557
```
537558

538-
### upsert
559+
### Tarantool::upsert
539560

540561
``` php
541-
rv = $tnt->update(space, tuple, ops[, index]);
562+
public array Tarantool::upsert(mixed $space, mixed $key, array $ops [, number $index] )
542563
```
543564

544565
_**Description**_: Update or Insert command (If tuple with PK == PK('tuple') exists,

src/tarantool.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ int __tarantool_connect(tarantool_object *obj, zval *id TSRMLS_DC) {
184184
return FAILURE;
185185
}
186186
if (obj->login != NULL && obj->passwd != NULL) {
187-
tarantool_schema_flush(obj->schema);
188187
status = __tarantool_authenticate(obj);
189188
}
190189
return status;
@@ -733,6 +732,7 @@ PHP_METHOD(tarantool_class, connect) {
733732
int __tarantool_authenticate(tarantool_object *obj) {
734733
TSRMLS_FETCH();
735734

735+
tarantool_schema_flush(obj->schema);
736736
tarantool_tp_update(obj->tps);
737737
int batch_count = 3;
738738
size_t passwd_len = (obj->passwd ? strlen(obj->passwd) : 0);
@@ -810,13 +810,15 @@ int __tarantool_authenticate(tarantool_object *obj) {
810810

811811
PHP_METHOD(tarantool_class, authenticate) {
812812
char *login; int login_len;
813-
char *passwd; int passwd_len;
813+
char *passwd = NULL; int passwd_len = 0;
814814

815815
TARANTOOL_PARSE_PARAMS(id, "s|s", &login, &login_len,
816816
&passwd, &passwd_len);
817817
TARANTOOL_FETCH_OBJECT(obj, id);
818818
obj->login = pestrdup(login, 1);
819-
obj->passwd = (passwd ? estrdup(passwd) : NULL);
819+
obj->passwd = NULL;
820+
if (passwd != NULL)
821+
obj->passwd = estrdup(passwd);
820822
TARANTOOL_CONNECT_ON_DEMAND(obj, id);
821823

822824
__tarantool_authenticate(obj);

test-run.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ def main():
6161
shutil.copy('test/shared/phpunit.xml', os.path.join(test_cwd, 'phpunit.xml'))
6262
shutil.copy('modules/tarantool.so', test_cwd)
6363
test_lib_path = os.path.join(test_dir_path, 'phpunit.phar')
64-
cmd = ''
6564

6665
version = read_popen_config('--version').strip(' \n\t') + '.'
6766
version1 = read_popen_config('--extension-dir').strip(' \n\t')
@@ -74,15 +73,18 @@ def main():
7473
'test/shared/tarantool-2.ini',
7574
'test/shared/tarantool-3.ini'
7675
]:
76+
cmd = ''
7777
shutil.copy(php_ini, os.path.join(test_cwd, 'tarantool.ini'))
7878
if '--flags' in sys.argv:
7979
os.environ['ZEND_DONT_UNLOAD_MODULES'] = '1'
8080
os.environ['USE_ZEND_ALLOC'] = '0'
8181
os.environ['MALLOC_CHECK_'] = '1'
8282
if '--valgrind' in sys.argv:
83-
cmd = cmd + 'valgrind --leak-check=full --log-file=php.out '
83+
cmd = cmd + 'valgrind --leak-check=full --log-file='
84+
cmd = cmd + os.path.basename(php_ini).split('.')[0] + '.out '
8485
cmd = cmd + '--suppressions=test/shared/valgrind.sup '
85-
cmd = cmd + '--keep-stacktraces=alloc-and-free --freelist-vol=2000000000 '
86+
cmd = cmd + '--keep-stacktraces=alloc-and-free'
87+
cmd = cmd + ' --freelist-vol=2000000000 '
8688
cmd = cmd + '--malloc-fill=0 --free-fill=0 '
8789
cmd = cmd + '--num-callers=50 ' + find_php_bin()
8890
cmd = cmd + ' -c tarantool.ini {0}'.format(test_lib_path)

0 commit comments

Comments
 (0)