Beispiel #1
0
function set_where($t)
{
    $cond1 = new SQLMakerCondition();
    $cond1->add(array('name' => 'john'));
    $cond2 = new SQLMakerCondition();
    $cond2->add(array('type' => array('in' => array(1, 2, 3))));
    $sql = _ns()->add_select('c')->add_from('foo')->set_where($cond1->compose_and($cond2))->as_sql();
    $t->is($sql, 'SELECT c FROM foo WHERE ((name = ?)) AND ((type IN (?, ?, ?)))');
}
Beispiel #2
0
#!/usr/bin/env php
<?php 
require_once dirname(__FILE__) . '/lib/setup.php';
require_once 'SQLMaker/Condition.php';
$w1 = new SQLMakerCondition();
$w1->add(array('x' => 1));
$w1->add(array('y' => 2));
$w2 = new SQLMakerCondition();
$w2->add('a', 3);
$w2->add('b', 4);
function compose_and($t)
{
    global $w1, $w2;
    $and = $w1->compose_and($w2);
    $t->is($and->as_sql(), '((x = ?) AND (y = ?)) AND ((a = ?) AND (b = ?))');
    $t->is(implode(',', $and->bind), '1,2,3,4');
    $and->add('z', 99);
    $t->is($and->as_sql(), '((x = ?) AND (y = ?)) AND ((a = ?) AND (b = ?)) AND (z = ?)');
    $t->is(implode(',', $and->bind), '1,2,3,4,99');
}
function compose_or($t)
{
    global $w1, $w2;
    $and = $w1->compose_or($w2);
    $t->is($and->as_sql(), '((x = ?) AND (y = ?)) OR ((a = ?) AND (b = ?))');
    $t->is(implode(',', $and->bind), '1,2,3,4');
    $and->add('z', 99);
    $t->is($and->as_sql(), '((x = ?) AND (y = ?)) OR ((a = ?) AND (b = ?)) AND (z = ?)');
    $t->is(implode(',', $and->bind), '1,2,3,4,99');
}
function to_string($t)