/** * Delete any existing settings from the database. Done inside a transaction * while saving new settings. * * @return void */ public function deleteCurrentSettings() { $this->dbAdapter->delete('dewdrop_field_groups', $this->dbAdapter->quoteInto('dewdrop_field_group_id IN ( SELECT dewdrop_field_group_id FROM dewdrop_sorted_fields WHERE component = ? )', $this->componentName)); $this->dbAdapter->delete('dewdrop_sorted_fields', $this->dbAdapter->quoteInto('component = ?', $this->componentName)); }
/** * While saving, delete existing values. If the new values will be limited to the * logged-in user, we only delete any settings specific to that user. Otherwise, * we also delete any current values not specific to a user. * * @param boolean $applyToAllUsers */ protected function deleteExistingValuesForSave($applyToAllUsers) { $where = $this->dbAdapter->quoteInto('component = ?', $this->componentName); $references = $this->getUserReferenceValues(); // We always delete per-user settings foreach ($references as $column => $value) { $where .= $this->dbAdapter->quoteInto(sprintf(' AND %s = ?', $this->dbAdapter->quoteIdentifier($column)), $value); } $this->dbAdapter->delete($this->dbTableName, $where); // If applying settings to all users, we _also_ delete the current global settings if ($applyToAllUsers) { $where = $this->dbAdapter->quoteInto('component = ?', $this->componentName); foreach ($references as $column => $value) { $where .= sprintf(' AND %s IS NULL', $this->dbAdapter->quoteIdentifier($column)); } $this->dbAdapter->delete($this->dbTableName, $where); } }
public function testDelete() { $table = 'dewdrop_test_fruits'; $idField = 'dewdrop_test_fruit_id'; $fetchAllSql = "SELECT * FROM {$table} ORDER BY {$idField}"; $fruits = $this->db->fetchAll($fetchAllSql); $this->assertSame(5, count($fruits)); $this->assertEquals(1, $fruits[0][$idField]); $this->assertSame(1, $this->db->delete($table, "{$idField} = 1")); $fruits = $this->db->fetchAll($fetchAllSql); $this->assertSame(4, count($fruits)); $this->assertEquals(2, $fruits[0][$idField]); $this->assertSame(0, $this->db->delete($table, "{$idField} = 7")); $fruits = $this->db->fetchAll($fetchAllSql); $this->assertSame(4, count($fruits)); $this->assertEquals(2, $fruits[0][$idField]); $this->assertSame(1, $this->db->delete($table, array("{$idField} = 2", 'is_delicious'))); $fruits = $this->db->fetchAll($fetchAllSql); $this->assertSame(3, count($fruits)); $this->assertEquals(3, $fruits[0][$idField]); }
/** * Deletes existing rows. * * @param array|string $where SQL WHERE clause(s). * @return int The number of rows deleted. */ public function delete($where) { return $this->db->delete($this->tableName, $where); }