7
7
8
8
import six
9
9
10
- from tarantool .error import SchemaError
10
+ from tarantool .error import SchemaError , DatabaseError
11
11
import tarantool .const as const
12
12
13
13
14
14
class 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 ]
18
18
if isinstance (self .name , bytes ):
19
19
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 ]
22
22
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
25
30
self .space = space
26
31
self .space .indexes [self .iid ] = self
27
32
if self .name :
@@ -34,10 +39,10 @@ def flush(self):
34
39
35
40
36
41
class 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 ]
41
46
if isinstance (self .name , bytes ):
42
47
self .name = self .name .decode ()
43
48
self .indexes = {}
@@ -66,15 +71,22 @@ def get_space(self, space):
66
71
if isinstance (space , six .string_types )
67
72
else const .INDEX_SPACE_PRIMARY )
68
73
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 ]):
73
85
temp_name = ('name' if isinstance (space , six .string_types ) else 'id' )
74
86
raise SchemaError (
75
87
"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 )
78
90
79
91
def get_index (self , space , index ):
80
92
_space = self .get_space (space )
@@ -86,17 +98,26 @@ def get_index(self, space, index):
86
98
if isinstance (index , six .string_types )
87
99
else const .INDEX_INDEX_PRIMARY )
88
100
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 ],
90
104
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 ]):
94
115
temp_name = ('name' if isinstance (index , six .string_types ) else 'id' )
95
116
raise SchemaError (
96
117
"There's no index with {2} '{0}' in space '{1}'" .format (
97
118
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 )
100
121
101
122
def flush (self ):
102
123
self .schema .clear ()
0 commit comments