@@ -61,16 +61,36 @@ WHERE 1 = 1
61
61
${
62
62
p => p . search
63
63
? `AND (
64
- LOWER(T.name || '.' || C.name ) LIKE '%${ p . search . toLowerCase ( ) } %'
65
- OR LOWER(C.name ) LIKE '%${ p . search . toLowerCase ( ) } %'
64
+ LOWER(TABLE_NAME || '.' || COLUMN_NAME ) LIKE '%${ p . search . toLowerCase ( ) } %'
65
+ OR LOWER(COLUMN_NAME ) LIKE '%${ p . search . toLowerCase ( ) } %'
66
66
)`
67
67
: ''
68
68
}
69
+ ${
70
+ p => p . tables ? 'AND (' +
71
+ p . tables . map ( t => `TABLE_NAME = '${ t . label } ' and TABLE_SCHEMA = '${ t . database } '` ) . join ( ' OR ' )
72
+ + ")" : ''
73
+ }
69
74
ORDER BY
70
75
TABLE_NAME,
71
76
ORDINAL_POSITION
72
77
` ;
73
78
79
+ const treeFunctionFilter = function ( p : { [ key : string ] : any } ) : string {
80
+ if ( p . schema || p . search ) {
81
+ let filter = ", '" ;
82
+ if ( p . schema ) {
83
+ filter += p . schema + "." ;
84
+ }
85
+ if ( p . search ) {
86
+ filter += p . search ;
87
+ }
88
+ filter += "*'" ;
89
+ return filter ;
90
+ }
91
+ return "" ;
92
+ }
93
+
74
94
const fetchRecords : IQueries [ 'fetchRecords' ] = queryFactory `
75
95
SELECT TOP ${ p => p . limit || 50 } *
76
96
FROM ${ p => p . table . schema } .${ p => ( p . table . label || p . table ) }
@@ -100,7 +120,7 @@ SELECT
100
120
'0:' || SCHEMA_NAME AS sortText
101
121
`
102
122
}
103
- FROM ${ Functions [ type ] } (${ p => p . showSystem ? 1 : 0 } ${ p => p . search ? `, '* ${ p . search } *'` : p . schema ? `, ' ${ p . schema } .*'` : '' } )
123
+ FROM ${ Functions [ type ] } (${ p => p . showSystem ? 1 : 0 } ${ p => treeFunctionFilter ( p ) } )
104
124
ORDER BY
105
125
${ p => p . schema || p . search && p . search . includes ( '.' ) ? ValueColumn [ type ] : 'SCHEMA_NAME' }
106
126
` ;
@@ -127,15 +147,15 @@ SELECT
127
147
'0:' || SCHEMA_NAME AS sortText
128
148
`
129
149
}
130
- FROM ${ Functions [ type ] } (${ p . showSystem ? 1 : 0 } ${ p . search ? `, ' ${ p . search } *'` : p . schema ? `, ' ${ p . schema } .*'` : '' } )
150
+ FROM ${ Functions [ type ] } (${ p . showSystem ? 1 : 0 } ${ treeFunctionFilter ( p ) } )
131
151
` ;
132
152
133
153
const searchTables : IQueries [ 'searchTables' ] = queryFactory `
134
154
${ p => searchHelper ( p , ContextValue . TABLE ) }
135
155
ORDER BY sortText
136
156
` ;
137
157
138
- const searchEverything : IQueries [ 'searchTables ' ] = queryFactory `
158
+ const searchEverything : IQueries [ 'searchEverything ' ] = queryFactory `
139
159
${ p => searchHelper ( p , ContextValue . TABLE ) }
140
160
UNION
141
161
${ p => searchHelper ( p , ContextValue . VIEW ) }
0 commit comments