|
19 | 19 | import com.google.auth.Credentials;
|
20 | 20 | import com.google.auth.ServiceAccountSigner;
|
21 | 21 | import com.google.auth.oauth2.UserCredentials;
|
| 22 | +import com.google.cloud.spanner.Dialect; |
22 | 23 | import com.google.cloud.spanner.ResultSets;
|
23 | 24 | import com.google.cloud.spanner.Struct;
|
24 | 25 | import com.google.cloud.spanner.Type;
|
@@ -48,8 +49,16 @@ class JdbcDatabaseMetaData extends AbstractJdbcWrapper implements DatabaseMetaDa
|
48 | 49 | private static final String PRODUCT_NAME = "Google Cloud Spanner";
|
49 | 50 |
|
50 | 51 | @VisibleForTesting
|
51 |
| -static String readSqlFromFile(String filename) { |
52 |
| -InputStream in = JdbcDatabaseMetaData.class.getResourceAsStream(filename); |
| 52 | +static String readSqlFromFile(String filename, Dialect dialect) { |
| 53 | +InputStream in; |
| 54 | +switch (dialect) { |
| 55 | +case POSTGRESQL: |
| 56 | +in = JdbcDatabaseMetaData.class.getResourceAsStream("postgresql/" + filename); |
| 57 | +break; |
| 58 | +case GOOGLE_STANDARD_SQL: |
| 59 | +default: |
| 60 | +in = JdbcDatabaseMetaData.class.getResourceAsStream(filename); |
| 61 | +} |
53 | 62 | BufferedReader reader = new BufferedReader(new InputStreamReader(in));
|
54 | 63 | StringBuilder builder = new StringBuilder();
|
55 | 64 | try (Scanner scanner = new Scanner(reader)) {
|
@@ -743,7 +752,7 @@ private JdbcPreparedStatement prepareStatementReplaceNullWithAnyString(
|
743 | 752 | public ResultSet getTables(
|
744 | 753 | String catalog, String schemaPattern, String tableNamePattern, String[] types)
|
745 | 754 | throws SQLException {
|
746 |
| -String sql = readSqlFromFile("DatabaseMetaData_GetTables.sql"); |
| 755 | +String sql = readSqlFromFile("DatabaseMetaData_GetTables.sql", connection.getDialect()); |
747 | 756 | String type1;
|
748 | 757 | String type2;
|
749 | 758 | if (types == null || types.length == 0) {
|
@@ -789,7 +798,7 @@ public ResultSet getTableTypes() {
|
789 | 798 | public ResultSet getColumns(
|
790 | 799 | String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern)
|
791 | 800 | throws SQLException {
|
792 |
| -String sql = readSqlFromFile("DatabaseMetaData_GetColumns.sql"); |
| 801 | +String sql = readSqlFromFile("DatabaseMetaData_GetColumns.sql", connection.getDialect()); |
793 | 802 | JdbcPreparedStatement statement =
|
794 | 803 | prepareStatementReplaceNullWithAnyString(
|
795 | 804 | sql, catalog, schemaPattern, tableNamePattern, columnNamePattern);
|
@@ -858,7 +867,7 @@ private ResultSet getEmptyColumnsResultSet() {
|
858 | 867 | @Override
|
859 | 868 | public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException {
|
860 | 869 | JdbcPreconditions.checkArgument(table != null, "table may not be null");
|
861 |
| -String sql = readSqlFromFile("DatabaseMetaData_GetPrimaryKeys.sql"); |
| 870 | +String sql = readSqlFromFile("DatabaseMetaData_GetPrimaryKeys.sql", connection.getDialect()); |
862 | 871 | JdbcPreparedStatement statement =
|
863 | 872 | prepareStatementReplaceNullWithAnyString(sql, catalog, schema, table);
|
864 | 873 | return statement.executeQueryWithOptions(InternalMetadataQuery.INSTANCE);
|
@@ -868,7 +877,7 @@ public ResultSet getPrimaryKeys(String catalog, String schema, String table) thr
|
868 | 877 | public ResultSet getImportedKeys(String catalog, String schema, String table)
|
869 | 878 | throws SQLException {
|
870 | 879 | JdbcPreconditions.checkArgument(table != null, "table may not be null");
|
871 |
| -String sql = readSqlFromFile("DatabaseMetaData_GetImportedKeys.sql"); |
| 880 | +String sql = readSqlFromFile("DatabaseMetaData_GetImportedKeys.sql", connection.getDialect()); |
872 | 881 | JdbcPreparedStatement statement =
|
873 | 882 | prepareStatementReplaceNullWithAnyString(sql, catalog, schema, table);
|
874 | 883 | return statement.executeQueryWithOptions(InternalMetadataQuery.INSTANCE);
|
@@ -878,7 +887,7 @@ public ResultSet getImportedKeys(String catalog, String schema, String table)
|
878 | 887 | public ResultSet getExportedKeys(String catalog, String schema, String table)
|
879 | 888 | throws SQLException {
|
880 | 889 | JdbcPreconditions.checkArgument(table != null, "table may not be null");
|
881 |
| -String sql = readSqlFromFile("DatabaseMetaData_GetExportedKeys.sql"); |
| 890 | +String sql = readSqlFromFile("DatabaseMetaData_GetExportedKeys.sql", connection.getDialect()); |
882 | 891 | JdbcPreparedStatement statement =
|
883 | 892 | prepareStatementReplaceNullWithAnyString(sql, catalog, schema, table);
|
884 | 893 | return statement.executeQueryWithOptions(InternalMetadataQuery.INSTANCE);
|
@@ -893,7 +902,8 @@ public ResultSet getCrossReference(
|
893 | 902 | String foreignSchema,
|
894 | 903 | String foreignTable)
|
895 | 904 | throws SQLException {
|
896 |
| -String sql = readSqlFromFile("DatabaseMetaData_GetCrossReferences.sql"); |
| 905 | +String sql = |
| 906 | +readSqlFromFile("DatabaseMetaData_GetCrossReferences.sql", connection.getDialect()); |
897 | 907 | JdbcPreparedStatement statement =
|
898 | 908 | prepareStatementReplaceNullWithAnyString(
|
899 | 909 | sql,
|
@@ -1251,7 +1261,7 @@ public ResultSet getIndexInfo(String catalog, String schema, String indexName)
|
1251 | 1261 | private ResultSet getIndexInfo(
|
1252 | 1262 | String catalog, String schema, String table, String indexName, boolean unique)
|
1253 | 1263 | throws SQLException {
|
1254 |
| -String sql = readSqlFromFile("DatabaseMetaData_GetIndexInfo.sql"); |
| 1264 | +String sql = readSqlFromFile("DatabaseMetaData_GetIndexInfo.sql", connection.getDialect()); |
1255 | 1265 | JdbcPreparedStatement statement =
|
1256 | 1266 | prepareStatementReplaceNullWithAnyString(
|
1257 | 1267 | sql, catalog, schema, table, indexName, unique ? "YES" : "%");
|
@@ -1467,7 +1477,7 @@ public RowIdLifetime getRowIdLifetime() {
|
1467 | 1477 |
|
1468 | 1478 | @Override
|
1469 | 1479 | public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException {
|
1470 |
| -String sql = readSqlFromFile("DatabaseMetaData_GetSchemas.sql"); |
| 1480 | +String sql = readSqlFromFile("DatabaseMetaData_GetSchemas.sql", connection.getDialect()); |
1471 | 1481 | JdbcPreparedStatement statement =
|
1472 | 1482 | prepareStatementReplaceNullWithAnyString(sql, catalog, schemaPattern);
|
1473 | 1483 | return statement.executeQueryWithOptions(InternalMetadataQuery.INSTANCE);
|
|
0 commit comments