-- This file will blank your iPhone's consolidated.db file and install a set of triggers that will keep it blanked
-- A modification of the original at http://www.tehtri-security.com/tehtris-iphone-privacy.sql
-- By singe - consolidateddb@singe.za.net

-- Initialise Database to a clear version
delete from CdmaCellLocationHarvest;
delete from CdmaCellLocationHarvestCounts;
insert into CdmaCellLocationHarvestCounts values (0); -- default on reset
delete from CdmaCellLocationLocal;
delete from CdmaCellLocationLocalCounts;
insert into CdmaCellLocationLocalCounts values (0); -- default on reset
delete from CdmaCellLocationLocalBoxes_node;
insert into CdmaCellLocationLocalBoxes_node values (1,""); -- default on reset
delete from CdmaCellLocationLocalBoxes_rowid;
delete from CdmaCellLocationLocalBoxes_parent;
delete from CdmaCellLocation;
delete from CdmaCellLocationCounts;
insert into CdmaCellLocationCounts values (0); -- default on reset
delete from CdmaCellLocationBoxes_node;
insert into CdmaCellLocationBoxes_node values (1,""); -- default on reset
delete from CdmaCellLocationBoxes_rowid;
delete from CdmaCellLocationBoxes_parent;
delete from Fences;
delete from CompassCalibration where TimeStamp NOT IN (SELECT MAX(TimeStamp) FROM CompassCalibration); -- keep the last entry, prevent needless compass recalibration
delete from CompassSettings;
delete from Location;
delete from Wifi;
delete from Cell;
delete from CellLocationHarvest;
delete from CellLocationHarvestCounts;
insert into CellLocationHarvestCounts values (0); -- default on reset
delete from WifiLocation;
delete from WifiLocationCounts;
insert into WifiLocationCounts values (0); -- default on reset
delete from WifiLocationHarvest;
delete from WifiLocationHarvestCounts;
insert into WifiLocationHarvestCounts values (0); -- default on reset
delete from LocationHarvest;
delete from LocationHarvestCounts;
insert into LocationHarvestCounts values (0); -- default on reset
delete from CellLocation;
delete from CellLocationCounts;
insert into CellLocationCounts values (0); -- default on reset
delete from CellLocationBoxes;
delete from CellLocationBoxes_node;
insert into CellLocationBoxes_node values (1,""); -- default on reset
delete from CellLocationBoxes_rowid;
delete from CellLocationBoxes_parent;
delete from CellLocationLocal;
delete from CellLocationLocalCounts;
insert into CellLocationLocalCounts values (0); -- default on reset
delete from CellLocationLocalBoxes_node;
insert into CellLocationLocalBoxes_node values (1,""); -- default on reset
delete from CellLocationLocalBoxes_rowid;
delete from CellLocationLocalBoxes_parent;

