Skip to content

Commit

Permalink
fixing bug #9918
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasEYSSERIC committed Jul 30, 2018
1 parent a21d3c5 commit 86a1691
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
Expand Up @@ -37,9 +37,9 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Vector;

import com.silverpeas.util.StringUtil;
import org.silverpeas.mydb.control.DriverManager;
Expand Down Expand Up @@ -495,7 +495,7 @@ public boolean checkConnection() {
* @return The list of tables names available in database.
*/
public String[] getTableNames() {
Vector<String> tableVector = new Vector<String>();
List<String> tableVector = new ArrayList<String>();
startConnection();
if (connection == null) {
SilverTrace.warn("myDB", "MyDBSessionController.getTableNames()",
Expand All @@ -506,7 +506,7 @@ public String[] getTableNames() {
if (dbMetaData != null) {
rs = dbMetaData.getTables(null, null, null, new String[]{"TABLE"});
while (rs.next()) {
tableVector.addElement(rs.getString("TABLE_NAME"));
tableVector.add(rs.getString("TABLE_NAME"));
}
}
} catch (SQLException e) {
Expand All @@ -517,7 +517,32 @@ public String[] getTableNames() {
closeConnection();
}
}
return (String[]) tableVector.toArray(new String[tableVector.size()]);
return getAuthorizedTables(tableVector);
}

private String[] getAuthorizedTables(List<String> tableNames) {
List<String> authorizedTables = new ArrayList<String>();
for (String tableName : tableNames) {
if (isAuthorizedTable(tableName)) {
authorizedTables.add(tableName);
}
}
return authorizedTables.toArray(new String[authorizedTables.size()]);
}

private boolean isAuthorizedTable(String tableName) {
startConnection();
try {
String query = "select count(*) from "+tableName;
prepStmt = connection.prepareStatement(query);
prepStmt.executeQuery();
rs = prepStmt.getResultSet();
} catch (SQLException e) {
return false;
} finally {
closeConnection();
}
return true;
}

/**
Expand Down Expand Up @@ -620,8 +645,9 @@ public DbTable getDbTable() throws MyDBException {
SilverpeasException.ERROR,
"myDB.EX_CANNOT_GET_TABLE_DESCRIPTION", "TableName : "
+ tableName, e);
} finally {
closeConnection();
}
closeConnection();

if (dbTable != null) {
final String query = new StringBuffer(100).append("select ").append(
Expand Down Expand Up @@ -695,8 +721,9 @@ public DbTable getDbTable() throws MyDBException {
throw new MyDBException("myDBSessionController.getDbTable()",
SilverpeasException.ERROR, "myDB.EX_CANNOT_GET_TABLE_DATA",
"TableName : " + tableName, e);
} finally {
closeConnection();
}
closeConnection();
}
}
}
Expand Down Expand Up @@ -1199,7 +1226,7 @@ public boolean dropTable() {
String tableName = tableManager.getTable().getName();
connection = getConnection();
DatabaseMetaData dbMetaData = connection.getMetaData();
rs = dbMetaData.getTables(null, "%", tableName, new String[]{"TABLE"});
rs = dbMetaData.getTables(null, "%", tableName, new String[]{"TABLE"});
if (rs.next()) {
// Vérification de l'existence de la table.
stmt = connection.createStatement();
Expand Down
9 changes: 7 additions & 2 deletions mydb/mydb-war/src/main/webapp/myDB/jsp/consultation.jsp
Expand Up @@ -40,8 +40,13 @@

<body>
<%
DbTable dbTable = myDBSC.getDbTable();
StringBuffer pageTitleSb = new StringBuffer(resource.getString("PageTitleConsultation"));
DbTable dbTable = null;
try {
dbTable = myDBSC.getDbTable();
} catch (Exception e) {
}
StringBuffer pageTitleSb = new StringBuffer(resource.getString("PageTitleConsultation"));
if (dbTable != null)
{
pageTitleSb.append(" : ").append(resource.getString("Table")).append(" ").append(dbTable.getName());
Expand Down

0 comments on commit 86a1691

Please sign in to comment.