Beispiel #1
0
  private boolean validateTables(TSelectSqlStatement stmt) {
    HashMap<String, Integer> present = new HashMap<String, Integer>();
    if (!stmt.getResultColumnList().getResultColumn(0).toString().equals("*")) {

      int cols = stmt.getResultColumnList().size();
      for (int a = 0; a < cols; a++) {
        present.put(
            stmt.getResultColumnList()
                .getResultColumn(a)
                .toString()
                .toLowerCase()
                .replace("(", "")
                .replace(")", ""),
            0);
      }
    }

    TJoinList joins = stmt.joins;
    int j = joins.size();
    int invalid = 1;
    for (int i = 0; i < j; i++) {
      Iterator<Table> it = DBSystem.tableList.iterator();
      Table table = null;
      while (it.hasNext()) {
        table = it.next();
        if (table.getName().equalsIgnoreCase(joins.getJoin(i).toString())) {
          invalid = 0;
          if (!stmt.getResultColumnList().getResultColumn(0).toString().equals("*")) {
            Iterator it1 = table.getColumnData().entrySet().iterator();

            while (it1.hasNext()) {
              Map.Entry pairs = (Map.Entry) it1.next();
              if (present.get(pairs.getKey().toString().toLowerCase()) != null
                  && present.get(pairs.getKey().toString().toLowerCase()) == 0) {
                present.put(pairs.getKey().toString(), 1);
              } else if (present.get(pairs.getKey().toString().toLowerCase()) != null
                  && present.get(pairs.getKey().toString().toLowerCase()) == 1) return false;
            }
          }
        }
      }
      if (invalid == 1) return false;
      else {
        invalid = 1;
      }
    }
    if (!stmt.getResultColumnList().getResultColumn(0).toString().equals("*")) {
      Iterator it2 = present.entrySet().iterator();
      while (it2.hasNext()) {
        Map.Entry pairs = (Map.Entry) it2.next();
        if ((Integer) pairs.getValue() == 0) {
          return false;
        }
      }
    }
    return true;
  }
Beispiel #2
0
  private String validateColumns(String condition, TJoinList joins) {
    try {
      Integer.parseInt(condition);
      return "int";
    } catch (NumberFormatException e) {

    }

    try {
      Double.parseDouble(condition);
      return "float";
    } catch (NumberFormatException e) {

    }

    if (condition.contains("'") || condition.contains("\"")) return "varchar";
    else {
      int j = joins.size();
      for (int i = 0; i < j; i++) {
        Iterator<Table> it = DBSystem.tableList.iterator();
        Table table = null;
        while (it.hasNext()) {
          table = it.next();
          if (table.getName().equalsIgnoreCase(joins.getJoin(i).toString())) {

            Iterator it1 = table.getColumnData().entrySet().iterator();

            while (it1.hasNext()) {
              Map.Entry pairs = (Map.Entry) it1.next();
              String colName = pairs.getValue().toString();
              if (pairs.getKey().toString().equalsIgnoreCase(condition)) {
                if (colName.equalsIgnoreCase("varchar") || colName.equalsIgnoreCase("string"))
                  return "varchar";
                else if (colName.equalsIgnoreCase("int") || colName.equalsIgnoreCase("integer"))
                  return "int";
                return pairs.getValue().toString().toLowerCase();
              }
            }
          }
        }
      }
    }
    return "invalid";
  }
Beispiel #3
0
 private String getColumnName(TJoinList joins) {
   int j = joins.size();
   Set<String> columnName = new HashSet<String>();
   for (int i = 0; i < j; i++) {
     Iterator<Table> it = DBSystem.tableList.iterator();
     Table table = null;
     while (it.hasNext()) {
       table = it.next();
       if (table.getName().equalsIgnoreCase(joins.getJoin(i).toString())) {
         Iterator it1 = table.getColumnData().entrySet().iterator();
         while (it1.hasNext()) {
           Map.Entry pairs = (Map.Entry) it1.next();
           columnName.add((String) pairs.getKey());
         }
         break;
       }
     }
   }
   return columnName
       .toString()
       .substring(1, columnName.toString().length() - 1)
       .replaceAll(" ", "")
       .toLowerCase();
 }