@@ -61,16 +61,36 @@ WHERE 1 = 1
6161${
6262 p => p . search
6363 ? `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 ( ) } %'
6666 )`
6767 : ''
6868 }
69+ ${
70+ p => p . tables ? 'AND (' +
71+ p . tables . map ( t => `TABLE_NAME = '${ t . label } ' and TABLE_SCHEMA = '${ t . database } '` ) . join ( ' OR ' )
72+ + ")" : ''
73+ }
6974ORDER BY
7075 TABLE_NAME,
7176 ORDINAL_POSITION
7277` ;
7378
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+
7494const fetchRecords : IQueries [ 'fetchRecords' ] = queryFactory `
7595SELECT TOP ${ p => p . limit || 50 } *
7696FROM ${ p => p . table . schema } .${ p => ( p . table . label || p . table ) }
@@ -100,7 +120,7 @@ SELECT
100120 '0:' || SCHEMA_NAME AS sortText
101121 `
102122 }
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 ) } )
104124ORDER BY
105125${ p => p . schema || p . search && p . search . includes ( '.' ) ? ValueColumn [ type ] : 'SCHEMA_NAME' }
106126` ;
@@ -127,15 +147,15 @@ SELECT
127147 '0:' || SCHEMA_NAME AS sortText
128148 `
129149 }
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 ) } )
131151` ;
132152
133153const searchTables : IQueries [ 'searchTables' ] = queryFactory `
134154${ p => searchHelper ( p , ContextValue . TABLE ) }
135155ORDER BY sortText
136156` ;
137157
138- const searchEverything : IQueries [ 'searchTables ' ] = queryFactory `
158+ const searchEverything : IQueries [ 'searchEverything ' ] = queryFactory `
139159${ p => searchHelper ( p , ContextValue . TABLE ) }
140160UNION
141161${ p => searchHelper ( p , ContextValue . VIEW ) }
0 commit comments