Example #1
0
 public function test3()
 {
     $sql = "/*BEGIN*/where /*IF id != null*/id = /*id*/3/*END*//*FOR userList*//*FIRST*/ and (/*END*//*NEXT 'or '*/username like /*#current*/'kato'/*LAST*/)/*END*//*END*//*END*/";
     $an = new SqlAnalyzer($sql);
     $node = $an->analyze();
     $param = array('userList' => array('sato', 'suzuki', 'takahashi'), 'id' => 3);
     $context = Context\CommandContext::createCommandContext($param);
     $node->acceptContext($context);
     echo $testSql = $context->getSql();
     $this->assertSame("where id = ? and (username like ? or username like ? or username like ?)", $testSql);
 }
Example #2
0
    public function testAnalyze3()
    {
        $sql = <<<SQL
/*IF pmb.isPaging()*/
SELECT * 
-- ELSE select count(*)
/*END*/
\tfrom user
SQL;
        $an = new SqlAnalyzer($sql);
        $node = $an->analyze();
        $param = new Param();
        $context = Context\CommandContext::createCommandContext($param);
        $node->acceptContext($context);
        echo $context->getSql();
    }
Example #3
0
 public function test24()
 {
     $sql = "/*IF a.isPaging('foo')*/b = /*@b*/100/*END*/";
     $an = new SqlAnalyzer($sql);
     $node = $an->analyze();
     $param = new Pmb();
     $context = Context\CommandContext::createCommandContext($param);
     $node->acceptContext($context);
     echo $testSql = $context->getSql();
     $this->assertSame('', $testSql);
 }
 public function test10()
 {
     $sql = "limit /*@a*/10, /*@b*/100";
     $an = new SqlAnalyzer($sql);
     $node = $an->analyze();
     $param = array('a' => 100, 'b' => 1000);
     $context = Context\CommandContext::createCommandContext($param);
     $node->acceptContext($context);
     echo $testSql = $context->getSql();
     $this->assertSame("limit 100, 1000", $testSql);
 }
Example #5
0
 public function test9()
 {
     $sql = "and BIRTHDATE = /*pmb.birthdate*/timestamp'2010-06-06 00:00:00'";
     $an = new SqlAnalyzer($sql);
     $node = $an->analyze();
     $param = array('birthdate' => '2013-10-10 00:00:00');
     $context = Context\CommandContext::createCommandContext($param);
     $node->acceptContext($context);
     $testSql = $context->getSql();
     $this->assertSame('and BIRTHDATE = ?', $testSql);
     $bindVariables = $context->getBindVariables();
     $this->assertSame('2013-10-10 00:00:00', $bindVariables[0]);
 }
 /**
  */
 public function test6()
 {
     $sql = "/*IF a != null*/a = /*b*/1/*END*/";
     $an = new SqlAnalyzer($sql);
     $node = $an->analyze();
     $param = array('a' => 4999, 'b' => null);
     $context = Context\CommandContext::createCommandContext($param);
     $node->acceptContext($context);
 }