-- Create Triggers, mirror of above, in trigger form
create trigger privacy_in_CdmaCellLocationHarvest after insert on CdmaCellLocationHarvest begin delete from CdmaCellLocationHarvest; end;
create trigger privacy_in_CdmaCellLocationHarvestCounts after insert on CdmaCellLocationHarvestCounts begin delete from CdmaCellLocationHarvestCounts; insert into CdmaCellLocationHarvestCounts values (0); end;
create trigger privacy_in_CdmaCellLocationLocal after insert on CdmaCellLocationLocal begin delete from CdmaCellLocationLocal; end;
create trigger privacy_in_CdmaCellLocationLocalCounts after insert on CdmaCellLocationLocalCounts begin delete from CdmaCellLocationLocalCounts; insert into CdmaCellLocationLocalCounts values (0); end;
create trigger privacy_in_CdmaCellLocationLocalBoxes_node after insert on CdmaCellLocationLocalBoxes_node begin delete from CdmaCellLocationLocalBoxes_node; insert into CdmaCellLocationLocalBoxes_node values (1,""); end;
create trigger privacy_in_CdmaCellLocationLocalBoxes_rowid after insert on CdmaCellLocationLocalBoxes_rowid begin delete from CdmaCellLocationLocalBoxes_rowid; end;
create trigger privacy_in_CdmaCellLocationLocalBoxes_parent after insert on CdmaCellLocationLocalBoxes_parent begin delete from CdmaCellLocationLocalBoxes_parent; end;
create trigger privacy_in_CdmaCellLocation after insert on CdmaCellLocation begin delete from CdmaCellLocation; end;
create trigger privacy_in_CdmaCellLocationCounts after insert on CdmaCellLocationCounts begin delete from CdmaCellLocationCounts; insert into CdmaCellLocationCounts values (0); end;
create trigger privacy_in_CdmaCellLocationBoxes_node after insert on CdmaCellLocationBoxes_node begin delete from CdmaCellLocationBoxes_node; insert into CdmaCellLocationBoxes_node values (1,""); end;
create trigger privacy_in_CdmaCellLocationBoxes_rowid after insert on CdmaCellLocationBoxes_rowid begin delete from CdmaCellLocationBoxes_rowid; end;
create trigger privacy_in_CdmaCellLocationBoxes_parent after insert on CdmaCellLocationBoxes_parent begin delete from CdmaCellLocationBoxes_parent; end;
create trigger privacy_in_Fences after insert on Fences begin delete from Fences; end;
create trigger privacy_in_CompassCalibration after insert on CompassCalibration begin DELETE FROM CompassCalibration WHERE TimeStamp NOT IN (SELECT MAX(TimeStamp) FROM CompassCalibration); end; -- don't delete the last calibration
create trigger privacy_in_CompassSettings after insert on CompassSettings begin delete from CompassSettings; end;
create trigger privacy_in_Location after insert on Location begin delete from Location; end;
create trigger privacy_in_Wifi after insert on Wifi begin delete from Wifi; end;
create trigger privacy_in_Cell after insert on Cell begin delete from Cell; end;
create trigger privacy_in_CellLocationHarvest after insert on CellLocationHarvest begin delete from CellLocationHarvest; end;
create trigger privacy_in_CellLocationHarvestCounts after insert on CellLocationHarvestCounts begin delete from CellLocationHarvestCounts; insert into CellLocationHarvestCounts values (0); end;
create trigger privacy_in_WifiLocation after insert on WifiLocation begin delete from WifiLocation; end;
create trigger privacy_in_WifiLocationCounts after insert on WifiLocationCounts begin delete from WifiLocationCounts; insert into WifiLocationCounts values (0); end;
create trigger privacy_in_WifiLocationHarvest after insert on WifiLocationHarvest begin delete from WifiLocationHarvest; end;
create trigger privacy_in_WifiLocationHarvestCounts after insert on WifiLocationHarvestCounts begin delete from WifiLocationHarvestCounts; insert into WifiLocationHarvestCounts values (0); end;
create trigger privacy_in_LocationHarvest after insert on LocationHarvest begin delete from LocationHarvest; end;
create trigger privacy_in_LocationHarvestCounts after insert on LocationHarvestCounts begin delete from LocationHarvestCounts; insert into LocationHarvestCounts values (0); end;
create trigger privacy_in_CellLocation after insert on CellLocation begin delete from CellLocation; end;
--create trigger privacy_in_CellLocationBoxes after insert on CellLocationBoxes begin delete from CellLocationBoxes; end; -- virtual table
create trigger privacy_in_CellLocationCounts after insert on CellLocationCounts begin delete from CellLocationCounts; insert into CellLocationCounts values (0); end;
create trigger privacy_in_CellLocationBoxes_node after insert on CellLocationBoxes_node begin delete from CellLocationBoxes_node; insert into CellLocationBoxes_node values (1,""); end;
create trigger privacy_in_CellLocationBoxes_rowid after insert on CellLocationBoxes_rowid begin delete from CellLocationBoxes_rowid; end;
create trigger privacy_in_CellLocationBoxes_parent after insert on CellLocationBoxes_parent begin delete from CellLocationBoxes_parent; end;
create trigger privacy_in_CellLocationLocal after insert on CellLocationLocal begin delete from CellLocationLocal; end;
create trigger privacy_in_CellLocationLocalCounts after insert on CellLocationLocalCounts begin delete from CellLocationLocalCounts; insert into CellLocationLocalCounts values (0); end;
create trigger privacy_in_CellLocationLocalBoxes_node after insert on CellLocationLocalBoxes_node begin delete from CellLocationLocalBoxes_node; insert into CellLocationLocalBoxes_node values (1,""); end;
create trigger privacy_in_CellLocationLocalBoxes_rowid after insert on CellLocationLocalBoxes_rowid begin delete from CellLocationLocalBoxes_rowid; end;
create trigger privacy_in_CellLocationLocalBoxes_parent after insert on CellLocationLocalBoxes_parent begin delete from CellLocationLocalBoxes_parent; end;

vacuum; --actually delete the data from the file
