Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 365 lines (363 sloc) 8.838 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
<?php

class page_db extends Page_DBTest {
    public $db;
    public $proper_responses=array(
            "Test_raw_insert"=>array (
  0 => '',
  1 =>
  array (
  ),
),
            "Test_raw_params"=>array (
  0 => '1',
  1 =>
  array (
  ),
),
            "Test_raw_getOne"=>array (
  0 => 'John',
  1 =>
  array (
  ),
),
            "Test_raw_select"=>array (
  0 => 'John, Peter, Ian, Steve, Robert, Lucas, Jane, Dot, Param',
  1 =>
  array (
  ),
),
            "Test_simple"=>array (
  0 => 'select `foo` from `bar` ',
  1 =>
  array (
  ),
),
            "Test_simple_tostring"=>array (
  0 => 'select `foo` from `bar` ',
  1 =>
  array (
  ),
),
            "Test_simple_dot"=>array (
  0 => 'select `x`.foo.bar from `bar` ',
  1 =>
  array (
  ),
),
            "Test_multifields"=>array (
  0 => 'select `a`,`b`,`c` from `bar` ',
  1 =>
  array (
  ),
),
            "Test_multitable"=>array (
  0 => 'select `foo`.`a`,`foo`.`b`,`foo`.`c`,`bar`.`x`,`bar`.`y` from `bar`,`baz` ',
  1 =>
  array (
  ),
),
            "Test_selectall"=>array (
  0 => 'select * from `bar` ',
  1 =>
  array (
  ),
),
            "Test_select_opton1"=>array (
  0 => 'select SQL_CALC_FOUND_ROWS * from `foo` ',
  1 =>
  array (
  ),
),
            "Test_select_calc_rows"=>array (
  0 => 'select SQL_CALC_FOUND_ROWS * from `foo` limit 0, 5',
  1 =>
  array (
  ),
),
            "Test_select_calc_rows2"=>array (
  0 => '9',
  1 =>
  array (
  ),
),
            "Test_select_calc_rows3"=>array (
  0 => '1',
  1 =>
  array (
  ),
),
            "Test_row"=>array (
  0 => '{"id":"2","name":"Peter","a":"2","b":"4","c":"7"}',
  1 =>
  array (
    ':a' => 2,
  ),
),
            "Test_getAll"=>array (
  0 => '[{"id":"1","name":"John","a":"1","b":"2","c":"3"},{"id":"2","name":"Peter","a":"2","b":"4","c":"7"}]',
  1 =>
  array (
    ':a' => 1,
    ':a_2' => 2,
  ),
),
            "Test_iter1"=>array (
  0 => '1,John,1,2,3',
  1 =>
  array (
    ':a' => 1,
    ':a_2' => 2,
  ),
),
            "Test_iter2"=>array (
  0 => '1,2',
  1 =>
  array (
    ':a' => 1,
    ':a_2' => 2,
  ),
),
            "Test_doubleget"=>array (
  0 => '1',
  1 =>
  array (
    ':a' => 1,
    ':a_2' => 2,
  ),
),
            "Test_doubleiter"=>array (
  0 => '1',
  1 =>
  array (
    ':a' => 1,
    ':a_2' => 2,
  ),
),
            "Test_iteriter"=>array (
  0 => '9=9',
  1 =>
  array (
  ),
),
            "Test_ts"=>array (
  0 => 'select * from `foo` ',
  1 =>
  array (
  ),
),
            "Test_expr"=>array (
  0 => 'call foobar()',
  1 =>
  array (
  ),
),
            "Test_expr1"=>array (
  0 => '(select 1)',
  1 =>
  array (
  ),
),
            "Test_expr2"=>array (
  0 => 'select (select 1) `x1`,3+3 `x2` ',
  1 =>
  array (
  ),
),
            "Test_expr3"=>array (
  0 => 'acceptance',
  1 =>
  array (
  ),
),
            "Test_expr4"=>array (
  0 => 'foo',
  1 =>
  array (
  ),
),
            "Test_expr5"=>array (
  0 => 'foo..bar',
  1 =>
  array (
  ),
),
            "Test_update"=>array (
  0 => 'update `foo` set `name`=:a where `id` = :a_2',
  1 =>
  array (
    ':a' => 'Silvia',
    ':a_2' => '1',
  ),
),
            "Test_update2"=>array (
  0 => '[{"id":"1","name":"Silvia","a":"1","b":"2","c":"3"},{"id":"2","name":"Peter","a":"2","b":"4","c":"7"}]',
  1 =>
  array (
    ':a' => 1,
    ':a_2' => 2,
  ),
),
            "Test_update_then_select"=>array (
  0 => 'select * from `foo` where `id` = :a ',
  1 =>
  array (
    ':a' => 1,
  ),
),
            "Test_insert_all"=>array (
  0 => '10,11',
  1 =>
  array (
    ':a' => 'O\'Brien X',
    ':a_2' => 2,
    ':a_3' => 9,
  ),
)
        );

