public function testGetIndexes() { $table = new MingoTable('tablename'); $table->setIndex('index1', array('one', 'two')); $index_list = $table->getIndexes(); $this->assertEquals(1, count($index_list)); $table->setIndex('index2', array('two', 'three')); $index_list = $table->getIndexes(); $this->assertEquals(2, count($index_list)); }
protected function getTable($name = '') { if (empty($name)) { $name = get_class($this); } //if $table = new MingoTable($name); $table->setIndex('foobarbaz', array('foo', 'bar', 'baz')); $table->setField('foo', MingoField::TYPE_INT); $table->setIndex('barbaz', array('bar', 'baz')); return $table; }
/** * assure right index is queried * * with 2 similar indexes using SQLite (and I assume MySQL) the interface's * index table selector would mess up because it would choose the first table * since the where would match and the sort was never taken into account, so a * PDOException would be thrown: * * PDOException: SQLSTATE[HY000]: General error: 1 no such column: che * * this test is here to make sure that is fixed * * @since 9-2-11 */ public function testSimilarIndexes() { $db = $this->getDb(); // create a more advanced table... $table = new MingoTable(__FUNCTION__); $table->setField('foo', MingoField::TYPE_STR); $table->setField('bar', MingoField::TYPE_STR); $table->setField('che', MingoField::TYPE_STR); // create 2 similar indexes... $table->setIndex('foo_and_bar', array('foo', 'bar')); $table->setIndex('foo_and_che', array('foo', 'che')); // make sure the table exists in the db $this->setTable($table); // now try and query the second index... $where_criteria = new MingoCriteria(); $where_criteria->isFoo(__FUNCTION__); $where_criteria->descChe(); // no errors should be thrown... $list = $db->get($table, $where_criteria); $this->assertEmpty($list); }