Add method to get indexes for the current table

This commit is contained in:
Timothy Warren 2014-04-08 14:26:28 -04:00
parent 9011678dc3
commit d06a3eda0d
9 changed files with 54 additions and 24 deletions

View File

@ -419,6 +419,19 @@ abstract class Abstract_Driver extends \PDO implements Driver_Interface {
// --------------------------------------------------------------------------
/**
* Retrieve indexes for the table
*
* @param string $table
* @return array
*/
public function get_indexes($table)
{
return $this->driver_query($this->sql->index_list($table), FALSE);
}
// --------------------------------------------------------------------------
/**
* Retrieve list of data types for the database
*

View File

@ -47,7 +47,8 @@ abstract class Abstract_Table {
*/
public function set_options(Array $options)
{
$type = end(explode('_', get_class($this)));
$class_segments = explode('_', get_class($this));
$type = end($class_segments);
foreach($options as $option => $value)
{

View File

@ -127,9 +127,17 @@ interface SQL_Interface {
* table
*
* @parma string $table
* @return string
* @return array
*/
public function fk_list($table);
/**
* Get the list of indexes for the current table
*
* @param string $table
* @return array
*/
public function index_list($table);
}
// End of sql_interface.php

View File

@ -43,15 +43,7 @@ abstract class DBTest extends Query_TestCase {
$this->assertTrue(is_array($tables));
}
// --------------------------------------------------------------------------
public function testCreateTransaction()
{
$res = $this->db->beginTransaction();
$this->assertTrue($res);
}
// --------------------------------------------------------------------------
public function testBackupData()
@ -83,5 +75,13 @@ abstract class DBTest extends Query_TestCase {
$this->assertTrue(is_array($keys));
}
// --------------------------------------------------------------------------
public function testGetIndexes()
{
$keys = $this->db->get_indexes('test');
$this->assertTrue(is_array($keys));
}
}
// End of db_test.php

View File

@ -140,7 +140,11 @@ class FirebirdQBTest extends QBTest {
public function testBackupStructure()
{
$this->assertEquals('', $this->db->util->backup_structure());
$existing = QTEST_DIR.QDS.'db_files'.QDS.'FB_TEST_DB.FDB';
$backup = QTEST_DIR.QDS.'db_files'.QDS.'FB_TEST_BKP.FDB';
$this->assertTrue($this->db->util->backup_structure($existing, $backup));
}
// --------------------------------------------------------------------------

View File

@ -109,6 +109,7 @@ class FirebirdTest extends DBtest {
public function testCreateTable()
{
//Attempt to create the table
$sql = $this->db->util->create_table('create_delete', array(
'id' => 'SMALLINT',
@ -314,4 +315,9 @@ SQL;
{
$this->assertFalse($this->db->setAttribute(47, 'foo'));
}
public function testLastInsertId()
{
$this->assertEqual(0, $this->db->lastInsertId('NEWTABLE_SEQ'));
}
}

View File

@ -62,10 +62,19 @@ class PgTest extends DBTest {
// --------------------------------------------------------------------------
public function DataCreate()
{
$this->db->exec(file_get_contents(QTEST_DIR.'/db_files/pgsql.sql'));
}
// --------------------------------------------------------------------------
public function testCreateTable()
{
if (empty($this->db)) return;
$this->DataCreate();
// Drop the table(s) if they exist
$sql = 'DROP TABLE IF EXISTS "create_test"';
$this->db->query($sql);

View File

@ -224,7 +224,7 @@ SQL;
public function testGetDBs()
{
$this->assertNull($this->db->get_dbs());
$this->assertTrue(is_array($this->db->get_dbs()));
}
// --------------------------------------------------------------------------
@ -261,16 +261,5 @@ SQL;
$sql = $this->db->sql->sequence_list();
$this->assertEqual(NULL, $sql);
$sql = $this->db->sql->fk_list('create_test');
$this->assertEqual(NULL, $sql);
}
// --------------------------------------------------------------------------
public function testGetFKs()
{
$keys = $this->db->get_fks('create_test');
$this->assertNull($keys);
}
}

Binary file not shown.