Esempio n. 1
0
  /** This method caueses the project to generate the table that is the result of the PROJECT. */
  public void generateTemporaryTable() {

    // Get the schema for the thing below it
    Relation source = RelationHolder.getRelationHolder().getRelation(tableOne.getResultTableID());

    // Create the new table
    Relation result = new Relation(QueryParser.RESULT + resultTableID, resultTableID);
    RelationHolder.getRelationHolder().addRelation(result);

    // System.out.println("PROJECT TABLE SOURCE: " + source);
    // System.out.println("PROJECT ATTRIBUTES: " + attributes);
    // System.out.println("SOURCE ATTRIBUTES: " + source.getAttributes());

    // For each attribute, get the real thing from the source
    for (int index = 0; index < attributes.size(); index++) {

      String currentName = attributes.get(index);
      // System.out.println("PROJECT CURRENT ATTRIBUTE: " + currentName);
      // Use tempCurrentName cause it may be qualified
      Attribute currentAttribute = source.getAttributeByName(currentName);

      // Give it the full name when we make it though
      Attribute newAttribute = new Attribute(currentName, currentAttribute.getType(), 0);

      result.addAttribute(newAttribute);
    }
  }
Esempio n. 2
0
  public boolean execute() {
    if (!tableOne.execute()) {
      System.out.println("in here?");
      return false;
    }
    Relation r = RelationHolder.getRelationHolder().getRelation(this.resultTableID);
    Relation s = RelationHolder.getRelationHolder().getRelation(tableOne.getResultTableID());
    String[] attnames = new String[attributes.size()];
    if (r == null) return false;

    for (int j = 0; j < attnames.length; j++) {
      Attribute att = s.getAttributeByName(attributes.get(j).trim());
      // r.addAttribute(att.getName(), att.getType(),
      // Database.getCatalog().getSmallestUnusedAttributeID());
      attnames[j] = att.getName();
    }
    System.out.println(attnames);
    Iterator it = new Iterator(s);
    String[] newattvals = new String[attnames.length];
    while (it.hasNext()) {
      System.out.println("onerow");
      String[] oldattvals = it.getNext();
      for (int j = 0; j < attributes.size(); j++) {
        for (Attribute a : s.getAttributes()) {
          System.out.println(a.getName());
        }
        int idx = s.getIndexByName(attributes.get(j));
        newattvals[j] = oldattvals[idx];
      }
      if (!Database.getCatalog().insert(this.resultTableID, attnames, newattvals)) return false;
    }
    return true;
  }