summaryrefslogtreecommitdiff
path: root/tests/unit/SQLMap/TAdodbConnectionTestCase.php
blob: df912c1b7f2ed0835dca23a673d6cbaef8d83fbe (plain)
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
<?php

require_once(SQLMAP_DIR.'/TMapper.php');

/**
 * @package System.DataAccess
 */
class TAdodbConnectionTestCase extends UnitTestCase
{
	protected $db_file;

	function setup()
	{
		$file = dirname(__FILE__).'/resources/data.db';
		$this->db_file = dirname(__FILE__).'/resources/test.db';
		copy($file,$this->db_file);
		$provider = new TAdodbProvider();
		$provider->importAdodbLibrary();
	}

	function getDsn()
	{
		return 'sqlite://'.urlencode(realpath($this->db_file));
	}

	function testProviderCreation()
	{
		$provider = new TAdodbProvider();
		$connection = $provider->getConnection();
		$this->assertTrue($connection instanceof TAdodbConnection);
		try
		{
			$connection->open();
			$this->fail();
		}
		catch (TDbConnectionException $e)
		{
			$this->pass();
		}
	}



	function testAdodbSqliteConnection()
	{
		$connection = new TAdodbConnection($this->getDsn());
		$this->assertTrue($connection->open());
	
		$statement = "insert into person(per_id, per_first_name,
			per_last_name, per_birth_date, per_weight_kg, per_height_m)
			values(?, ?, ?, ?, ?, ?)";
		$sql = $connection->prepare($statement);
		$connection->execute($sql, 
					array(2,'mini','me','2000-01-01', 50.5, 145.5));

		$statement = "select * from person";
		$results = $connection->execute($statement);
		$this->assertEquals($results->RecordCount(), 2);
	
	}
}

?>