Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated PHPUnit to version 7 + gh-24 + gh-42 + gh-85 + gh-83 + gh-71 #134

Closed
wants to merge 10 commits into from
54 changes: 54 additions & 0 deletions src/tarantool.c
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,55 @@ int convert_iterator(zval *iter, int all) {
return -1;
}

int obtain_space_by_spaceno(tarantool_connection *obj, uint32_t space_no) {
if (tarantool_schema_has_space_no(obj->schema, space_no)) {
return 0;
}

tarantool_tp_update(obj->tps);
tp_select(obj->tps, SPACE_SPACE, INDEX_SPACE_NO, 0, 4096);
tp_key(obj->tps, 1);
tp_encode_uint(obj->tps, space_no);
tp_reqid(obj->tps, TARANTOOL_G(sync_counter)++);

obj->value->len = tp_used(obj->tps);
tarantool_tp_flush(obj->tps);

if (tarantool_stream_send(obj) == FAILURE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block (here and below) was mostly copy-pasted from get_spaceno_by_name. It worth to wrap it into a function I think.

return FAILURE;

char pack_len[5] = {0, 0, 0, 0, 0};
if (tarantool_stream_read(obj, pack_len, 5) == FAILURE)
return FAILURE;
size_t body_size = php_mp_unpack_package_size(pack_len);
smart_string_ensure(obj->value, body_size);
if (tarantool_stream_read(obj, obj->value->c,
body_size) == FAILURE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Underindented.

return FAILURE;

struct tnt_response resp; memset(&resp, 0, sizeof(struct tnt_response));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: two operators on the same line.

if (php_tp_response(&resp, obj->value->c, body_size) == -1) {
tarantool_throw_parsingexception("query");
return FAILURE;
}

if (resp.error) {
tarantool_throw_clienterror(resp.code, resp.error,
resp.error_len);
return FAILURE;
}

if (tarantool_schema_add_spaces(obj->schema, resp.data, resp.data_len)) {
tarantool_throw_parsingexception("schema (space)");
return FAILURE;
}
if (!tarantool_schema_has_space_no(obj->schema, space_no)) {
THROW_EXC("No space %u defined", space_no);
return FAILURE;
}
return 0;
}

int get_spaceno_by_name(tarantool_connection *obj, zval *name) {
if (Z_TYPE_P(name) == IS_LONG)
return Z_LVAL_P(name);
Expand Down Expand Up @@ -695,6 +744,11 @@ int get_indexno_by_name(tarantool_connection *obj, int space_no,
THROW_EXC("Index ID must be String or Long");
return FAILURE;
}

if (obtain_space_by_spaceno(obj, space_no) == FAILURE) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this call should be a part of get_spaceno_by_name.

return FAILURE;
}

int32_t index_no = tarantool_schema_get_iid_by_string(obj->schema,
space_no, Z_STRVAL_P(name), Z_STRLEN_P(name));
if (index_no != FAILURE)
Expand Down
2 changes: 2 additions & 0 deletions src/tarantool_proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#define SPACE_SPACE 281
#define SPACE_INDEX 289

#define INDEX_SPACE_NO 0
#define INDEX_INDEX_NO 0
#define INDEX_SPACE_NAME 2
#define INDEX_INDEX_NAME 2

Expand Down
15 changes: 15 additions & 0 deletions src/tarantool_schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,21 @@ schema_add_space(
return -1;
}

int
tarantool_schema_has_space_no(
struct tarantool_schema *schema_obj,
uint32_t space_no) {
/* Prepare key for space search */
struct schema_key space_key;
space_key.number = space_no;
space_key.id = (void *)&(space_key.number);
space_key.id_len = sizeof(uint32_t);

struct mh_schema_space_t *schema = schema_obj->space_hash;
mh_int_t space_slot = mh_schema_space_find(schema, &space_key, NULL);
return (space_slot != mh_end(schema));
}

int
tarantool_schema_add_spaces(
struct tarantool_schema *schema_obj,
Expand Down
3 changes: 3 additions & 0 deletions src/tarantool_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ struct tarantool_schema {
struct mh_schema_space_t *space_hash;
};

int
tarantool_schema_has_space_no(struct tarantool_schema *, uint32_t);

int
tarantool_schema_add_spaces(struct tarantool_schema *, const char *, uint32_t);
int
Expand Down
8 changes: 8 additions & 0 deletions test/DMLTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -474,4 +474,12 @@ public function test_18_02_delete_loop() {
gc_collect_cycles();
gc_collect_cycles();
}

/**
* @doesNotPerformAssertions
*/
public function test_19_schema_obtain_failed() {
$empty_tarantool = new Tarantool('localhost', getenv('PRIMARY_PORT'), 'test');
$empty_tarantool->select(289, [], 'name');
}
}