-- This is a modification of http://www.tehtri-security.com/tehtris-iphone-privacy.sql by singe.za.net

-- Don't delete built in triggers, especially as they just seem to increment/decrement & delete 
--drop trigger CdmaCellLocationHarvestIncrementRowCount;
--drop trigger CdmaCellLocationHarvestDecrementRowCount;
--drop trigger CdmaCellLocationLocalIncrementRowCount;
--drop trigger CdmaCellLocationLocalDecrementRowCount;
--drop trigger CdmaCellLocationLocalDeleteBoundingBoxes;
--drop trigger CdmaCellLocationIncrementRowCount;
--drop trigger CdmaCellLocationDecrementRowCount;
--drop trigger CdmaCellLocationDeleteBoundingBoxes;
--drop trigger CellLocationHarvestIncrementRowCount;
--drop trigger CellLocationHarvestDecrementRowCount;
--drop trigger WifiLocationHarvestIncrementRowCount;
--drop trigger WifiLocationHarvestDecrementRowCount;
--drop trigger LocationHarvestIncrementRowCount;
--drop trigger LocationHarvestDecrementRowCount;
--drop trigger CellLocationIncrementRowCount;
--drop trigger CellLocationDecrementRowCount;
--drop trigger CellLocationDeleteBoundingBoxes;
--drop trigger CellLocationLocalIncrementRowCount;
--drop trigger CellLocationLocalDecrementRowCount;
--drop trigger CellLocationLocalDeleteBoundingBoxes;

-- Initialise Database to a clear version
delete from TableInfo; --This table appeats to have useful things, don't delete it
INSERT INTO TableInfo (TableName,SoftwareVersion,SerialNumber) VALUES ('CdmaCellLocationHarvest','1079.25','<your serial number here>');
INSERT INTO TableInfo (TableName,SoftwareVersion,SerialNumber) VALUES ('CdmaCellLocationLocal','1079.25','<your serial number here>');
INSERT INTO TableInfo (TableName,SoftwareVersion,SerialNumber) VALUES ('CdmaCellLocationLocalBoxes','1079.25','<your serial number here>');
INSERT INTO TableInfo (TableName,SoftwareVersion,SerialNumber) VALUES ('CdmaCellLocation','1079.25','<your serial number here>');
INSERT INTO TableInfo (TableName,SoftwareVersion,SerialNumber) VALUES ('CdmaCellLocationBoxes','1079.25','<your serial number here>');
INSERT INTO TableInfo (TableName,SoftwareVersion,SerialNumber) VALUES ('Fences','1079.25','<your serial number here>');
INSERT INTO TableInfo (TableName,SoftwareVersion,SerialNumber) VALUES ('CompassCalibration','1079.25','<your serial number here>');
INSERT INTO TableInfo (TableName,SoftwareVersion,SerialNumber) VALUES ('Location','1079.25','<your serial number here>');
INSERT INTO TableInfo (TableName,SoftwareVersion,SerialNumber) VALUES ('Wifi','1079.25','<your serial number here>');
INSERT INTO TableInfo (TableName,SoftwareVersion,SerialNumber) VALUES ('Cell','1079.25','<your serial number here>');
INSERT INTO TableInfo (TableName,SoftwareVersion,SerialNumber) VALUES ('CellLocationHarvest','1079.25','<your serial number here>');
INSERT INTO TableInfo (TableName,SoftwareVersion,SerialNumber) VALUES ('WifiLocationHarvest','1079.25','<your serial number here>');
INSERT INTO TableInfo (TableName,SoftwareVersion,SerialNumber) VALUES ('LocationHarvest','1079.25','<your serial number here>');
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; -- This will save you having to recalibrate your compass
delete from CompassCalibration where TimeStamp NOT IN (SELECT MAX(TimeStamp) FROM CompassCalibration);
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; -- not in my stub
delete from CellLocationCounts; -- not in my stub
insert into CellLocationCounts values (0); -- default on reset
delete from CellLocationBoxes_node; -- not in my stub
insert into CellLocationBoxes_node values (1,""); -- default on reset
delete from CellLocationBoxes_rowid; -- not in my stub
delete from CellLocationBoxes_parent; -- not in my stub
delete from CellLocationLocal; -- not in my stub
delete from CellLocationLocalCounts; -- not in my stub
insert into CellLocationLocalCounts values (0); -- default on reset
delete from CellLocationLocalBoxes_node; -- not in my stub
insert into CellLocationLocalBoxes_node values (1,""); -- default on reset
delete from CellLocationLocalBoxes_rowid; -- not in my stub
delete from CellLocationLocalBoxes_parent; -- not in my stub

-- Create Triggers
--create trigger privacy_in_TableInfo after insert on TableInfo begin delete from TableInfo; end; -- doesn't have private info
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_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;
