Skip to content

Commit 8ccbf02

Browse files
committed
remove read attached databases pragma
1 parent e7fe0a9 commit 8ccbf02

File tree

3 files changed

+7
-40
lines changed

3 files changed

+7
-40
lines changed

src/main/java/org/sqlite/SQLiteConfig.java

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ public class SQLiteConfig {
5656

5757
private final int busyTimeout;
5858
private boolean explicitReadOnly;
59-
private boolean readAttachedDatabases;
6059

6160
private final SQLiteConnectionConfig defaultConnectionConfig;
6261

@@ -94,10 +93,6 @@ public SQLiteConfig(Properties prop) {
9493
this.explicitReadOnly =
9594
Boolean.parseBoolean(
9695
pragmaTable.getProperty(Pragma.JDBC_EXPLICIT_READONLY.pragmaName, "false"));
97-
this.readAttachedDatabases =
98-
Boolean.parseBoolean(
99-
pragmaTable.getProperty(
100-
Pragma.METADATA_READ_ATTACHED_DATABASES.pragmaName, "false"));
10196
}
10297

10398
public SQLiteConnectionConfig newConnectionConfig() {
@@ -191,9 +186,8 @@ public void apply(Connection conn) throws SQLException {
191186
pragmaParams.remove(Pragma.LIMIT_WORKER_THREADS.pragmaName);
192187
pragmaParams.remove(Pragma.LIMIT_PAGE_COUNT.pragmaName);
193188

194-
// exclude these "fake" pragmas from execution
189+
// exclude this "fake" pragma from execution
195190
pragmaParams.remove(Pragma.JDBC_EXPLICIT_READONLY.pragmaName);
196-
pragmaParams.remove(Pragma.METADATA_READ_ATTACHED_DATABASES.pragmaName);
197191

198192
Statement stat = conn.createStatement();
199193
try {
@@ -336,10 +330,6 @@ public Properties toProperties() {
336330
defaultConnectionConfig.getDateStringFormat());
337331
pragmaTable.setProperty(
338332
Pragma.JDBC_EXPLICIT_READONLY.pragmaName, this.explicitReadOnly ? "true" : "false");
339-
pragmaTable.setProperty(
340-
Pragma.METADATA_READ_ATTACHED_DATABASES.pragmaName,
341-
this.readAttachedDatabases ? "true" : "false"
342-
);
343333
return pragmaTable;
344334
}
345335

@@ -383,20 +373,6 @@ public void setExplicitReadOnly(boolean readOnly) {
383373
this.explicitReadOnly = readOnly;
384374
}
385375

386-
/** @return true if reading attached databases is allowed */
387-
public boolean isReadAttachedDatabases() {
388-
return readAttachedDatabases;
389-
}
390-
391-
/**
392-
* Enable reading attached databases in metadata, they will be shown as schemas
393-
*
394-
* @param readAttachedDatabases whether to read attached databases
395-
*/
396-
public void setReadAttachedDatabases(boolean readAttachedDatabases) {
397-
this.readAttachedDatabases = readAttachedDatabases;
398-
}
399-
400376
public enum Pragma {
401377

402378
// Parameters requiring SQLite3 API invocation
@@ -558,11 +534,8 @@ public enum Pragma {
558534

559535
// extensions: "fake" pragmas to allow conformance with JDBC
560536
JDBC_EXPLICIT_READONLY(
561-
"jdbc.explicit_readonly", "Set explicit read only transactions", null),
562-
// "fake" pragma to allow configurating metadata reading by driver
563-
METADATA_READ_ATTACHED_DATABASES("metadata.read_attached_databases",
564-
"Set read attached databases as schemas",
565-
OnOff);
537+
"jdbc.explicit_readonly", "Set explicit read only transactions", null);
538+
566539
public final String pragmaName;
567540
public final String[] choices;
568541
public final String description;

src/main/java/org/sqlite/jdbc3/JDBC3DatabaseMetaData.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ public boolean supportsSavepoints() {
681681

682682
/** @see java.sql.DatabaseMetaData#supportsSchemasInDataManipulation() */
683683
public boolean supportsSchemasInDataManipulation() {
684-
return conn.getDatabase().getConfig().isReadAttachedDatabases();
684+
return true;
685685
}
686686

687687
/** @see java.sql.DatabaseMetaData#supportsSchemasInIndexDefinitions() */
@@ -1172,12 +1172,8 @@ public ResultSet getCrossReference(
11721172
/** @see java.sql.DatabaseMetaData#getSchemas() */
11731173
public ResultSet getSchemas() throws SQLException {
11741174
if (getSchemas == null) {
1175-
if (conn.getDatabase().getConfig().isReadAttachedDatabases()) {
1176-
getSchemas = conn.prepareStatement(
1177-
"select name as TABLE_SCHEM, null as TABLE_CATALOG from pragma_database_list;");
1178-
} else {
1179-
getSchemas = conn.prepareStatement("select null as TABLE_SCHEM, null as TABLE_CATALOG limit 0;");
1180-
}
1175+
getSchemas = conn.prepareStatement(
1176+
"select name as TABLE_SCHEM, null as TABLE_CATALOG from pragma_database_list;");
11811177
}
11821178

11831179
return getSchemas.executeQuery();

src/test/java/org/sqlite/DBMetaDataTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@ public void columnOrderOfgetProcedurColumns() throws SQLException {
10871087
@Test
10881088
public void columnOrderOfgetSchemas() throws SQLException {
10891089
ResultSet rs = meta.getSchemas();
1090-
assertThat(rs.next()).isFalse();
1090+
assertThat(rs.next()).isTrue();
10911091
ResultSetMetaData rsmeta = rs.getMetaData();
10921092
assertThat(rsmeta.getColumnCount()).isEqualTo(2);
10931093
assertThat(rsmeta.getColumnName(1)).isEqualTo("TABLE_SCHEM");
@@ -1577,7 +1577,6 @@ class DBMetadataTestWithAttachedDatabases {
15771577

15781578
@BeforeEach
15791579
public void init() throws IOException, SQLException {
1580-
((SQLiteConnection) conn).getDatabase().getConfig().setReadAttachedDatabases(true);
15811580
testDB = Files.createTempFile("temp", ".sqlite").toFile();
15821581
stat.executeUpdate("attach database \"" + testDB.toURI().toURL() + "\" as db2;");
15831582
stat.executeUpdate(
@@ -1875,7 +1874,6 @@ public void getIndexInfoIndexedMultiForAttachedDatabase() throws SQLException {
18751874

18761875
@AfterEach
18771876
public void exit() throws SQLException {
1878-
((SQLiteConnection) conn).getDatabase().getConfig().setReadAttachedDatabases(false);
18791877
stat.executeUpdate("Detach database db2;");
18801878
testDB.deleteOnExit();
18811879
}

0 commit comments

Comments
 (0)