abstract public function tables($name = null);
/**
+ * Return a table's primary key
+ */
+ abstract public function primaryKey($tableName, $name = null);
+
+ /**
* Returns an array of indexes for the given table.
*
* @param string $tableName
}
/**
+ * Return a table's primary key
+ */
+ public function primaryKey($tableName, $name = null)
+ {
+ // Share the column cache with the columns() method
+ $rows = @unserialize($this->_cache->get("tables/columns/$tableName"));
+
+ if (!$rows) {
+ $rows = $this->selectAll('SHOW FIELDS FROM ' . $this->quoteTableName($tableName), $name);
+
+ $this->_cache->set("tables/columns/$tableName", serialize($rows));
+ }
+
+ $pk = $this->componentFactory('Index', array($tableName, 'PRIMARY', true, true, array()));
+ foreach ($rows as $row) {
+ if ($row['Key'] == 'PRI') {
+ $pk->columns[] = $row['Field'];
+ }
+ }
+
+ return $pk;
+ }
+
+ /**
* List of indexes for the given table
*
* @param string $tableName
}
/**
+ * Return a table's primary key
+ */
+ public function primaryKey($tableName, $name = null)
+ {
+ list($defaultPk, ) = $this->pkAndSequenceFor($tableName);
+ return $this->componentFactory('Index', array($tableName, 'PRIMARY', true, true, array($defaultPk)));
+ }
+
+ /**
* Returns the list of all indexes for a table.
*/
public function indexes($tableName, $name = null)
}
/**
+ * Return a table's primary key
+ */
+ public function primaryKey($tableName, $name = null)
+ {
+ // Share the columns cache with the columns() method
+ $rows = @unserialize($this->_cache->get("tables/columns/$tableName"));
+
+ if (!$rows) {
+ $rows = $this->selectAll('PRAGMA table_info(' . $this->quoteTableName($tableName) . ')', $name);
+
+ $this->_cache->set("tables/columns/$tableName", serialize($rows));
+ }
+
+ $pk = $this->componentFactory('Index', array($tableName, 'PRIMARY', true, true, array()));
+ foreach ($rows as $row) {
+ if ($row['pk'] == 1) {
+ $pk->columns[] = $row['name'];
+ }
+ }
+
+ return $pk;
+ }
+
+ /**
* List of indexes for the given table
*
* @param string $tableName
$this->assertContains('unit_tests', $tables);
}
+ public function testPrimaryKey()
+ {
+ $pk = $this->_conn->primaryKey('unit_tests');
+ $this->assertEquals('id', (string)$pk);
+ $this->assertEquals(1, count($pk->columns));
+ $this->assertEquals('id', $pk->columns[0]);
+ }
+
public function testIndexes()
{
$indexes = $this->_conn->indexes('unit_tests');
$this->assertContains('unit_tests', $tables);
}
+ public function testPrimaryKey()
+ {
+ $pk = $this->_conn->primaryKey('unit_tests');
+ $this->assertEquals('id', (string)$pk);
+ $this->assertEquals(1, count($pk->columns));
+ $this->assertEquals('id', $pk->columns[0]);
+ }
+
public function testIndexes()
{
$indexes = $this->_conn->indexes('unit_tests');
$this->assertContains('unit_tests', $tables);
}
+ public function testPrimaryKey()
+ {
+ $pk = $this->_conn->primaryKey('unit_tests');
+ $this->assertEquals('id', (string)$pk);
+ $this->assertEquals(1, count($pk->columns));
+ $this->assertEquals('id', $pk->columns[0]);
+ }
+
public function testIndexes()
{
$indexes = $this->_conn->indexes('unit_tests');
$this->assertContains('unit_tests', $tables);
}
+ public function testPrimaryKey()
+ {
+ $pk = $this->_conn->primaryKey('unit_tests');
+ $this->assertEquals('id', (string)$pk);
+ $this->assertEquals(1, count($pk->columns));
+ $this->assertEquals('id', $pk->columns[0]);
+ }
+
public function testIndexes()
{
$indexes = $this->_conn->indexes('unit_tests');