Query/tests/databases/firebird/firebird-qb.php

273 lines
5.2 KiB
PHP
Raw Normal View History

2012-03-15 09:25:18 -04:00
<?php
/**
* Query
*
* Free Query Builder / Database Abstraction Layer
*
* @author Timothy J. Warren
* @copyright Copyright (c) 2012
* @link https://github.com/aviat4ion/Query
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
/**
* Firebird Query Builder Tests
*/
class FirebirdQBTest extends QBTest {
2012-03-15 09:25:18 -04:00
function __construct()
{
parent::__construct();
2012-04-11 11:48:56 -04:00
$dbpath = TEST_DIR.DS.'db_files'.DS.'FB_TEST_DB.FDB';
2012-03-15 09:25:18 -04:00
// Test the query builder
$params = new Stdclass();
$params->type = 'firebird';
$params->file = $dbpath;
$params->host = 'localhost';
$params->user = 'sysdba';
$params->pass = 'masterkey';
$this->db = new Query_Builder($params);
2012-03-19 13:58:14 -04:00
// echo '<hr /> Firebird Queries <hr />';
2012-03-15 09:25:18 -04:00
}
function TestGet()
{
$query = $this->db->get('create_test ct');
$this->assertIsA($query, 'Firebird_Result');
2012-03-15 09:25:18 -04:00
}
function TestGetLimit()
{
$query = $this->db->get('create_test', 2);
$this->assertIsA($query, 'Firebird_Result');
2012-03-15 09:25:18 -04:00
}
function TestGetLimitSkip()
{
$query = $this->db->get('create_test', 2, 1);
$this->assertIsA($query, 'Firebird_Result');
2012-03-15 09:25:18 -04:00
}
function TestSelectWhereGet()
{
$query = $this->db->select('id, key as k, val')
->where('id >', 1)
->where('id <', 800)
->get('create_test', 2, 1);
$this->assertIsA($query, 'Firebird_Result');
2012-03-15 09:25:18 -04:00
}
function TestSelectWhereGet2()
{
$query = $this->db->select('id, key as k, val')
->where(' id ', 1)
->get('create_test', 2, 1);
$this->assertIsA($query, 'Firebird_Result');
2012-03-15 09:25:18 -04:00
}
function TestSelectMax()
{
if (empty($this->db)) return;
$query = $this->db->select_max('id', 'di')
->get('create_test');
$this->assertIsA($query, 'Firebird_Result');
}
function TestSelectMin()
{
if (empty($this->db)) return;
$query = $this->db->select_min('id', 'di')
->get('create_test');
$this->assertIsA($query, 'Firebird_Result');
}
function TestSelectAvg()
{
if (empty($this->db)) return;
$query = $this->db->select_avg('id', 'di')
->get('create_test');
$this->assertIsA($query, 'Firebird_Result');
}
function TestSelectSum()
{
if (empty($this->db)) return;
$query = $this->db->select_sum('id', 'di')
->get('create_test');
$this->assertIsA($query, 'Firebird_Result');
}
function TestGetWhere()
{
if (empty($this->db)) return;
$query = $this->db->get_where('create_test', array('id !=' => 1), 2, 1);
$this->assertIsA($query, 'Firebird_Result');
}
2012-03-15 09:25:18 -04:00
function TestSelectGet()
{
$query = $this->db->select('id, key as k, val')
->get('create_test', 2, 1);
$this->assertIsA($query, 'Firebird_Result');
2012-03-15 09:25:18 -04:00
}
function TestSelectFromGet()
{
$query = $this->db->select('id, key as k, val')
->from('create_test ct')
->where('id >', 1)
->get();
$this->assertIsA($query, 'Firebird_Result');
2012-03-15 09:25:18 -04:00
}
function TestSelectFromLimitGet()
{
$query = $this->db->select('id, key as k, val')
->from('create_test ct')
->where('id >', 1)
->limit(3)
->get();
$this->assertIsA($query, 'Firebird_Result');
2012-03-15 09:25:18 -04:00
}
function TestOrderBy()
{
$query = $this->db->select('id, key as k, val')
->from('create_test')
->where('id >', 0)
->where('id <', 9000)
->order_by('id', 'DESC')
->order_by('k', 'ASC')
->limit(5,2)
->get();
$this->assertIsA($query, 'Firebird_Result');
2012-03-15 09:25:18 -04:00
}
2012-03-19 13:38:49 -04:00
function TestOrderByRandom()
2012-03-15 09:25:18 -04:00
{
$query = $this->db->select('id, key as k, val')
->from('create_test')
->where('id >', 0)
->where('id <', 9000)
->order_by('id', 'rand')
->limit(5,2)
->get();
$this->assertIsA($query, 'Firebird_Result');
2012-03-15 09:25:18 -04:00
}
function TestOrWhere()
{
$query = $this->db->select('id, key as k, val')
->from('create_test')
->where(' id ', 1)
->or_where('key >', 0)
->limit(2, 1)
->get();
$this->assertIsA($query, 'Firebird_Result');
2012-03-15 09:25:18 -04:00
}
2012-03-19 13:38:49 -04:00
function TestGroupBy()
{
}
2012-03-15 09:25:18 -04:00
/*function TestGroupBy()
{
$query = $this->db->select('id, key as k, val')
->from('create_test')
->where('id >', 0)
->where('id <', 9000)
->group_by('k')
->group_by('val')
->order_by('id', 'DESC')
->order_by('k', 'ASC')
->limit(5,2)
->get();
$this->assertIsA($query, 'Firebird_Result');
2012-03-15 09:25:18 -04:00
}*/
function TestLike()
{
$query = $this->db->from('create_test')
->like('key', 'og')
->get();
$this->assertIsA($query, 'Firebird_Result');
2012-03-15 09:25:18 -04:00
}
function TestWhereIn()
{
$query = $this->db->from('create_test')
->where_in('key', array(12, 96, "works"))
->get();
$this->assertIsA($query, 'Firebird_Result');
2012-03-15 09:25:18 -04:00
}
function TestJoin()
{
$query = $this->db->from('create_test')
->join('create_join cj', 'cj.id = create_test.id')
->get();
$this->assertIsA($query, 'Firebird_Result');
2012-03-15 09:25:18 -04:00
}
function TestInsert()
{
$query = $this->db->set('id', 4)
->set('key', 4)
->set('val', 5)
->insert('create_test');
$this->assertTrue($query);
}
function TestUpdate()
{
$query = $this->db->set('id', 4)
->set('key', 'gogle')
->set('val', 'non-word')
->where('id', 4)
->update('create_test');
$this->assertTrue($query);
}
function TestDelete()
{
$query = $this->db->where('id', 4)->delete('create_test');
$this->assertTrue($query);
}
}