示例#1
0
  public int validateAndDisplayCreateCommandParameters(String query) { // incomplete
    int rValue = 0;
    TGSqlParser tgSqlParser = new TGSqlParser(EDbVendor.dbvoracle);
    tgSqlParser.sqltext = query;
    tgSqlParser.parse();
    TCreateTableSqlStatement tCreateTableSqlStatement =
        (TCreateTableSqlStatement) tgSqlParser.sqlstatements.get(0);

    try {
      // Also validate that if that table is present
      // by searching for that table in the tablelist
      // populated by the readConfig method.

      for (Table t : DBSystem.tableList) {
        if (t.getName().equalsIgnoreCase(tCreateTableSqlStatement.getTableName().toString())) {
          return 0;
        }
      }
      System.out.println("Querytype:create");
      System.out.println("Tablename:" + tCreateTableSqlStatement.getTableName());
      tab_name = tCreateTableSqlStatement.getTableName().toString().toLowerCase();
      // System.out.println(tCreateTableSqlStatement.getTableName());        //table name
      int numberOfCols = tCreateTableSqlStatement.getColumnList().size();
      // System.out.println(numberOfCols);
      System.out.print("Attributes:");
      for (int k = 0; k < numberOfCols; k++) {
        String CName =
            tCreateTableSqlStatement.getColumnList().getColumn(k).getColumnName().toString();
        String dType =
            tCreateTableSqlStatement.getColumnList().getColumn(k).getDatatype().toString();

        System.out.print(CName); // get 1st column name
        System.out.print(" ");
        System.out.print(dType); // get 1st column data type
        if (k != numberOfCols - 1) {
          sb.append(CName).append(":").append(dType).append(",");
          System.out.print(",");
        } else {
          sb.append(CName).append(":").append(dType);
        }
      }
      System.out.println();
      rValue = 1;

    } catch (NullPointerException ne) {
      // ne.printStackTrace();
    }
    return rValue;
  }
示例#2
0
  public void createCommand(String query) {

    int isValid = validateAndDisplayCreateCommandParameters(query);
    PrintWriter pow = null;
    if (isValid == 1) {
      // System.out.println(DBSystem.PATH_FOR_DATA);
      try {
        // code to Create the tablename.data and tablename.csv file.
        File fdataFile = new File(DBSystem.PATH_FOR_DATA + "/" + tab_name + ".data");
        new File(DBSystem.PATH_FOR_DATA + "/" + tab_name + ".csv").createNewFile();
        // Add the details in the .data file
        pow = new PrintWriter(new FileWriter(fdataFile));
        pow.write(sb.toString());
        pow.flush();
        // Add the details in the config.txt.
        pow = new PrintWriter(new FileWriter(DBSystem.CONFIG_FILE_PATH, true));
        pow.write("BEGIN\n");
        pow.write(tab_name + "\n");
        String[] ar = sb.toString().split(",");
        for (int j = 0; j < ar.length; j++) {
          String[] at = ar[j].split(":");
          pow.write(at[0]);
          pow.write(",");
          pow.write(at[1] + "\n");
        }
        pow.write("END\n");
      } catch (IOException e) {
        e.printStackTrace();
      } finally {
        pow.close();
      }
    } else {
      System.out.println("Query Invalid");
    }
    DBSystem.readConfig(DBSystem.CONFIG_FILE_PATH);
  }