@Override public String getIdentifierQuoteString() throws SQLException { return metaData.getIdentifierQuoteString(); }
/** * Determine the String that should be used to quote identifiers. * @param conn Active connection * @return quotes * @throws SQLException */ protected String getIdentifierQuoteString(Connection conn) throws SQLException { if (identifierQuoteString == null) { identifierQuoteString = conn.getMetaData().getIdentifierQuoteString(); } return identifierQuoteString; }
@Signature public String identifier(String value) throws SQLException { String identifierQuoteString = connection.getMetaData().getIdentifierQuoteString(); return identifierQuoteString + value + identifierQuoteString; }
public static TableSchema from(final Connection conn, final String catalog, final String schema, final String tableName, final boolean translateColumnNames, final boolean includePrimaryKeys) throws SQLException { final DatabaseMetaData dmd = conn.getMetaData(); try (final ResultSet colrs = dmd.getColumns(catalog, schema, tableName, "%")) { final List<ColumnDescription> cols = new ArrayList<>(); while (colrs.next()) { final ColumnDescription col = ColumnDescription.from(colrs); cols.add(col); } final Set<String> primaryKeyColumns = new HashSet<>(); if (includePrimaryKeys) { try (final ResultSet pkrs = conn.getMetaData().getPrimaryKeys(catalog, null, tableName)) { while (pkrs.next()) { final String colName = pkrs.getString("COLUMN_NAME"); primaryKeyColumns.add(normalizeColumnName(colName, translateColumnNames)); } } } return new TableSchema(cols, translateColumnNames, primaryKeyColumns, dmd.getIdentifierQuoteString()); } } }
public static TableSchema from(final Connection conn, final String catalog, final String schema, final String tableName, final boolean translateColumnNames, final boolean includePrimaryKeys) throws SQLException { final DatabaseMetaData dmd = conn.getMetaData(); try (final ResultSet colrs = dmd.getColumns(catalog, schema, tableName, "%")) { final List<ColumnDescription> cols = new ArrayList<>(); while (colrs.next()) { final ColumnDescription col = ColumnDescription.from(colrs); cols.add(col); } final Set<String> primaryKeyColumns = new HashSet<>(); if (includePrimaryKeys) { try (final ResultSet pkrs = dmd.getPrimaryKeys(catalog, null, tableName)) { while (pkrs.next()) { final String colName = pkrs.getString("COLUMN_NAME"); primaryKeyColumns.add(normalizeColumnName(colName, translateColumnNames)); } } } return new TableSchema(cols, translateColumnNames, primaryKeyColumns, dmd.getIdentifierQuoteString()); } } }
maxRowsSupported = true; fetchSizeSupported = true; identifierQuoteString = metaData.getIdentifierQuoteString();
@Test public void returnsQuotedTableNameWhenMetaDataHasQuoteId() throws Exception { setupPrimaryKeysMetaData(); when(primaryKeysResultSet.next()).thenReturn(true).thenReturn(false); when(tablesResultSet.next()).thenReturn(true).thenReturn(true).thenReturn(false); when(tablesResultSet.getString("TABLE_NAME")).thenReturn(TABLE_NAME.toUpperCase()) .thenReturn(TABLE_NAME); String QUOTE = "@@"; when(this.databaseMetaData.getIdentifierQuoteString()).thenReturn(QUOTE); TableMetaDataView data = tableMetaDataManager.getTableMetaDataView(connection, regionMapping); assertThat(data.getQuotedTablePath()).isEqualTo(QUOTE + TABLE_NAME + QUOTE); }
@Test public void returnsQuoteStringFromMetaData() throws Exception { setupPrimaryKeysMetaData(); when(primaryKeysResultSet.next()).thenReturn(true).thenReturn(false); String expectedQuoteString = "123"; when(databaseMetaData.getIdentifierQuoteString()).thenReturn(expectedQuoteString); TableMetaDataView data = tableMetaDataManager.getTableMetaDataView(connection, regionMapping); assertThat(data.getIdentifierQuoteString()).isEqualTo(expectedQuoteString); verify(connection).getMetaData(); }
@Test public void testGetIdentifierQuoteString() throws SQLException { // If connection string hasn't "quoting_identifiers" property, this method will return current system // "planner.parser.quoting_identifiers" option (back tick by default) assertThat(dbmd.getIdentifierQuoteString(), equalTo(Quoting.BACK_TICK.string)); }
@Test public void testQuotingIdentifiersProperty() throws Exception { Connection connection = connect("jdbc:drill:zk=local;quoting_identifiers='\"'"); DatabaseMetaData dbmd = connection.getMetaData(); assertThat(dbmd.getIdentifierQuoteString(), equalTo(Quoting.DOUBLE_QUOTE.string)); reset(); connection = connect("jdbc:drill:zk=local;quoting_identifiers=["); dbmd = connection.getMetaData(); assertThat(dbmd.getIdentifierQuoteString(), equalTo(Quoting.BRACKET.string)); }
private QueryBuilder createQueryBuilder() { if (queryOptions == null) { try (Connection connection = getConnection()) { String quoteIdentifier = connection.getMetaData().getIdentifierQuoteString(); queryOptions = new QueryBuilder.Options(quoteIdentifier, true, configuration.getTableTransformer(), configuration.getColumnTransformer(), configuration.getQuoteTableNames(), configuration.getQuoteColumnNames()); } catch (SQLException e) { throw new PersistenceException(e); } } return new QueryBuilder(queryOptions); }
private TableMetaDataView computeTableMetaDataView(Connection connection, String tableName, RegionMapping regionMapping) { try { DatabaseMetaData metaData = connection.getMetaData(); String realCatalogName = getCatalogNameFromMetaData(metaData, regionMapping); String realSchemaName = getSchemaNameFromMetaData(metaData, regionMapping, realCatalogName); String realTableName = getTableNameFromMetaData(metaData, realCatalogName, realSchemaName, tableName); List<String> keys = getPrimaryKeyColumnNamesFromMetaData(metaData, realCatalogName, realSchemaName, realTableName, regionMapping.getIds()); String quoteString = metaData.getIdentifierQuoteString(); Map<String, Integer> dataTypes = getDataTypesFromMetaData(metaData, realCatalogName, realSchemaName, realTableName); return new TableMetaData(realCatalogName, realSchemaName, realTableName, keys, quoteString, dataTypes); } catch (SQLException e) { throw JdbcConnectorException.createException(e); } }
protected void checkConnectionMetadata() { synchronized (configuration) { // only done once metadata assumed to be the same for every connection if (!metadataChecked) { try (Connection connection = context.getConnection()) { DatabaseMetaData metadata = connection.getMetaData(); if (!metadata.supportsTransactions()) { transactionMode = TransactionMode.NONE; } supportsBatchUpdates = metadata.supportsBatchUpdates(); String quoteIdentifier = metadata.getIdentifierQuoteString(); queryOptions = new QueryBuilder.Options(quoteIdentifier, true, configuration.getTableTransformer(), configuration.getColumnTransformer(), configuration.getQuoteTableNames(), configuration.getQuoteColumnNames()); metadataChecked = true; } catch (SQLException e) { throw new PersistenceException(e); } } } }
@Override public String getIdentifierQuoteString() throws SQLException { return metaData.getIdentifierQuoteString(); }
java.sql.DatabaseMetaData md = conn.getMetaData(); String q = md.getIdentifierQuoteString(); String sql = "SELECT MAX(AGE) FROM %s%s%s"; sql = String.format(sql, q, tablename.replaceAll(q, q+q), q);
String quote = metaData.getIdentifierQuoteString();
protected String deduceIdentifierQuoteString( DatabaseMetaData databaseMetaData) { try { final String quoteIdentifierString = databaseMetaData.getIdentifierQuoteString(); return "".equals(quoteIdentifierString) // quoting not supported ? null : quoteIdentifierString; } catch (SQLException e) { throw Util.newInternal(e, "while quoting identifier"); } }
storesLowerCaseQuotedIdentifiers = databaseMetaData.storesLowerCaseQuotedIdentifiers(); storesMixedCaseQuotedIdentifiers = databaseMetaData.storesMixedCaseQuotedIdentifiers(); identifierQuoteString = databaseMetaData.getIdentifierQuoteString(); sqlKeywords = databaseMetaData.getSQLKeywords(); numericFunctions = databaseMetaData.getNumericFunctions();
r.refOfIndex("identifierQuoteString").assign(metaData.getIdentifierQuoteString());
public DbmsMeta fetchDbmsMeta(DatabaseMetaData databaseMetaData) { DbmsMeta.Builder builder = new DbmsMeta.Builder(); onlyLogException(() -> builder.productName(databaseMetaData.getDatabaseProductName())); onlyLogException(() -> builder.productVersion(databaseMetaData.getDatabaseProductVersion())); onlyLogException(() -> builder.sqlKeywords(getSQLKeywords(databaseMetaData))); onlyLogException(() -> builder.systemFunctions(formatSqlKeyWords(databaseMetaData.getSystemFunctions().split(",")))); onlyLogException(() -> builder.stringFunctions(formatSqlKeyWords(databaseMetaData.getStringFunctions().split(",")))); onlyLogException(() -> builder.numericFunctions(formatSqlKeyWords(databaseMetaData.getNumericFunctions().split(",")))); onlyLogException(() -> builder.timeDateFunctions(formatSqlKeyWords(databaseMetaData.getTimeDateFunctions().split(",")))); onlyLogException(() -> builder.identifierQuoteString(databaseMetaData.getIdentifierQuoteString().trim())); return builder.getDbmsMeta(); }