Esempio n. 1
1
  public static void main(String arr[]) {
    ParseQuery pq = new ParseQuery();
    // DBSystem.readConfig("/tmp/config.txt");
    String configFilePath = arr[0];
    DBSystem.readConfig(configFilePath);
    // String query = "Select distinct * from countries where id=123 and code like 'jkl' group by
    // continent having code like 'antartic' order by name";
    String inputFile = arr[1];
    try {
      BufferedReader br = new BufferedReader(new FileReader(inputFile));
      String line;
      while ((line = br.readLine()) != null) {
        pq.queryType(line);
      }
    } catch (FileNotFoundException e) {
      System.out.println("Input file not found");
      // e.printStackTrace();
    } catch (IOException e) {
      System.out.println("I/O Exception");
      // e.printStackTrace();
    }

    //        /String query = "create table rtyui(name varchar, age int, rollno int)";

  }
Esempio n. 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);
  }