public function xtestSetup() { $db = $this->getDb(); $table = $this->getTable(__FUNCTION__); $_id_list = $this->addRows($db, $table, 5); ///$where_criteria = new MingoCriteria(); ///$where_criteria->ninFoo(1,2); ///$where_criteria->is_q('foo:(-1 -2)'); $list = $db->getQuery('foo NOT foo:(1 2)', array('table' => $table)); out::e($list); $this->assertEquals(3, count($list)); $this->assureSubset($list, $_id_list); return; $db = $this->getDb(); $table = $this->getTable(__FUNCTION__); ///$table = new MingoTable(__FUNCTION__); $_id_list = array(); for ($i = 0; $i < 5; $i++) { $map = array('foo' => $i); $map = $db->set($table, $map); $_id_list[] = (string) $map['_id']; } //for out::e($_id_list); $c = new MingoCriteria(); $c->in_id($_id_list); $list = $db->get($table, $c); out::e($list); $count = $db->getCount($table, $c); out::e($count); ///$db->getQuery('_id:(1z4ddb7b390b5b1759137267 OR 6z4ddb7b39119fc745281592)',array('table' => $table)); }
/** * make sure removing lots of rows using just the _ids works */ public function testKillLots2() { $db = $this->getDb(); $table = $this->getTable(); $foo = 44; $timestamp = time(); // now let's make sure _id deletion works also... $_id_list = array(); for ($i = 0; $i < 201; $i++) { $timestamp += 1; $map = array(); $map['foo'] = $foo; $map['bar'] = $timestamp; $map['baz'] = $timestamp; $ret_map = $db->set($table, $map); $_id_list[] = $ret_map['_id']; } //for */ $where_criteria = new MingoCriteria(); $where_criteria->in_id($_id_list); $db->kill($table, $where_criteria); $result = $db->getOne($table, $where_criteria); $this->assertEmpty($result); }
/** * @see kill() * @param mixed $table the table ran through {@link normalizeTable()} * @param mixed $where_criteria the where criteria ran through {@link normalizeCriteria()) * @return boolean */ protected function _kill($table, $where_criteria) { $ret_bool = false; if (empty($where_criteria['is_index'])) { // we aren't deleting on an index table, so we can just remove from the main // table which will cause the foreign keys to drop on all the index tables // build delete query... $query = sprintf('DELETE FROM %s', $where_criteria['table_str']); if (!empty($where_criteria['where_str'])) { $query .= ' ' . $where_criteria['where_str']; } //if if (!empty($where_criteria['limit_str'])) { $query .= ' ' . $where_criteria['limit_str']; } //if $ret_bool = $this->getQuery($query, $where_criteria['where_params']); } else { // we need to use the index table to get the _ids of the main table and delete the matching // rows on the main table, this will cause all the index tables to drop references to those // rows also $db = $this->getDb(); $limit = 500; // SQLite has a 500 variable IN (...) limit $offset = 0; // we don't ever have to increment this because we delete the rows as we pull them do { // query the index table to get just the _ids of the main table $where_criteria = $this->normalizeLimitCriteria($where_criteria, $limit, $offset); $query = $this->getSelectQuery($where_criteria); $_id_list = $this->getQuery($query, $where_criteria['where_params']); if (!empty($_id_list)) { // now use the _ids to build a criteria that will select on the main table and // delete the main table rows $c = new MingoCriteria(); $c->in_id($_id_list); $ret_bool = $this->kill($table, $c); } //if } while (count($_id_list) >= $limit); } //if/else return $ret_bool; }