@@ -139,7 +139,9 @@ public Schema capture() throws SQLException {
139139 Schema s = new Schema (databases , captureDefaultCharset (), this .sensitivity );
140140 try {
141141 if ( isMariaDB () && mariaSupportsJSON ()) {
142- detectMariaDBJSON (s );
142+ for (String dbName : s .getDatabaseNames ()) {
143+ detectMariaDBJSON (s , dbName );
144+ }
143145 }
144146 } catch ( InvalidSchemaError e ) {
145147 e .printStackTrace ();
@@ -315,38 +317,40 @@ public void close() throws SQLException {
315317 }
316318 }
317319
318- private void detectMariaDBJSON (Schema schema ) throws SQLException , InvalidSchemaError {
320+ private void detectMariaDBJSON (Schema schema , String dbName ) throws SQLException , InvalidSchemaError {
319321 String checkConstraintSQL = "SELECT CONSTRAINT_SCHEMA, TABLE_NAME, CONSTRAINT_NAME, CHECK_CLAUSE " +
320322 "from INFORMATION_SCHEMA.CHECK_CONSTRAINTS " +
321- "where CHECK_CLAUSE LIKE 'json_valid(%)'" ;
323+ "where CONSTRAINT_SCHEMA = ? AND CHECK_CLAUSE LIKE 'json_valid(%)'" ;
322324
323325 String regex = "json_valid\\ (`(.*)`\\ )" ;
324326 Pattern pattern = Pattern .compile (regex );
325327
326328 try (
327- PreparedStatement statement = connection .prepareStatement (checkConstraintSQL );
328- ResultSet rs = statement .executeQuery ()
329- ) {
330- while ( rs .next () ) {
331- String checkClause = rs .getString ("CHECK_CLAUSE" );
332- Matcher m = pattern .matcher (checkClause );
333- if ( m .find () ) {
334- String column = m .group (1 );
335- Database d = schema .findDatabase (rs .getString ("CONSTRAINT_SCHEMA" ));
336- if ( d == null ) continue ;
337- Table t = d .findTable (rs .getString ("TABLE_NAME" ));
338- if ( t == null ) continue ;
339- short i = t .findColumnIndex (column );
340- if ( i < 0 ) continue ;
341-
342- ColumnDef cd = t .findColumn (i );
343- if ( cd instanceof StringColumnDef ) {
344- t .replaceColumn (i , JsonColumnDef .create (cd .getName (), "json" , i ));
329+ PreparedStatement statement = connection .prepareStatement (checkConstraintSQL )) {
330+ statement .setString (1 , dbName );
331+
332+ try (
333+ ResultSet rs = statement .executeQuery ()) {
334+ while ( rs .next () ) {
335+ String checkClause = rs .getString ("CHECK_CLAUSE" );
336+ Matcher m = pattern .matcher (checkClause );
337+ if ( m .find () ) {
338+ String column = m .group (1 );
339+ Database d = schema .findDatabase (rs .getString ("CONSTRAINT_SCHEMA" ));
340+ if ( d == null ) continue ;
341+ Table t = d .findTable (rs .getString ("TABLE_NAME" ));
342+ if ( t == null ) continue ;
343+ short i = t .findColumnIndex (column );
344+ if ( i < 0 ) continue ;
345+
346+ ColumnDef cd = t .findColumn (i );
347+ if ( cd instanceof StringColumnDef ) {
348+ t .replaceColumn (i , JsonColumnDef .create (cd .getName (), "json" , i ));
349+ }
345350 }
346351 }
347352 }
348353 }
349-
350354 }
351355
352356}
0 commit comments