5
0
mirror of https://github.com/apache/sqoop.git synced 2025-05-09 21:51:01 +08:00

SQOOP-741: The OracleConnect getTables() implementation needs to restrict tables to current user

(Venkat Ranganathan via Jarek Jarcec Cecho)
This commit is contained in:
Jarek Jarcec Cecho 2012-12-06 08:51:41 -08:00
parent 0b465594d2
commit 05774d49be

View File

@ -82,7 +82,7 @@ public class OracleManager
* ensure that the table can be operated on for import/export purposes.
*/
public static final String QUERY_LIST_TABLES =
"SELECT TABLE_NAME FROM ALL_TABLES";
"SELECT TABLE_NAME FROM ALL_TABLES WHERE OWNER = ?";
/**
* Query to list all columns of the given table. Even if the user has the
@ -654,15 +654,20 @@ public String[] listDatabases() {
@Override
public String[] listTables() {
Connection conn = null;
Statement stmt = null;
PreparedStatement pStmt = null;
ResultSet rset = null;
List<String> tables = new ArrayList<String>();
String tableOwner = this.options.getUsername();
try {
conn = getConnection();
stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
pStmt = conn.prepareStatement(QUERY_LIST_TABLES,
ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY);
rset = stmt.executeQuery(QUERY_LIST_TABLES);
pStmt.setString(1, tableOwner);
rset = pStmt.executeQuery();
while (rset.next()) {
tables.add(rset.getString(1));
@ -683,9 +688,9 @@ public String[] listTables() {
LOG.error("Failed to close resultset", ex);
}
}
if (stmt != null) {
if (pStmt != null) {
try {
stmt.close();
pStmt.close();
} catch (Exception ex) {
LOG.error("Failed to close statement", ex);
}