77
88import six
99
10- from tarantool .error import SchemaError
10+ from tarantool .error import SchemaError , DatabaseError
1111import tarantool .const as const
1212
1313
1414class SchemaIndex (object ):
15- def __init__ (self , array , space ):
16- self .iid = array [1 ]
17- self .name = array [2 ]
15+ def __init__ (self , index_row , space ):
16+ self .iid = index_row [1 ]
17+ self .name = index_row [2 ]
1818 if isinstance (self .name , bytes ):
1919 self .name = self .name .decode ()
20- self .index = array [3 ]
21- self .unique = array [4 ]
20+ self .index = index_row [3 ]
21+ self .unique = index_row [4 ]
2222 self .parts = []
23- for i in range (array [5 ]):
24- self .parts .append ((array [5 + 1 + i * 2 ], array [5 + 2 + i * 2 ]))
23+ if isinstance (index_row [5 ], (list , tuple )):
24+ for k , v in index_row [5 ]:
25+ self .parts .append (k , v )
26+ else :
27+ for i in range (index_row [5 ]):
28+ self .parts .append ((index_row [5 + 1 + i * 2 ], index_row [5 + 2 + i * 2 ]))
29+ sel
2530 self .space = space
2631 self .space .indexes [self .iid ] = self
2732 if self .name :
@@ -34,10 +39,10 @@ def flush(self):
3439
3540
3641class SchemaSpace (object ):
37- def __init__ (self , array , schema ):
38- self .sid = array [0 ]
39- self .arity = array [1 ]
40- self .name = array [2 ]
42+ def __init__ (self , space_row , schema ):
43+ self .sid = space_row [0 ]
44+ self .arity = space_row [1 ]
45+ self .name = space_row [2 ]
4146 if isinstance (self .name , bytes ):
4247 self .name = self .name .decode ()
4348 self .indexes = {}
@@ -66,15 +71,22 @@ def get_space(self, space):
6671 if isinstance (space , six .string_types )
6772 else const .INDEX_SPACE_PRIMARY )
6873
69- array = self .con .select (const .SPACE_SPACE , space , index = _index )
70- if len (array ) > 1 :
71- raise SchemaError ('Some strange output from server: \n ' + array )
72- elif len (array ) == 0 or not len (array [0 ]):
74+ space_row = None
75+ try :
76+ space_row = self .con .select (const .SPACE_VSPACE , space , index = _index )
77+ except DatabaseError as e :
78+ if e .args [0 ] != 36 :
79+ raise
80+ if space_row is None :
81+ space_row = self .con .select (const .SPACE_SPACE , space , index = _index )
82+ if len (space_row ) > 1 :
83+ raise SchemaError ('Some strange output from server: \n ' + space_row )
84+ elif len (space_row ) == 0 or not len (space_row [0 ]):
7385 temp_name = ('name' if isinstance (space , six .string_types ) else 'id' )
7486 raise SchemaError (
7587 "There's no space with {1} '{0}'" .format (space , temp_name ))
76- array = array [0 ]
77- return SchemaSpace (array , self .schema )
88+ space_row = space_row [0 ]
89+ return SchemaSpace (space_row , self .schema )
7890
7991 def get_index (self , space , index ):
8092 _space = self .get_space (space )
@@ -86,17 +98,26 @@ def get_index(self, space, index):
8698 if isinstance (index , six .string_types )
8799 else const .INDEX_INDEX_PRIMARY )
88100
89- array = self .con .select (const .SPACE_INDEX , [_space .sid , index ],
101+ index_row = None
102+ try :
103+ index_row = self .con .select (const .SPACE_VSPACE , [_space .sid , index ],
90104 index = _index )
91- if len (array ) > 1 :
92- raise SchemaError ('Some strange output from server: \n ' + array )
93- elif len (array ) == 0 or not len (array [0 ]):
105+ except DatabaseError as e :
106+ if e .args [0 ] != 36 :
107+ raise
108+ if index_row is None :
109+ index_row = self .con .select (const .SPACE_SPACE , [_space .sid , index ],
110+ index = _index )
111+
112+ if len (index_row ) > 1 :
113+ raise SchemaError ('Some strange output from server: \n ' + index_row )
114+ elif len (index_row ) == 0 or not len (index_row [0 ]):
94115 temp_name = ('name' if isinstance (index , six .string_types ) else 'id' )
95116 raise SchemaError (
96117 "There's no index with {2} '{0}' in space '{1}'" .format (
97118 index , _space .name , temp_name ))
98- array = array [0 ]
99- return SchemaIndex (array , _space )
119+ index_row = index_row [0 ]
120+ return SchemaIndex (index_row , _space )
100121
101122 def flush (self ):
102123 self .schema .clear ()
0 commit comments