public function testBlock4() { $alias = new Alias($sum = new Op('+', ["red", "yellow", "green"]), "local"); $node = Enum::values(["aa", "bb", $alias, "cc"]); $sum->setBlock(); $res = $node->render($this->board(), 1); $exp = implode("\n", [" 'aa',", " 'bb',", " red", " + yellow", " + green AS \"local\",", " 'cc'"]); // $this->dump($res, 1); // $this->assertEquals($exp, $res->getSql()); }
public function testBlock5() { $board = $this->board(); $cc = Op::bin('xx', '@@', 'yy'); $node = new Op('AND', ['aa', Op::bin('bb', 'OR', $cc), 'dd']); $node->setBlock(); $res = $node->render($board, 1); $exp = implode("\n", [" aa", " AND (bb OR (xx @@ yy))", " AND dd"]); // $this->dump($res, 0); $this->assertEquals($exp, $res->getSql()); }
public function testComplex1() { $db = $this->board(false); $select1 = (new Sql\Select("info"))->from("other_table")->where("id = ?", [4711]); $select = new Sql\Select(); $select->columns([["t.id", "the_id"], "t.name", [$select1, "col_x"], "t.created_at", "t.data"])->from("the_table", "t")->join("other_table", "x", "t.id = x.id")->join("more_table", "m", "t.id = m.id AND m.filter = ?", 123)->where($where = new Sql\Operator('AND'))->orderBy(["created_at ASC"])->limit(10)->offset(15); $where->add("t.some_num = ?", 42)->add("t.second = ?", 'string'); $res = $select->render($db); $exp = file_get_contents($this->path('select-01.sql')); $val = [4711, 123, 42, 'string']; // $this->dump($res, 0); // var_dump($res->getParams()); $this->assertEquals(trim($exp), trim($res)); $this->assertEquals($val, $res->getParams()); }
public function testBasic() { $table = new Sql\Table("my_table", "t"); $table->leftJoin("other_table", "x", "t.id = x.id AND y = ?", [4711]); $table->leftJoin("third_table", "y", Op::bin(new Id("t.id"), '=', new Id("y.id"))); $res = $table->render($this->board(false)); // $this->dump($res, 0); // var_dump($res->getParams()); }