Exemplo n.º 1
0
 @Test
 public void InsertTest() {
   String query = "INSERT INTO test_tab VALUES (1, 2, \"dog\"), \n(3, 4, \"cat\")";
   SQLParser parser = new SQLParser(null);
   InsertRowsCommand command = (InsertRowsCommand) parser.parse(query);
   Assert.assertEquals(true, true);
 }
Exemplo n.º 2
0
  @Test
  public void SelectWhereTest() {
    DbContext context = new DbContext(RESOURCE_PATH);
    String tableName = CreateTestTable(context);
    String query = "SELECT * FROM " + tableName + " WHERE column1 > 3 AND col3 <> \"ccc5\"";

    SQLParser parser = new SQLParser(context);
    SelectCommand command = (SelectCommand) parser.parse(query);
    RowPredicate predicate = command.predicate();
    List<SingleCondition> conditions = predicate.conditions();

    Assert.assertEquals("{0}", conditions.get(0)._val1);
    Assert.assertEquals(">", conditions.get(0)._operator);
    Assert.assertEquals("3", conditions.get(0)._val2);

    Assert.assertEquals("{2}", conditions.get(1)._val1);
    Assert.assertEquals("<>", conditions.get(1)._operator);
    Assert.assertEquals("\"ccc5\"", conditions.get(1)._val2);

    List<Object> test_row1 = new ArrayList<Object>();
    test_row1.add(4);
    test_row1.add("\"abc4\"");
    test_row1.add("\"ccc4\"");

    List<Object> test_row2 = new ArrayList<Object>();
    test_row2.add(5);
    test_row2.add("\"abc5\"");
    test_row2.add("\"ccc5\"");

    Assert.assertEquals(predicate.evaluate(test_row1), true);
    Assert.assertEquals(predicate.evaluate(test_row2), false);
  }
Exemplo n.º 3
0
  @Test
  public void SelectAllTest() {
    DbContext context = new DbContext(RESOURCE_PATH);
    String tableName = CreateTestTable(context);
    String query = "SELECT * FROM " + tableName;

    SQLParser parser = new SQLParser(context);
    SelectAllRowsCommand command = (SelectAllRowsCommand) parser.parse(query);
    Assert.assertEquals(tableName, command.tableName());

    context.close();
  }
Exemplo n.º 4
0
 @Test
 public void CreateTableTest() {
   String query =
       "CREATE TABLE test_tab \n ( \n "
           + "col1 int , \n"
           + "col2 char(32) ,\n"
           + "col3 char (8)\n"
           + ")";
   SQLParser parser = new SQLParser(null);
   CreateTableCommand command = (CreateTableCommand) parser.parse(query);
   Assert.assertEquals(true, true);
 }