Skip to content

Commit 197358f

Browse files
committed
Add ability to give null to select in limit. closes gh-58
1 parent 78d1285 commit 197358f

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/tarantool.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -913,13 +913,22 @@ PHP_METHOD(tarantool_class, ping) {
913913
PHP_METHOD(tarantool_class, select) {
914914
zval *space = NULL, *index = NULL;
915915
zval *key = NULL, *key_new = NULL;
916+
zval *zlimit = NULL;
916917
long limit = LONG_MAX-1, offset = 0, iterator = 0;
917918

918-
TARANTOOL_PARSE_PARAMS(id, "z|zzlll", &space, &key,
919-
&index, &limit, &offset, &iterator);
919+
TARANTOOL_PARSE_PARAMS(id, "z|zzzll", &space, &key,
920+
&index, &zlimit, &offset, &iterator);
920921
TARANTOOL_FETCH_OBJECT(obj, id);
921922
TARANTOOL_CONNECT_ON_DEMAND(obj, id);
922923

924+
if (zlimit != NULL && Z_TYPE_P(zlimit) != IS_NULL && Z_TYPE_P(zlimit) != IS_LONG) {
925+
THROW_EXC("wrong type of 'limit' - expected long/null, got '%s'",
926+
zend_zval_type_name(zlimit));
927+
RETURN_FALSE;
928+
} else if (zlimit != NULL && Z_TYPE_P(zlimit) == IS_LONG) {
929+
limit = Z_LVAL_P(zlimit);
930+
}
931+
923932
long space_no = get_spaceno_by_name(obj, id, space TSRMLS_CC);
924933
if (space_no == FAILURE) RETURN_FALSE;
925934
int32_t index_no = 0;

test/DMLTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,14 @@ public function test_13_eval() {
259259
$this->assertEquals(self::$tarantool->eval("return test_3(...)", array(3, 4)), array('0' => 7));
260260
$this->assertEquals(self::$tarantool->evaluate("return test_3(...)", array(3, 4)), array('0' => 7));
261261
}
262+
263+
public function test_14_select_limit_defaults() {
264+
self::$tarantool->insert("test", array(1, 2, "hello"));
265+
self::$tarantool->insert("test", array(2, 3, "hello"));
266+
self::$tarantool->insert("test", array(3, 4, "hello"));
267+
self::$tarantool->insert("test", array(4, 2, "hello"));
268+
$this->assertEquals(count(self::$tarantool->select("test", 3, "secondary", null, null, TARANTOOL_ITER_GT)), 1);
269+
$this->assertEquals(count(self::$tarantool->select("test", 3, "secondary", 0, null, TARANTOOL_ITER_GT)), 0);
270+
$this->assertEquals(count(self::$tarantool->select("test", 3, "secondary", 100, null, TARANTOOL_ITER_GT)), 1);
271+
}
262272
}

0 commit comments

Comments
 (0)