@@ -630,21 +630,30 @@ int convert_iterator(zval *iter, int all) {
630
630
}
631
631
632
632
int get_spaceno_by_name (tarantool_connection * obj , zval * name ) {
633
- if (Z_TYPE_P (name ) == IS_LONG )
634
- return Z_LVAL_P (name );
635
- if (Z_TYPE_P (name ) != IS_STRING ) {
633
+ if (Z_TYPE_P (name ) != IS_STRING && Z_TYPE_P (name ) != IS_LONG ) {
636
634
tarantool_throw_exception ("Space ID must be String or Long" );
637
635
return FAILURE ;
638
636
}
639
- int32_t space_no = tarantool_schema_get_sid_by_string (obj -> schema ,
640
- Z_STRVAL_P (name ), Z_STRLEN_P (name ));
641
- if (space_no != FAILURE )
642
- return space_no ;
643
-
637
+ int32_t space_no = -1 ;
644
638
tarantool_tp_update (obj -> tps );
645
- tp_select (obj -> tps , SPACE_SPACE , INDEX_SPACE_NAME , 0 , 4096 );
646
- tp_key (obj -> tps , 1 );
647
- tp_encode_str (obj -> tps , Z_STRVAL_P (name ), Z_STRLEN_P (name ));
639
+ if (Z_TYPE_P (name ) == IS_LONG ) {
640
+ space_no = tarantool_schema_get_sid_by_number (obj -> schema ,
641
+ Z_LVAL_P (name ));
642
+ if (space_no != FAILURE )
643
+ return space_no ;
644
+ tp_select (obj -> tps , SPACE_SPACE , INDEX_SPACE_NO , 0 , 4096 );
645
+ tp_key (obj -> tps , 1 );
646
+ tp_encode_uint (obj -> tps , Z_LVAL_P (name ));
647
+ } else {
648
+ space_no = tarantool_schema_get_sid_by_string (obj -> schema ,
649
+ Z_STRVAL_P (name ),
650
+ Z_STRLEN_P (name ));
651
+ if (space_no != FAILURE )
652
+ return space_no ;
653
+ tp_select (obj -> tps , SPACE_SPACE , INDEX_SPACE_NAME , 0 , 4096 );
654
+ tp_key (obj -> tps , 1 );
655
+ tp_encode_str (obj -> tps , Z_STRVAL_P (name ), Z_STRLEN_P (name ));
656
+ }
648
657
tp_reqid (obj -> tps , TARANTOOL_G (sync_counter )++ );
649
658
650
659
obj -> value -> len = tp_used (obj -> tps );
@@ -659,10 +668,11 @@ int get_spaceno_by_name(tarantool_connection *obj, zval *name) {
659
668
size_t body_size = php_mp_unpack_package_size (pack_len );
660
669
smart_string_ensure (obj -> value , body_size );
661
670
if (tarantool_stream_read (obj , obj -> value -> c ,
662
- body_size ) == FAILURE )
671
+ body_size ) == FAILURE )
663
672
return FAILURE ;
664
673
665
- struct tnt_response resp ; memset (& resp , 0 , sizeof (struct tnt_response ));
674
+ struct tnt_response resp ;
675
+ memset (& resp , 0 , sizeof (struct tnt_response ));
666
676
if (php_tp_response (& resp , obj -> value -> c , body_size ) == -1 ) {
667
677
tarantool_throw_parsingexception ("query" );
668
678
return FAILURE ;
@@ -678,10 +688,22 @@ int get_spaceno_by_name(tarantool_connection *obj, zval *name) {
678
688
tarantool_throw_parsingexception ("schema (space)" );
679
689
return FAILURE ;
680
690
}
681
- space_no = tarantool_schema_get_sid_by_string (obj -> schema ,
682
- Z_STRVAL_P (name ), Z_STRLEN_P (name ));
683
- if (space_no == FAILURE )
684
- THROW_EXC ("No space '%s' defined" , Z_STRVAL_P (name ));
691
+
692
+ if (Z_TYPE_P (name ) == IS_LONG ) {
693
+ space_no = tarantool_schema_get_sid_by_number (obj -> schema ,
694
+ Z_LVAL_P (name ));
695
+ if (space_no == FAILURE ) {
696
+ THROW_EXC ("No space '%s' defined" , Z_STRVAL_P (name ));
697
+ }
698
+ } else {
699
+ space_no = tarantool_schema_get_sid_by_string (obj -> schema ,
700
+ Z_STRVAL_P (name ),
701
+ Z_STRLEN_P (name ));
702
+ if (space_no == FAILURE ) {
703
+ THROW_EXC ("No space '%ul' defined" , Z_LVAL_P (name ));
704
+ }
705
+ }
706
+
685
707
return space_no ;
686
708
}
687
709
@@ -695,6 +717,7 @@ int get_indexno_by_name(tarantool_connection *obj, int space_no,
695
717
THROW_EXC ("Index ID must be String or Long" );
696
718
return FAILURE ;
697
719
}
720
+
698
721
int32_t index_no = tarantool_schema_get_iid_by_string (obj -> schema ,
699
722
space_no , Z_STRVAL_P (name ), Z_STRLEN_P (name ));
700
723
if (index_no != FAILURE )
@@ -721,7 +744,8 @@ int get_indexno_by_name(tarantool_connection *obj, int space_no,
721
744
if (tarantool_stream_read (obj , obj -> value -> c , body_size ) == FAILURE )
722
745
return FAILURE ;
723
746
724
- struct tnt_response resp ; memset (& resp , 0 , sizeof (struct tnt_response ));
747
+ struct tnt_response resp ;
748
+ memset (& resp , 0 , sizeof (struct tnt_response ));
725
749
if (php_tp_response (& resp , obj -> value -> c , body_size ) == -1 ) {
726
750
tarantool_throw_parsingexception ("query" );
727
751
return FAILURE ;
@@ -776,7 +800,8 @@ int get_fieldno_by_name(tarantool_connection *obj, uint32_t space_no,
776
800
if (tarantool_stream_read (obj , obj -> value -> c , body_size ) == FAILURE )
777
801
return FAILURE ;
778
802
779
- struct tnt_response resp ; memset (& resp , 0 , sizeof (struct tnt_response ));
803
+ struct tnt_response resp ;
804
+ memset (& resp , 0 , sizeof (struct tnt_response ));
780
805
if (php_tp_response (& resp , obj -> value -> c , body_size ) == -1 ) {
781
806
tarantool_throw_parsingexception ("query" );
782
807
return FAILURE ;
0 commit comments