    function test_raw_insert($t){
        $this->db->query('insert into foo (name,a,b,c) values ("John", 1,2,3)');
        $this->db->query('insert into foo (name,a,b,c) values ("Peter", 2,4,7)');
        $this->db->query('insert into foo (name,a,b,c) values ("Ian", 2,4,7)');
        $this->db->query('insert into foo (name,a,b,c) values ("Steve", 2,4,7)');
        $this->db->query('insert into foo (name,a,b,c) values ("Robert", 2,4,7)');
        $this->db->query('insert into foo (name,a,b,c) values ("Lucas", 2,4,7)');
        $this->db->query('insert into foo (name,a,b,c) values ("Jane", 2,4,7)');
        $this->db->query('insert into foo (name,a,b,c) values ("Dot", 2,4,7)');
    }
    function test_raw_params($t){
        $this->db->query('insert into foo (name,a,b,c) values (:1, :2,:3, :4)',
            array(':1'=>'Param',':2'=>1,':3'=>2,':4'=>3)
        );
        return $this->db->getOne('select count(*) from foo where name=:1',array(':1'=>'Param'));
    }
    function test_raw_getOne($t){
        return $this->db->getOne('select name from foo');
    }
    function test_raw_select($t){
        $stmt=$this->db->query('select name from foo');
        $data=array();
        foreach($stmt as $row){
            $data[]=$row['name'];
        }
        return implode(', ',$data);
    }
    function test_simple($t){
        return $t->table('bar')->field('foo');
    }
    function test_simple_tostring($t){
        return $t->table('bar')->field('foo');
    }
    function test_simple_dot($t){
        return $t->table('bar')->field('foo.bar','x');
    }
    function test_multifields($t){
        return $t->table('bar')->field(array('a','b','c'));
    }
    function test_multitable($t){
        return $t->table(array('bar','baz'))->field(array('a','b','c'),'foo')->field(array('x','y'),'bar');
    }
    function test_selectall($t){
        return $t->table('bar');
    }
    function test_select_opton1($t){
        return $t->table('foo')->option('SQL_CALC_FOUND_ROWS');
    }
    function test_select_calc_rows($t){
        return $t->table('foo')->limit(5)->calc_found_rows();
    }
    function test_select_calc_rows2($t){
        $data=$t->table('foo')->limit(5)->calc_found_rows();
        return $t->foundRows();
    }
    function test_select_calc_rows3($t){
        $data=$t->table('foo')->limit(5)->get();// not using option, backward-compatible mode
        return $t->foundRows();
    }
    function test_row($t){
        return json_encode($t->table('foo')->where('id',2)->fetch());
    }
    function test_getAll($t){
        return json_encode($t->table('foo')->where('id',array(1,2))->get(),true);
    }
    function test_iter1($t){
        foreach($t->table('foo')->where('id',array(1,2)) as $row){
            return join(',',$row);
        }
        return 'OPS';
    }
    function test_iter2($t){
        $res=array();
        $t->table('foo')->where('id',array(1,2))->each(function($row) use(&$res){
            $res[]=$row['id'];
        });
        return join(',',$res);
    }
    function test_doubleget($t){
        $t->table('foo')->where('id',array(1,2));
        return $t->get()==$t->get();
    }
    function test_doubleiter($t){
        switch(1) {
        case 1:
            foreach($t->table('foo')->where('id',array(1,2)) as $row){
                $r=join(',',$row);
                break;
            }
        }
        foreach($t as $row){
            return $r==join(',',$row);
        }
        return "OPS";
    }
    function test_iteriter($t){
        $t1=$t2=0;
        foreach($t->table('foo') as $row){
            $t1++;
        }
        foreach($t as $row){
            $t2++;
        }
        return "$t1=$t2";
    }
    function test_ts($t){
        return $t->table('foo');
    }
    function test_expr($t){
        return $t->expr('call foobar()');
    }
    function test_expr1($t){
        return $t->expr('(select 1)');
    }
    function test_expr2($t){
        return $t
            ->field($t->expr('(select 1)'),'x1')
            ->field($t->expr('3+3'),'x2');
    }
    function test_expr3($t){
        return $t->expr('show tables')->getOne();
    }
    function test_expr4($t){
        return $t->expr('select [args]')->args(array('foo'))->getOne();
    }
    function test_expr5($t){
        return implode(',',$t->expr('select concat_ws([args])')->args(array('..','foo','bar'))->getHash());
    }
    function test_update($t){
        return $t->table('foo')->where('id','1')->set('name','Silvia')->SQLTemplate('update');
    }
    function test_update2($t){
        $tt=clone $t;
        $tt->table('foo')->where('id','1')->set('name','Silvia')->update();
        return json_encode($t->table('foo')->where('id',array(1,2))->getAll(),true);
    }
    function test_update_then_select($t){
        // executes update then returns select query
        return $t->table('foo')->where('id',1)->set('name','No1')->update();
    }
    function test_insert_all($t){
        return implode(',',$t->table('foo')->insertAll(array(
            array('name'=>'Jane "X-Men"','a'=>'2'),
            array('name'=>'O\'Brien X','b'=>2,'c'=>9),
        )));
    }
}
Something went wrong with that request. Please try again.