Skip to content

Commit e50e288

Browse files
committed
Selecting by space_no/index_name shouldn't throw error now
closes tarantoolgh-42
1 parent e93c8ed commit e50e288

File tree

5 files changed

+82
-0
lines changed

5 files changed

+82
-0
lines changed

src/tarantool.c

+54
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,55 @@ int convert_iterator(zval *iter, int all) {
629629
return -1;
630630
}
631631

632+
int obtain_space_by_spaceno(tarantool_connection *obj, uint32_t space_no) {
633+
if (tarantool_schema_has_space_no(obj->schema, space_no)) {
634+
return 0;
635+
}
636+
637+
tarantool_tp_update(obj->tps);
638+
tp_select(obj->tps, SPACE_SPACE, INDEX_SPACE_NO, 0, 4096);
639+
tp_key(obj->tps, 1);
640+
tp_encode_uint(obj->tps, space_no);
641+
tp_reqid(obj->tps, TARANTOOL_G(sync_counter)++);
642+
643+
obj->value->len = tp_used(obj->tps);
644+
tarantool_tp_flush(obj->tps);
645+
646+
if (tarantool_stream_send(obj) == FAILURE)
647+
return FAILURE;
648+
649+
char pack_len[5] = {0, 0, 0, 0, 0};
650+
if (tarantool_stream_read(obj, pack_len, 5) == FAILURE)
651+
return FAILURE;
652+
size_t body_size = php_mp_unpack_package_size(pack_len);
653+
smart_string_ensure(obj->value, body_size);
654+
if (tarantool_stream_read(obj, obj->value->c,
655+
body_size) == FAILURE)
656+
return FAILURE;
657+
658+
struct tnt_response resp; memset(&resp, 0, sizeof(struct tnt_response));
659+
if (php_tp_response(&resp, obj->value->c, body_size) == -1) {
660+
tarantool_throw_parsingexception("query");
661+
return FAILURE;
662+
}
663+
664+
if (resp.error) {
665+
tarantool_throw_clienterror(resp.code, resp.error,
666+
resp.error_len);
667+
return FAILURE;
668+
}
669+
670+
if (tarantool_schema_add_spaces(obj->schema, resp.data, resp.data_len)) {
671+
tarantool_throw_parsingexception("schema (space)");
672+
return FAILURE;
673+
}
674+
if (!tarantool_schema_has_space_no(obj->schema, space_no)) {
675+
THROW_EXC("No space %u defined", space_no);
676+
return FAILURE;
677+
}
678+
return 0;
679+
}
680+
632681
int get_spaceno_by_name(tarantool_connection *obj, zval *name) {
633682
if (Z_TYPE_P(name) == IS_LONG)
634683
return Z_LVAL_P(name);
@@ -695,6 +744,11 @@ int get_indexno_by_name(tarantool_connection *obj, int space_no,
695744
THROW_EXC("Index ID must be String or Long");
696745
return FAILURE;
697746
}
747+
748+
if (obtain_space_by_spaceno(obj, space_no) == FAILURE) {
749+
return FAILURE;
750+
}
751+
698752
int32_t index_no = tarantool_schema_get_iid_by_string(obj->schema,
699753
space_no, Z_STRVAL_P(name), Z_STRLEN_P(name));
700754
if (index_no != FAILURE)

src/tarantool_proto.h

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#define SPACE_SPACE 281
1313
#define SPACE_INDEX 289
1414

15+
#define INDEX_SPACE_NO 0
16+
#define INDEX_INDEX_NO 0
1517
#define INDEX_SPACE_NAME 2
1618
#define INDEX_INDEX_NAME 2
1719

src/tarantool_schema.c

+15
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,21 @@ schema_add_space(
399399
return -1;
400400
}
401401

402+
int
403+
tarantool_schema_has_space_no(
404+
struct tarantool_schema *schema_obj,
405+
uint32_t space_no) {
406+
/* Prepare key for space search */
407+
struct schema_key space_key;
408+
space_key.number = space_no;
409+
space_key.id = (void *)&(space_key.number);
410+
space_key.id_len = sizeof(uint32_t);
411+
412+
struct mh_schema_space_t *schema = schema_obj->space_hash;
413+
mh_int_t space_slot = mh_schema_space_find(schema, &space_key, NULL);
414+
return (space_slot != mh_end(schema));
415+
}
416+
402417
int
403418
tarantool_schema_add_spaces(
404419
struct tarantool_schema *schema_obj,

src/tarantool_schema.h

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ struct tarantool_schema {
4949
struct mh_schema_space_t *space_hash;
5050
};
5151

52+
int
53+
tarantool_schema_has_space_no(struct tarantool_schema *, uint32_t);
54+
5255
int
5356
tarantool_schema_add_spaces(struct tarantool_schema *, const char *, uint32_t);
5457
int

test/DMLTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -474,4 +474,12 @@ public function test_18_02_delete_loop() {
474474
gc_collect_cycles();
475475
gc_collect_cycles();
476476
}
477+
478+
/**
479+
* @doesNotPerformAssertions
480+
*/
481+
public function test_19_schema_obtain_failed() {
482+
$empty_tarantool = new Tarantool('localhost', getenv('PRIMARY_PORT'), 'test');
483+
$empty_tarantool->select(289, [], 'name');
484+
}
477485
}

0 commit comments

Comments
 (0)