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