// return all grantees: thr_0, thr_1, thr_2 ..., excluding itself
 private static String getAllGrantees() {
   StringBuffer aStr = new StringBuffer("  ");
   Map<String, String> userPasswd =
       (Map<String, String>) SQLBB.getBB().getSharedMap().get(SQLSecurityTest.userPasswdMap);
   for (Map.Entry<String, String> e : userPasswd.entrySet()) {
     if (!e.getKey().equalsIgnoreCase("thr_" + RemoteTestModule.getCurrentThread().getThreadId()))
       aStr.append(e.getKey() + ", ");
   }
   if (aStr.charAt(aStr.length() - 2) == ',') {
     aStr.deleteCharAt(aStr.length() - 2);
   }
   aStr.deleteCharAt(0); // delete the leading space
   return aStr.toString();
 }
 // return optionally any insert, delete, trigger, select [col list], update [col list]
 private String getPrivilegeLists(String tableName) {
   StringBuffer aStr = new StringBuffer("  ");
   for (int i = 0; i < tablePriv.length; i++) {
     if (SQLTest.random.nextBoolean()) {
       aStr.append(tablePriv[i]); // insert delete etc
       if (i > 2) {
         aStr.append(getColumnLists(tableName)); // column list for the table
       } // may include column list
       aStr.append(", ");
     }
   }
   if (aStr.charAt(aStr.length() - 2) == ',') {
     aStr.deleteCharAt(aStr.length() - 2);
   }
   aStr.deleteCharAt(0); // delete the leading space
   return aStr.toString();
 }
 // returns column list: column-id, column-id ...
 private String getColumnLists(String tableName) {
   List<String> colNames = (List<String>) tableCols.get(tableName);
   StringBuffer aStr = new StringBuffer("  ");
   for (int i = 0; i < colNames.size(); i++) {
     if (SQLTest.random.nextBoolean()) {
       aStr.append(colNames.get(i) + ", ");
     }
   }
   if (aStr.charAt(aStr.length() - 2) == ',') {
     aStr.deleteCharAt(aStr.length() - 2);
   }
   aStr.deleteCharAt(0); // delete the leading space
   if (aStr.length() != 1) {
     aStr.insert(1, '(');
     aStr.append(')');
   } // has column
   return aStr.toString();
 }
  // any number of users excluding itself
  private static String getGrantees(int num) {
    StringBuffer aStr = new StringBuffer("  ");
    Map<String, String> userPasswd =
        (Map<String, String>) SQLBB.getBB().getSharedMap().get(SQLSecurityTest.userPasswdMap);
    userPasswd.remove("thr_" + RemoteTestModule.getCurrentThread().getThreadId());
    String[] users = new String[userPasswd.size()];
    userPasswd.keySet().toArray(users);
    int i = 0;
    while (i < num) {
      int x = SQLTest.random.nextInt(users.length);
      aStr.append(users[x] + ", ");
      i++;
    }

    if (aStr.charAt(aStr.length() - 2) == ',') {
      aStr.deleteCharAt(aStr.length() - 2);
    }
    aStr.deleteCharAt(0); // delete the leading space
    return aStr.toString();
  }
Ejemplo n.º 5
0
  private void addModuleScore(Connection conn, List row, int modId, int studId, boolean isPractice)
      throws SQLException {
    ResultSet rs = null;
    PreparedStatement stmt = null;
    try {
      String q =
          "select isCorrect,userInput,eventType,qid from eventlog where userid=? and (eventType='survey.evalq' or eventType='evalq' or eventType='evaltq' or eventType='survey.evaltq') and modId=?";
      stmt = conn.prepareStatement(q);
      stmt.setInt(1, studId);
      stmt.setInt(2, modId);
      rs = stmt.executeQuery();
      StringBuffer surveyAnswers = new StringBuffer();
      int nQuestions = 0;
      int nCorrect = 0;
      while (rs.next()) {
        boolean isCorrect = rs.getBoolean(1);
        String input = rs.getString(2);
        String eventType = rs.getString(3);
        int qid = rs.getInt(4);
        if (eventType.equals("survey.evalq") || eventType.equals("survey.evaltq"))
          surveyAnswers.append("(" + qid + " " + input + ") |");
        else {
          nQuestions++;
          if (isCorrect) nCorrect++;
        }
      }
      if (surveyAnswers.length() > 0) surveyAnswers.deleteCharAt(surveyAnswers.length() - 1);
      if (!isPractice) row.add(String.format("%5.2f", (nCorrect / ((double) nQuestions) * 100.0)));
      else row.add("");
      row.add(surveyAnswers.toString());

    } finally {
      if (stmt != null) stmt.close();
      if (rs != null) rs.close();
    }
  }