You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/10/10 06:32:35 UTC

[GitHub] [shardingsphere] coder616 opened a new issue, #20338: The database name cannot be properly obtained

coder616 opened a new issue, #20338:
URL: https://github.com/apache/shardingsphere/issues/20338

   ShardingSphere version 5.1.2?
   
   The database name cannot be properly obtained when using ShardingSphere-JDBC to connect to a mysql instance proxied by ShardingSphere-proxy.
   
   
   org.apache.shardingsphere.infra.metadata.database.schema.loader.dialect.MySQLSchemaMetaDataLoader:
   
   `private Map<String, Collection<ColumnMetaData>> loadColumnMetaDataMap(final DataSource dataSource, final Collection<String> tables) throws SQLException {
           Map<String, Collection<ColumnMetaData>> result = new HashMap<>();
           try (
                   Connection connection = dataSource.getConnection();
                   PreparedStatement preparedStatement = connection.prepareStatement(getTableMetaDataSQL(tables))) {
               Map<String, Integer> dataTypes = DataTypeLoaderFactory.getInstance(DatabaseTypeFactory.getInstance("MySQL")).load(connection.getMetaData());
               String databaseName = "".equals(connection.getCatalog()) ? GlobalDataSourceRegistry.getInstance().getCachedDatabaseTables().get(tables.iterator().next()) : connection.getCatalog();
               preparedStatement.setString(1, databaseName);
               try (ResultSet resultSet = preparedStatement.executeQuery()) {
                   while (resultSet.next()) {
                       String tableName = resultSet.getString("TABLE_NAME");
                       ColumnMetaData columnMetaData = loadColumnMetaData(dataTypes, resultSet);
                       if (!result.containsKey(tableName)) {
                           result.put(tableName, new LinkedList<>());
                       }
                       result.get(tableName).add(columnMetaData);
                   }
               }
           }
           return result;
       }`  
   
   connection.getCatalog() returned is not real database name.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] RaigorJiang closed issue #20338: The database name cannot be properly obtained

Posted by "RaigorJiang (via GitHub)" <gi...@apache.org>.
RaigorJiang closed issue #20338: The database name cannot be properly obtained
URL: https://github.com/apache/shardingsphere/issues/20338


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] github-actions[bot] commented on issue #20338: The database name cannot be properly obtained

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on issue #20338:
URL: https://github.com/apache/shardingsphere/issues/20338#issuecomment-1272348818

   Hello , this issue has not received a reply for several days.
   This issue is supposed to be closed.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] strongduanmu commented on issue #20338: The database name cannot be properly obtained

Posted by GitBox <gi...@apache.org>.
strongduanmu commented on issue #20338:
URL: https://github.com/apache/shardingsphere/issues/20338#issuecomment-1221660166

   Hi @coder616, ShardingSphere uses the logical database name, which can be configured in `config-xxx.xml` file.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] RaigorJiang commented on issue #20338: The database name cannot be properly obtained

Posted by "RaigorJiang (via GitHub)" <gi...@apache.org>.
RaigorJiang commented on issue #20338:
URL: https://github.com/apache/shardingsphere/issues/20338#issuecomment-1407557710

   When using ShardingSphere, the physical schema name cannot be used in the join statement.
   
   This issue has been inactive for a long time, so I'm closing it now.
   If this problem persists, please reopen it or submit a new one.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] github-actions[bot] closed issue #20338: The database name cannot be properly obtained

Posted by GitBox <gi...@apache.org>.
github-actions[bot] closed issue #20338: The database name cannot be properly obtained
URL: https://github.com/apache/shardingsphere/issues/20338


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] coder616 commented on issue #20338: The database name cannot be properly obtained

Posted by GitBox <gi...@apache.org>.
coder616 commented on issue #20338:
URL: https://github.com/apache/shardingsphere/issues/20338#issuecomment-1222358174

   I know that ShardingSphere Proxy uses the logical database name, but in practice, the logical database name is usually composed of prefix or suffix with business significance and the actual database name. So when I use the ShardingSphere - JBDC to a database table through the agent as the decryption MySQLSchemaMetaDataLoader cannot correct to get the actual metadata, leading to a join operation of the query results cannot be normal.
   
   org.apache.shardingsphere.encrypt.merge.dql.EncryptMergedResult#getValue:
   `public Object getValue(final int columnIndex, final Class<?> type) throws SQLException {
           Optional<EncryptContext> encryptContext = metaData.findEncryptContext(columnIndex);
           if (!encryptContext.isPresent() || !metaData.isQueryWithCipherColumn(encryptContext.get().getTableName(), encryptContext.get().getColumnName())) {
               return mergedResult.getValue(columnIndex, type);
           }
           Optional<EncryptAlgorithm> encryptAlgorithm = metaData.findEncryptor(encryptContext.get().getTableName(), encryptContext.get().getColumnName());
           if (!encryptAlgorithm.isPresent()) {
               return mergedResult.getValue(columnIndex, type);
           }
           Object cipherValue = mergedResult.getValue(columnIndex, Object.class);
           return null == cipherValue ? null : encryptAlgorithm.get().decrypt(cipherValue, encryptContext.get());
       }`
   
   `/**
        * Find encrypt context.
        * 
        * @param columnIndex column index
        * @return encrypt context
        */
       public Optional<EncryptContext> findEncryptContext(final int columnIndex) {
           Optional<ColumnProjection> columnProjection = findColumnProjection(columnIndex);
           if (!columnProjection.isPresent()) {
               return Optional.empty();
           }
           TablesContext tablesContext = selectStatementContext.getTablesContext();
           String schemaName = tablesContext.getSchemaName().orElseGet(() -> DatabaseTypeEngine.getDefaultSchemaName(selectStatementContext.getDatabaseType(), database.getName()));
           Map<String, String> expressionTableNames = tablesContext.findTableNamesByColumnProjection(
                   Collections.singletonList(columnProjection.get()), database.getSchema(schemaName));
           Optional<String> tableName = findTableName(columnProjection.get(), expressionTableNames);
           return tableName.map(optional -> EncryptContextBuilder.build(database.getName(), schemaName, optional, columnProjection.get().getName()));
       }`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org