10
10
'FieldInfo' , BaseFieldInfo ._fields + ('auto_increment' , ))
11
11
12
12
13
+ def schema_name (table_name ):
14
+ table_schema = 'SQLUser'
15
+ if '.' in table_name :
16
+ [table_schema , table_name ] = table_name .split ('.' )
17
+ return [table_schema , table_name , ]
18
+
19
+
13
20
class DatabaseIntrospection (BaseDatabaseIntrospection ):
14
21
data_types_reverse = {
15
22
'bigint' : 'BigIntegerField' ,
@@ -48,11 +55,12 @@ def get_sequences(self, cursor, table_name, table_fields=()):
48
55
49
56
def get_table_list (self , cursor ):
50
57
cursor .execute ("""
51
- SELECT TABLE_NAME
58
+ SELECT TABLE_SCHEMA, TABLE_NAME
52
59
FROM information_schema.tables
53
- WHERE TABLE_SCHEMA = 'SQLUser'
60
+ WHERE TABLE_TYPE = 'BASE TABLE'
61
+ AND NOT (TABLE_SCHEMA %STARTSWITH 'Ens')
54
62
""" )
55
- return [TableInfo (row [0 ], 't' ) for row in cursor .fetchall ()]
63
+ return [TableInfo (row [1 ] if row [ 0 ] == 'SQLUser' else row [ 0 ] + '.' + row [ 1 ], 't' ) for row in cursor .fetchall ()]
56
64
57
65
def get_table_description (self , cursor , table_name ):
58
66
"""
@@ -74,7 +82,7 @@ def get_table_description(self, cursor, table_name):
74
82
AND TABLE_NAME = %s
75
83
ORDER BY ORDINAL_POSITION
76
84
""" ,
77
- [ 'SQLUser' , table_name ]
85
+ schema_name ( table_name )
78
86
)
79
87
80
88
description = [
@@ -101,6 +109,7 @@ def get_relations(self, cursor, table_name):
101
109
Return a dictionary of {field_name: (field_name_other_table, other_table)}
102
110
representing all relationships to the given table.
103
111
"""
112
+
104
113
# Dictionary of relations to return
105
114
cursor .execute ("""
106
115
SELECT column_name, referenced_column_name, referenced_table_name
@@ -109,7 +118,7 @@ def get_relations(self, cursor, table_name):
109
118
AND table_name = %s
110
119
AND referenced_table_name IS NOT NULL
111
120
AND referenced_column_name IS NOT NULL
112
- """ , [ 'SQLUser' , table_name ] )
121
+ """ , schema_name ( table_name ) )
113
122
return {
114
123
field_name : (other_field , other_table )
115
124
for field_name , other_field , other_table in cursor .fetchall ()
@@ -151,13 +160,13 @@ def get_constraints(self, cursor, table_name):
151
160
information_schema.table_constraints AS c
152
161
WHERE
153
162
kc.table_schema = %s AND
163
+ kc.table_name = %s AND
154
164
c.table_schema = kc.table_schema AND
155
165
c.constraint_name = kc.constraint_name AND
156
- c.constraint_type != 'CHECK' AND
157
- kc.table_name = %s
166
+ c.constraint_type != 'CHECK'
158
167
ORDER BY kc.ordinal_position
159
168
"""
160
- cursor .execute (name_query , [ 'SQLUser' , table_name ] )
169
+ cursor .execute (name_query , schema_name ( table_name ) )
161
170
for constraint , column , ref_table , ref_column , kind in cursor .fetchall ():
162
171
if constraint not in constraints :
163
172
constraints [constraint ] = {
@@ -188,7 +197,7 @@ def get_constraints(self, cursor, table_name):
188
197
tc.constraint_type = 'CHECK' AND
189
198
tc.table_name = %s
190
199
"""
191
- cursor .execute (type_query , [ 'SQLUser' , table_name ] )
200
+ cursor .execute (type_query , schema_name ( table_name ) )
192
201
for constraint , check_clause in cursor .fetchall ():
193
202
constraint_columns = self ._parse_constraint_columns (
194
203
check_clause , columns )
@@ -219,7 +228,7 @@ def get_constraints(self, cursor, table_name):
219
228
AND TABLE_NAME = %s
220
229
ORDER BY ORDINAL_POSITION
221
230
"""
222
- cursor .execute (index_query , [ 'SQLUser' , table_name ] )
231
+ cursor .execute (index_query , schema_name ( table_name ) )
223
232
for index , column , primary , non_unique , order in cursor .fetchall ():
224
233
if index not in constraints :
225
234
constraints [index ] = {
0 commit comments