-- Table structure for table `relationalgorithms`
--

CREATE TABLE `relationalgorithms` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `AlgorithmID` int(11) NOT NULL DEFAULT '0',
  `SensorID` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`ID`),
  UNIQUE KEY `ID` (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `relationalgorithms`
--

INSERT INTO `relationalgorithms` VALUES (1,4,2),(2,4,3),(3,5,4),(4,5,5),(5,4,6),(6,4,7),(7,4,8),(8,5,9),(9,7,10),(10,4,11),(11,27,12),(12,6,13),(13,5,14),(14,6,15),(15,6,16),(16,6,17),(17,2,18),(19,4,20),(20,8,21),(21,27,22),(22,5,23),(23,6,24),(24,6,25),(25,6,26),(26,2,27),(27,4,28),(28,5,29),(29,5,30),(30,5,31);

--
-- Table structure for table `report_pass_zones`
--

CREATE TABLE `report_pass_zones` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `ZoneID` int(11) NOT NULL COMMENT 'Идентификатор КЗ',
  PRIMARY KEY (`ID`),
  KEY `IDX_ZoneID` (`ZoneID`) USING BTREE,
  CONSTRAINT `FK_RPZ_Zones` FOREIGN KEY (`ZoneID`) REFERENCES `zones` (`Zone_ID`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=cp1251 COMMENT='Список зон, используемый в отчетах по пассажиропотоку.';

--
-- Dumping data for table `report_pass_zones`
--


--
-- Table structure for table `route_items`
--

CREATE TABLE `route_items` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `Seq` int(11) DEFAULT NULL,
  `Route_ID` int(11) DEFAULT NULL,
  `Zone_ID` int(11) DEFAULT NULL,
  `Zone_IO` int(11) DEFAULT NULL,
  `GoNext_Min` int(11) DEFAULT NULL,
  `GoNext_Max` int(11) DEFAULT NULL,
  `Link_Item` int(11) DEFAULT NULL,
  `Link_Info` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `route_items`
--


--
-- Table structure for table `route_list`
--

CREATE TABLE `route_list` (
  `Route_ID` int(11) NOT NULL AUTO_INCREMENT,
  `GIS` blob,
  `Name` varchar(50) DEFAULT NULL,
  `Descr` varchar(200) DEFAULT NULL,
  `Modified` int(11) DEFAULT NULL,
  PRIMARY KEY (`Route_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `route_list`
--


--
-- Table structure for table `route_lists`
--

CREATE TABLE `route_lists` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `Parent` int(11) DEFAULT NULL,
  `Title` varchar(70) DEFAULT NULL,
  `Data` text,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `route_lists`
--


--
-- Table structure for table `route_mobitel_links`
--

CREATE TABLE `route_mobitel_links` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `List_ID` int(11) DEFAULT NULL,
  `Route_ID` int(11) DEFAULT NULL,
  `Mobitel_ID` int(11) DEFAULT NULL,
  `Time1` int(11) DEFAULT NULL,
  `Time2` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `route_mobitel_links`
--


--
-- Table structure for table `route_mobitel_plans`
--

CREATE TABLE `route_mobitel_plans` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `Title` varchar(70) DEFAULT NULL,
  `Time1` int(11) DEFAULT NULL,
  `Time2` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `route_mobitel_plans`
--


--
-- Table structure for table `route_points`
--

CREATE TABLE `route_points` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `Route_ID` int(11) DEFAULT NULL,
  `Zone_ID` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `route_points`
--


--
-- Table structure for table `rt_events`
--

CREATE TABLE `rt_events` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Name` varchar(50) NOT NULL,
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `rt_events`
--

INSERT INTO `rt_events` VALUES (1,'Въезд'),(2,'Выезд');

--
-- Table structure for table `rt_route`
--

CREATE TABLE `rt_route` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Id_sample` int(11) NOT NULL COMMENT 'Ссылка на шаблон маршрута ',
  `Id_mobitel` int(11) NOT NULL DEFAULT '0' COMMENT 'Транспортное средство ',
  `Id_driver` int(11) NOT NULL DEFAULT '0' COMMENT 'Водитель',
  `TimeStartPlan` datetime DEFAULT NULL COMMENT 'План время начала маршрута',
  `Distance` double NOT NULL DEFAULT '0' COMMENT 'Общий путь, км',
  `TimePlanTotal` varchar(20) DEFAULT NULL COMMENT 'Общее время на маршруте (план)',
  `TimeFactTotal` varchar(20) DEFAULT NULL COMMENT 'Общее время на маршруте (факт)',
  `Deviation` varchar(20) DEFAULT NULL COMMENT 'Отклонение от графика',
  `DeviationAr` varchar(20) DEFAULT NULL COMMENT 'Отклонение по времени прибытия',
  `Remark` text COMMENT 'Примечание',
  `FuelStart` double(10,2) NOT NULL DEFAULT '0.00' COMMENT 'ДУТ Топливо в начале',
  `FuelAdd` double(10,2) NOT NULL DEFAULT '0.00' COMMENT 'ДУТ Заправлено',
  `FuelSub` double(10,2) NOT NULL DEFAULT '0.00' COMMENT 'ДУТ Слито',
  `FuelEnd` double(10,2) NOT NULL DEFAULT '0.00' COMMENT 'ДУТ Топливо в конце',
  `FuelExpens` double(10,2) NOT NULL DEFAULT '0.00' COMMENT 'ДУТ Общий расход топлива',
  `FuelExpensAvg` double(10,2) NOT NULL DEFAULT '0.00' COMMENT 'ДУТ Средний расход,  л/100 км',
  `Fuel_ExpensMove` double(10,2) NOT NULL DEFAULT '0.00' COMMENT 'ДРТ/CAN Расход топлива в движении, л',
  `Fuel_ExpensStop` double(10,2) NOT NULL DEFAULT '0.00' COMMENT 'ДРТ/CAN Расход топлива на стоянках, л',
  `Fuel_ExpensTotal` double(10,2) NOT NULL DEFAULT '0.00' COMMENT 'ДРТ/CAN Общий расход, л',
  `Fuel_ExpensAvg` double(10,2) NOT NULL DEFAULT '0.00' COMMENT 'ДРТ/CAN Средний расход, л/100 км',
  `TimeMove` varchar(20) DEFAULT NULL COMMENT 'Время движения',
  `TimeStop` varchar(20) DEFAULT NULL COMMENT 'Время остановок',
  `SpeedAvg` double(10,2) DEFAULT '0.00' COMMENT 'Средняя скорость',
  `FuelAddQty` int(11) DEFAULT '0' COMMENT 'ДУТ Заправлено - кол-во',
  `FuelSubQty` int(11) DEFAULT '0' COMMENT 'ДУТ Слито - кол-во',
  `PointsValidity` int(11) DEFAULT '0' COMMENT 'Валидность данных',
  `PointsCalc` int(11) DEFAULT '0' COMMENT 'Количество точек (по Log_ID) расчетное',
  `PointsFact` int(11) DEFAULT '0' COMMENT 'Количество точек (по Log_ID) фактическое',
  `PointsIntervalMax` varchar(20) DEFAULT NULL COMMENT 'Максимальный интервал между точками',
  `Type` tinyint(4) NOT NULL DEFAULT '1' COMMENT 'Тип маршрутного листа - КЗ или населенные пункты',
  `TimeEndFact` datetime DEFAULT NULL COMMENT 'Фактическое время окончания маршрута',
  `DistLogicSensor` double(10,2) DEFAULT '0.00' COMMENT 'Путь с включенным логическим датчиком, км',
  `OutLinkId` varchar(20) DEFAULT NULL COMMENT 'Код внешней базы',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `rt_route`
--


--
-- Table structure for table `rt_route_fuel`
--

CREATE TABLE `rt_route_fuel` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Id_main` int(11) NOT NULL,
  `Location` varchar(255) NOT NULL,
  `time_` datetime NOT NULL,
  `dValueCalc` double NOT NULL DEFAULT '0' COMMENT 'Расчетная величина',
  `dValueHandle` double DEFAULT '0' COMMENT 'Ручная правка',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `Id` (`Id`) USING BTREE,
  KEY `rt_route_fuel_FK1` (`Id_main`),
  CONSTRAINT `rt_route_fuel_FK1` FOREIGN KEY (`Id_main`) REFERENCES `rt_route` (`Id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `rt_route_fuel`
--


--
-- Table structure for table `rt_route_sensors`
--

CREATE TABLE `rt_route_sensors` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Id_main` int(11) NOT NULL,
  `SensorName` varchar(127) NOT NULL,
  `Location` varchar(255) NOT NULL,
  `EventTime` datetime NOT NULL,
  `Duration` time NOT NULL,
  `Description` varchar(255) DEFAULT NULL,
  `Speed` double DEFAULT '0',
  `Distance` double(10,2) DEFAULT '0.00' COMMENT 'Путь, км',
  PRIMARY KEY (`Id`),
  KEY `rt_route_sensors_FK1` (`Id_main`) USING BTREE,
  CONSTRAINT `rt_route_sensors_FK1` FOREIGN KEY (`Id_main`) REFERENCES `rt_route` (`Id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `rt_route_sensors`
--


--
-- Table structure for table `rt_route_stops`
--

CREATE TABLE `rt_route_stops` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Id_main` int(11) NOT NULL,
  `Location` varchar(255) DEFAULT NULL,
  `InitialTime` datetime DEFAULT NULL,
  `FinalTime` datetime DEFAULT NULL,
  `Interval` time DEFAULT NULL,
  `CheckZone` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Остановка в контрольной зоне',
  PRIMARY KEY (`Id`),
  KEY `rt_route_stops_FK1` (`Id_main`) USING BTREE,
  CONSTRAINT `rt_route_stops_FK1` FOREIGN KEY (`Id_main`) REFERENCES `rt_route` (`Id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `rt_route_stops`
--


--
-- Table structure for table `rt_route_type`
--

CREATE TABLE `rt_route_type` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Name` varchar(50) NOT NULL COMMENT 'Тип маршрута',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `rt_route_type`
--

INSERT INTO `rt_route_type` VALUES (1,'Контрольные зоны'),(2,'Населенные пункты');

--
-- Table structure for table `rt_routet`
--

CREATE TABLE `rt_routet` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Id_main` int(11) NOT NULL,
  `Id_zone` int(11) NOT NULL DEFAULT '0' COMMENT 'Контрольная зона',
  `Id_event` int(11) NOT NULL DEFAULT '1' COMMENT 'Событие - въезд / выезд ',
  `DatePlan` datetime DEFAULT NULL COMMENT 'План время события ',
  `DateFact` datetime DEFAULT NULL COMMENT 'Факт время события ',
  `Deviation` varchar(10) DEFAULT NULL COMMENT 'Отклонение от графика',
  `Remark` text COMMENT 'Примечание',
  `Distance` double DEFAULT '0' COMMENT 'Путь между точками маршрута',
  `Location` varchar(255) DEFAULT NULL COMMENT 'Населенный пункт',
  PRIMARY KEY (`Id`),
  KEY `rt_routet_FK1` (`Id_main`) USING BTREE,
  CONSTRAINT `rt_routet_FK1` FOREIGN KEY (`Id_main`) REFERENCES `rt_route` (`Id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `rt_routet`
--


--
-- Table structure for table `rt_sample`
--

CREATE TABLE `rt_sample` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Name` varchar(100) NOT NULL,
  `Id_mobitel` int(11) DEFAULT '0' COMMENT 'Транспортное средство (опц)',
  `TimeStart` time DEFAULT NULL COMMENT 'Время начала маршрута (опц)',
  `Distance` double DEFAULT '0' COMMENT 'Общий путь, км',
  `Remark` text COMMENT 'Примечание',
  `Id_main` int(11) NOT NULL DEFAULT '0' COMMENT 'Ссылка на элемент верхнего уровня в иерархии',
  `IsGroupe` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Запись - группа',
  `AutoCreate` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Маршрут может автосоздаваться ',
  `OutLinkId` varchar(20) DEFAULT NULL COMMENT 'Код внешней базы',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `rt_sample`
--


--
-- Table structure for table `rt_samplet`
--

CREATE TABLE `rt_samplet` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Id_main` int(11) NOT NULL,
  `Position` tinyint(4) NOT NULL COMMENT 'Порядковый номер записи шаблона маршрута',
  `Id_event` int(11) NOT NULL COMMENT 'Событие - въезд / выезд ',
  `Id_zone` int(11) DEFAULT NULL COMMENT 'Контрольная зона',
  `TimeRel` char(5) DEFAULT '00:00' COMMENT 'Относительное время от начала маршрута',
  `TimeRelP` char(5) DEFAULT '00:00' COMMENT 'Допустимое отклонение (+)',
  `TimeRelM` char(5) DEFAULT '00:00' COMMENT 'Допустимое отклонение (-)',
  `TimeAbs` char(8) DEFAULT '00:00:00' COMMENT 'Абсолютное время маршрута',
  PRIMARY KEY (`Id`),
  KEY `rt_samplet_FK1` (`Id_main`) USING BTREE,
  CONSTRAINT `rt_samplet_FK1` FOREIGN KEY (`Id_main`) REFERENCES `rt_sample` (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `rt_samplet`
--


--
-- Table structure for table `rt_shedule`
--

CREATE TABLE `rt_shedule` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Id_shedule_dc` int(11) DEFAULT NULL COMMENT 'Ссылка на справочник графиков',
  `Id_zone_main` int(11) DEFAULT NULL COMMENT 'Зона старта транспортных средств',
  `DateShedule` datetime NOT NULL COMMENT 'Дата графика',
  `Remark` varchar(127) DEFAULT NULL COMMENT 'Примечание',
  `OutLinkId` varchar(20) DEFAULT NULL COMMENT 'Ссылка на внешний документ учетной системы',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=cp1251 COMMENT='Шапка документа ГРАФИК ДВИЖЕНИЯ';

--
-- Dumping data for table `rt_shedule`
--


--
-- Table structure for table `rt_shedule_dc`
--

CREATE TABLE `rt_shedule_dc` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Name` varchar(127) NOT NULL COMMENT 'Название шаблона графика движения',
  `Id_zone_main` int(11) DEFAULT NULL COMMENT 'Зона старта транспортных средств',
  `Remark` varchar(127) DEFAULT NULL COMMENT 'Примечание',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=cp1251 COMMENT='Шаблон шапки документа ГРАФИК ДВИЖЕНИЯ';

--
-- Dumping data for table `rt_shedule_dc`
--


--
-- Table structure for table `rt_shedulet`
--

CREATE TABLE `rt_shedulet` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Id_main` int(11) NOT NULL COMMENT 'Ссылка на шапку документа',
  `Id_zone_to` int(11) DEFAULT NULL COMMENT 'Зона прибытия транспортного средства',
  `Id_vehicle` int(11) DEFAULT NULL COMMENT 'Транспортное средство',
  `TimePlanStart` datetime NOT NULL COMMENT 'Плановая дата начала движения',
  `TimePlanEnd` datetime DEFAULT NULL COMMENT 'Плановая дата окончания движения',
  `TimeFactStart` datetime DEFAULT NULL COMMENT 'Фактическая дата начала движения',
  `TimeFactEnd` datetime DEFAULT NULL COMMENT 'Фактическая дата окончания движения',
  `Distance` float NOT NULL DEFAULT '0' COMMENT 'Плановое расстояние',
  `State` varchar(127) DEFAULT NULL COMMENT 'Статус слежения за транспортным средством',
  `IsClose` bit(1) NOT NULL DEFAULT b'0' COMMENT 'Слежение за транспортным средством прекращено',
  PRIMARY KEY (`Id`),
  KEY `FK_rt_shedulet_rt_shedule` (`Id_main`) USING BTREE,
  CONSTRAINT `FK_rt_shedulet_rt_shedule` FOREIGN KEY (`Id_main`) REFERENCES `rt_shedule` (`Id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=cp1251 COMMENT='Содержимое документа ГРАФИК ДВИЖЕНИЯ';

--
-- Dumping data for table `rt_shedulet`
--


--
-- Table structure for table `rt_shedulet_dc`
--

CREATE TABLE `rt_shedulet_dc` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Id_main` int(11) NOT NULL COMMENT 'Ссылка на шапку документа',
  `Id_zone_to` int(11) DEFAULT NULL COMMENT 'Зона прибытия транспортного средства',
  `TimePlanStart` char(5) NOT NULL COMMENT 'Плановая дата начала движения',
  `TimePlanEnd` char(5) DEFAULT NULL COMMENT 'Плановая дата окончания движения',
  `Distance` float NOT NULL DEFAULT '0' COMMENT 'Плановое расстояние',
  PRIMARY KEY (`Id`),
  KEY `FK_rt_shedulet_rt_shedule` (`Id_main`) USING BTREE,
  CONSTRAINT `FK_rt_shedulet_dc_rt_shedule_dc` FOREIGN KEY (`Id_main`) REFERENCES `rt_shedule_dc` (`Id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=cp1251 COMMENT='Шаблон содержимого документа ГРАФИК ДВИЖЕНИЯ';

--
-- Dumping data for table `rt_shedulet_dc`
--


--
-- Table structure for table `rules`
--

CREATE TABLE `rules` (
  `Rule_ID` int(11) NOT NULL AUTO_INCREMENT,
  `Name` char(50) DEFAULT NULL,
  `Password` char(50) DEFAULT NULL,
  `Descr` char(200) DEFAULT NULL,
  `ID` int(11) NOT NULL DEFAULT '0',
  `Rule1` tinyint(4) NOT NULL DEFAULT '0',
  `Rule2` tinyint(4) NOT NULL DEFAULT '0',
  `Rule3` tinyint(4) NOT NULL DEFAULT '0',
  `Rule4` tinyint(4) NOT NULL DEFAULT '0',
  `Rule5` tinyint(4) NOT NULL DEFAULT '0',
  `Rule6` tinyint(4) NOT NULL DEFAULT '0',
  `Rule7` tinyint(4) NOT NULL DEFAULT '0',
  `Rule8` tinyint(4) NOT NULL DEFAULT '0',
  `Rule9` tinyint(4) NOT NULL DEFAULT '0',
  `Rule10` tinyint(4) NOT NULL DEFAULT '0',
  `Rule11` tinyint(4) NOT NULL DEFAULT '0',
  `Rule12` tinyint(4) NOT NULL DEFAULT '0',
  `Rule13` tinyint(4) NOT NULL DEFAULT '0',
  `Rule14` tinyint(4) NOT NULL DEFAULT '0',
  `Rule15` tinyint(4) NOT NULL DEFAULT '0',
  `Rule16` tinyint(4) NOT NULL DEFAULT '0',
  PRIMARY KEY (`Rule_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `rules`
--

INSERT INTO `rules` VALUES (1,'guest','guest','guest account',0,1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0),(8,'power','power','Description for Power User Profile',0,1,1,1,1,1,0,0,1,1,0,0,0,0,0,0,0),(9,'root','root','Description for root  Profile',0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0);

--
-- Table structure for table `sensor_hookups`
--

CREATE TABLE `sensor_hookups` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `Mobitel_ID` int(11) DEFAULT NULL,
  `Sensor_ID` int(11) DEFAULT NULL,
  `FirstBit` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `sensor_hookups`
--


--
-- Table structure for table `sensor_list`
--

CREATE TABLE `sensor_list` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `Title` varchar(70) DEFAULT NULL,
  `Kind` varchar(20) DEFAULT NULL,
  `BitsCount` int(11) DEFAULT NULL,
  `FirstBit` int(11) DEFAULT NULL,
  `Data` text,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `sensor_list`
--


--
-- Table structure for table `sensoralgorithms`
--

CREATE TABLE `sensoralgorithms` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `Name` char(45) NOT NULL,
  `Description` char(45) DEFAULT NULL,
  `AlgorithmID` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`ID`),
  UNIQUE KEY `ID` (`ID`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=32 DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `sensoralgorithms`
--

INSERT INTO `sensoralgorithms` VALUES (1,'Логический датчик','Для анализа используется критерий вкл. выкл.',1),(2,'Работа основного двигателя','Обычно используется при подключении к заж.',2),(3,'Обороты оборудования','Для анализа используются к-во оборотов',3),(4,'Напряжение','Контролируется борт сеть',4),(5,'Обороты основного двигателя','Для анализа используются к-во оборотов',5),(6,'Температура','Датчик температуры',6),(7,'Уровень топлива','Уровень топлива в баке1',7),(8,'Расход топлива','Уровень топлива в баке2',8),(9,'Пассажиры1','Для подсчета количества пассажиров1',9),(10,'Пассажиры2','Для подсчета количества пассажиров2',10),(11,'Дверь1','Для пассажиров1',11),(12,'Дверь2','Для пассажиров2',12),(13,'Идентификация водителя','Для идентификации водителей',13),(14,'Идентификация прицепного устройства','Для идентификации прицепных устройств',14),(15,'Топливозаправщик','Для контроля запровок с бензовоза',15),(16,'Слежение - логический датчик','Для отображения в режиме слежения',16),(17,'Прицепное оборудование - логический датчик','Для контроля состояний работа/переезд',17),(18,'Инклинометр - продольная ось X,','Для контроля угла наклона по оси Х',18),(19,'Инклинометр - продольная ось Y,','Для контроля угла наклона по оси Y',19),(20,'Идентификация оператора','Для идентификации водителя принявшего топливо',20),(21,'Идентификация транспортного средства','Для идентификации топливозаправщика',21),(22,'Угломерный датчик рабочего положения','Для идентификации агрегата в агро',22),(23,'Датчик разгрузки транспортного средства','Выгрузка бункера комбайна в агро',23),(24,'Расход топлива прямой','Расход топлива в баке прямой',24),(25,'Расход топлива обратный','Расход топлива в баке обратный',25),(26,'Дальномер','Дальномер',26),(27,'Расходомер топлива накопительный','Расходомер типа ДРТ, только накопительный',27),(28,'Определение уровня зерна в бункере','Алгоритм определения уровня зерна в бункере',28),(29,'Расход топлива дифференциальный','Дифференциальный проточник',29),(30,'Топливозаправщик (дифференциальный)','Топливозаправщик на дифф ДРТ',30),(31,'Уровень топлива в агрегате','Уровень топлива в баке агрегата',31);

--
-- Table structure for table `sensorcoefficient`
--

CREATE TABLE `sensorcoefficient` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `Sensor_id` int(10) unsigned NOT NULL,
  `UserValue` double(10,5) NOT NULL,
  `SensorValue` double(10,5) NOT NULL,
  `K` double(10,5) NOT NULL DEFAULT '1.00000',
  `b` double NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  UNIQUE KEY `Index_2` (`Sensor_id`,`UserValue`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=485 DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `sensorcoefficient`
--

INSERT INTO `sensorcoefficient` VALUES (1,16,-40.00000,0.00000,1.00000,-40),(2,16,-39.00000,1.00000,1.00000,-40),(3,16,-38.00000,2.00000,1.00000,-40),(4,16,-37.00000,3.00000,1.00000,-40),(5,16,-36.00000,4.00000,1.00000,-40),(6,16,-35.00000,5.00000,1.00000,-40),(7,16,-34.00000,6.00000,1.00000,-40),(8,16,-33.00000,7.00000,1.00000,-40),(9,16,-32.00000,8.00000,1.00000,-40),(10,16,-31.00000,9.00000,1.00000,-40),(11,16,-30.00000,10.00000,1.00000,-40),(12,16,-29.00000,11.00000,1.00000,-40),(13,16,-28.00000,12.00000,1.00000,-40),(14,16,-27.00000,13.00000,1.00000,-40),(15,16,-26.00000,14.00000,1.00000,-40),(16,16,-25.00000,15.00000,1.00000,-40),(17,16,-24.00000,16.00000,1.00000,-40),(18,16,-23.00000,17.00000,1.00000,-40),(19,16,-22.00000,18.00000,1.00000,-40),(20,16,-21.00000,19.00000,1.00000,-40),(21,16,-20.00000,20.00000,1.00000,-40),(22,16,-19.00000,21.00000,1.00000,-40),(23,16,-18.00000,22.00000,1.00000,-40),(24,16,-17.00000,23.00000,1.00000,-40),(25,16,-16.00000,24.00000,1.00000,-40),(26,16,-15.00000,25.00000,1.00000,-40),(27,16,-14.00000,26.00000,1.00000,-40),(28,16,-13.00000,27.00000,1.00000,-40),(29,16,-12.00000,28.00000,1.00000,-40),(30,16,-11.00000,29.00000,1.00000,-40),(31,16,-10.00000,30.00000,1.00000,-40),(32,16,-9.00000,31.00000,1.00000,-40),(33,16,-8.00000,32.00000,1.00000,-40),(34,16,-7.00000,33.00000,1.00000,-40),(35,16,-6.00000,34.00000,1.00000,-40),(36,16,-5.00000,35.00000,1.00000,-40),(37,16,-4.00000,36.00000,1.00000,-40),(38,16,-3.00000,37.00000,1.00000,-40),(39,16,-2.00000,38.00000,1.00000,-40),(40,16,-1.00000,39.00000,1.00000,-40),(41,16,0.00000,40.00000,1.00000,-40),(42,16,1.00000,41.00000,1.00000,-40),(43,16,2.00000,42.00000,1.00000,-40),(44,16,3.00000,43.00000,1.00000,-40),(45,16,4.00000,44.00000,1.00000,-40),(46,16,5.00000,45.00000,1.00000,-40),(47,16,6.00000,46.00000,1.00000,-40),(48,16,7.00000,47.00000,1.00000,-40),(49,16,8.00000,48.00000,1.00000,-40),(50,16,9.00000,49.00000,1.00000,-40),(51,16,10.00000,50.00000,1.00000,-40),(52,16,11.00000,51.00000,1.00000,-40),(53,16,12.00000,52.00000,1.00000,-40),(54,16,13.00000,53.00000,1.00000,-40),(55,16,14.00000,54.00000,1.00000,-40),(56,16,15.00000,55.00000,1.00000,-40),(57,16,16.00000,56.00000,1.00000,-40),(58,16,17.00000,57.00000,1.00000,-40),(59,16,18.00000,58.00000,1.00000,-40),(60,16,19.00000,59.00000,1.00000,-40),(61,16,20.00000,60.00000,1.00000,-40),(62,16,21.00000,61.00000,1.00000,-40),(63,16,22.00000,62.00000,1.00000,-40),(64,16,23.00000,63.00000,1.00000,-40),(65,16,24.00000,64.00000,1.00000,-40),(66,16,25.00000,65.00000,1.00000,-40),(67,16,26.00000,66.00000,1.00000,-40),(68,16,27.00000,67.00000,1.00000,-40),(69,16,28.00000,68.00000,1.00000,-40),(70,16,29.00000,69.00000,1.00000,-40),(71,16,30.00000,70.00000,1.00000,-40),(72,16,31.00000,71.00000,1.00000,-40),(73,16,32.00000,72.00000,1.00000,-40),(74,16,33.00000,73.00000,1.00000,-40),(75,16,34.00000,74.00000,1.00000,-40),(76,16,35.00000,75.00000,1.00000,-40),(77,16,36.00000,76.00000,1.00000,-40),(78,16,37.00000,77.00000,1.00000,-40),(79,16,38.00000,78.00000,1.00000,-40),(80,16,39.00000,79.00000,1.00000,-40),(81,16,40.00000,80.00000,1.00000,-40),(82,16,41.00000,81.00000,1.00000,-40),(83,16,42.00000,82.00000,1.00000,-40),(84,16,43.00000,83.00000,1.00000,-40),(85,16,44.00000,84.00000,1.00000,-40),(86,16,45.00000,85.00000,1.00000,-40),(87,16,46.00000,86.00000,1.00000,-40),(88,16,47.00000,87.00000,1.00000,-40),(89,16,48.00000,88.00000,1.00000,-40),(90,16,49.00000,89.00000,1.00000,-40),(91,16,50.00000,90.00000,1.00000,-40),(92,16,51.00000,91.00000,1.00000,-40),(93,16,52.00000,92.00000,1.00000,-40),(94,16,53.00000,93.00000,1.00000,-40),(95,16,54.00000,94.00000,1.00000,-40),(96,16,55.00000,95.00000,1.00000,-40),(97,16,56.00000,96.00000,1.00000,-40),(98,16,57.00000,97.00000,1.00000,-40),(99,16,58.00000,98.00000,1.00000,-40),(100,16,59.00000,99.00000,1.00000,-40),(101,16,60.00000,100.00000,1.00000,-40),(102,16,61.00000,101.00000,1.00000,-40),(103,16,62.00000,102.00000,1.00000,-40),(104,16,63.00000,103.00000,1.00000,-40),(105,16,64.00000,104.00000,1.00000,-40),(106,16,65.00000,105.00000,1.00000,-40),(107,16,66.00000,106.00000,1.00000,-40),(108,16,67.00000,107.00000,1.00000,-40),(109,16,68.00000,108.00000,1.00000,-40),(110,16,69.00000,109.00000,1.00000,-40),(111,16,70.00000,110.00000,1.00000,-40),(112,16,71.00000,111.00000,1.00000,-40),(113,16,72.00000,112.00000,1.00000,-40),(114,16,73.00000,113.00000,1.00000,-40),(115,16,74.00000,114.00000,1.00000,-40),(116,16,75.00000,115.00000,1.00000,-40),(117,16,76.00000,116.00000,1.00000,-40),(118,16,77.00000,117.00000,1.00000,-40),(119,16,78.00000,118.00000,1.00000,-40),(120,16,79.00000,119.00000,1.00000,-40),(121,16,80.00000,120.00000,1.00000,-40),(122,17,-40.00000,0.00000,1.00000,-40),(123,17,-39.00000,1.00000,1.00000,-40),(124,17,-38.00000,2.00000,1.00000,-40),(125,17,-37.00000,3.00000,1.00000,-40),(126,17,-36.00000,4.00000,1.00000,-40),(127,17,-35.00000,5.00000,1.00000,-40),(128,17,-34.00000,6.00000,1.00000,-40),(129,17,-33.00000,7.00000,1.00000,-40),(130,17,-32.00000,8.00000,1.00000,-40),(131,17,-31.00000,9.00000,1.00000,-40),(132,17,-30.00000,10.00000,1.00000,-40),(133,17,-29.00000,11.00000,1.00000,-40),(134,17,-28.00000,12.00000,1.00000,-40),(135,17,-27.00000,13.00000,1.00000,-40),(136,17,-26.00000,14.00000,1.00000,-40),(137,17,-25.00000,15.00000,1.00000,-40),(138,17,-24.00000,16.00000,1.00000,-40),(139,17,-23.00000,17.00000,1.00000,-40),(140,17,-22.00000,18.00000,1.00000,-40),(141,17,-21.00000,19.00000,1.00000,-40),(142,17,-20.00000,20.00000,1.00000,-40),(143,17,-19.00000,21.00000,1.00000,-40),(144,17,-18.00000,22.00000,1.00000,-40),(145,17,-17.00000,23.00000,1.00000,-40),(146,17,-16.00000,24.00000,1.00000,-40),(147,17,-15.00000,25.00000,1.00000,-40),(148,17,-14.00000,26.00000,1.00000,-40),(149,17,-13.00000,27.00000,1.00000,-40),(150,17,-12.00000,28.00000,1.00000,-40),(151,17,-11.00000,29.00000,1.00000,-40),(152,17,-10.00000,30.00000,1.00000,-40),(153,17,-9.00000,31.00000,1.00000,-40),(154,17,-8.00000,32.00000,1.00000,-40),(155,17,-7.00000,33.00000,1.00000,-40),(156,17,-6.00000,34.00000,1.00000,-40),(157,17,-5.00000,35.00000,1.00000,-40),(158,17,-4.00000,36.00000,1.00000,-40),(159,17,-3.00000,37.00000,1.00000,-40),(160,17,-2.00000,38.00000,1.00000,-40),(161,17,-1.00000,39.00000,1.00000,-40),(162,17,0.00000,40.00000,1.00000,-40),(163,17,1.00000,41.00000,1.00000,-40),(164,17,2.00000,42.00000,1.00000,-40),(165,17,3.00000,43.00000,1.00000,-40),(166,17,4.00000,44.00000,1.00000,-40),(167,17,5.00000,45.00000,1.00000,-40),(168,17,6.00000,46.00000,1.00000,-40),(169,17,7.00000,47.00000,1.00000,-40),(170,17,8.00000,48.00000,1.00000,-40),(171,17,9.00000,49.00000,1.00000,-40),(172,17,10.00000,50.00000,1.00000,-40),(173,17,11.00000,51.00000,1.00000,-40),(174,17,12.00000,52.00000,1.00000,-40),(175,17,13.00000,53.00000,1.00000,-40),(176,17,14.00000,54.00000,1.00000,-40),(177,17,15.00000,55.00000,1.00000,-40),(178,17,16.00000,56.00000,1.00000,-40),(179,17,17.00000,57.00000,1.00000,-40),(180,17,18.00000,58.00000,1.00000,-40),(181,17,19.00000,59.00000,1.00000,-40),(182,17,20.00000,60.00000,1.00000,-40),(183,17,21.00000,61.00000,1.00000,-40),(184,17,22.00000,62.00000,1.00000,-40),(185,17,23.00000,63.00000,1.00000,-40),(186,17,24.00000,64.00000,1.00000,-40),(187,17,25.00000,65.00000,1.00000,-40),(188,17,26.00000,66.00000,1.00000,-40),(189,17,27.00000,67.00000,1.00000,-40),(190,17,28.00000,68.00000,1.00000,-40),(191,17,29.00000,69.00000,1.00000,-40),(192,17,30.00000,70.00000,1.00000,-40),(193,17,31.00000,71.00000,1.00000,-40),(194,17,32.00000,72.00000,1.00000,-40),(195,17,33.00000,73.00000,1.00000,-40),(196,17,34.00000,74.00000,1.00000,-40),(197,17,35.00000,75.00000,1.00000,-40),(198,17,36.00000,76.00000,1.00000,-40),(199,17,37.00000,77.00000,1.00000,-40),(200,17,38.00000,78.00000,1.00000,-40),(201,17,39.00000,79.00000,1.00000,-40),(202,17,40.00000,80.00000,1.00000,-40),(203,17,41.00000,81.00000,1.00000,-40),(204,17,42.00000,82.00000,1.00000,-40),(205,17,43.00000,83.00000,1.00000,-40),(206,17,44.00000,84.00000,1.00000,-40),(207,17,45.00000,85.00000,1.00000,-40),(208,17,46.00000,86.00000,1.00000,-40),(209,17,47.00000,87.00000,1.00000,-40),(210,17,48.00000,88.00000,1.00000,-40),(211,17,49.00000,89.00000,1.00000,-40),(212,17,50.00000,90.00000,1.00000,-40),(213,17,51.00000,91.00000,1.00000,-40),(214,17,52.00000,92.00000,1.00000,-40),(215,17,53.00000,93.00000,1.00000,-40),(216,17,54.00000,94.00000,1.00000,-40),(217,17,55.00000,95.00000,1.00000,-40),(218,17,56.00000,96.00000,1.00000,-40),(219,17,57.00000,97.00000,1.00000,-40),(220,17,58.00000,98.00000,1.00000,-40),(221,17,59.00000,99.00000,1.00000,-40),(222,17,60.00000,100.00000,1.00000,-40),(223,17,61.00000,101.00000,1.00000,-40),(224,17,62.00000,102.00000,1.00000,-40),(225,17,63.00000,103.00000,1.00000,-40),(226,17,64.00000,104.00000,1.00000,-40),(227,17,65.00000,105.00000,1.00000,-40),(228,17,66.00000,106.00000,1.00000,-40),(229,17,67.00000,107.00000,1.00000,-40),(230,17,68.00000,108.00000,1.00000,-40),(231,17,69.00000,109.00000,1.00000,-40),(232,17,70.00000,110.00000,1.00000,-40),(233,17,71.00000,111.00000,1.00000,-40),(234,17,72.00000,112.00000,1.00000,-40),(235,17,73.00000,113.00000,1.00000,-40),(236,17,74.00000,114.00000,1.00000,-40),(237,17,75.00000,115.00000,1.00000,-40),(238,17,76.00000,116.00000,1.00000,-40),(239,17,77.00000,117.00000,1.00000,-40),(240,17,78.00000,118.00000,1.00000,-40),(241,17,79.00000,119.00000,1.00000,-40),(242,17,80.00000,120.00000,1.00000,-40),(243,24,-40.00000,0.00000,1.00000,-40),(244,24,-39.00000,1.00000,1.00000,-40),(245,24,-38.00000,2.00000,1.00000,-40),(246,24,-37.00000,3.00000,1.00000,-40),(247,24,-36.00000,4.00000,1.00000,-40),(248,24,-35.00000,5.00000,1.00000,-40),(249,24,-34.00000,6.00000,1.00000,-40),(250,24,-33.00000,7.00000,1.00000,-40),(251,24,-32.00000,8.00000,1.00000,-40),(252,24,-31.00000,9.00000,1.00000,-40),(253,24,-30.00000,10.00000,1.00000,-40),(254,24,-29.00000,11.00000,1.00000,-40),(255,24,-28.00000,12.00000,1.00000,-40),(256,24,-27.00000,13.00000,1.00000,-40),(257,24,-26.00000,14.00000,1.00000,-40),(258,24,-25.00000,15.00000,1.00000,-40),(259,24,-24.00000,16.00000,1.00000,-40),(260,24,-23.00000,17.00000,1.00000,-40),(261,24,-22.00000,18.00000,1.00000,-40),(262,24,-21.00000,19.00000,1.00000,-40),(263,24,-20.00000,20.00000,1.00000,-40),(264,24,-19.00000,21.00000,1.00000,-40),(265,24,-18.00000,22.00000,1.00000,-40),(266,24,-17.00000,23.00000,1.00000,-40),(267,24,-16.00000,24.00000,1.00000,-40),(268,24,-15.00000,25.00000,1.00000,-40),(269,24,-14.00000,26.00000,1.00000,-40),(270,24,-13.00000,27.00000,1.00000,-40),(271,24,-12.00000,28.00000,1.00000,-40),(272,24,-11.00000,29.00000,1.00000,-40),(273,24,-10.00000,30.00000,1.00000,-40),(274,24,-9.00000,31.00000,1.00000,-40),(275,24,-8.00000,32.00000,1.00000,-40),(276,24,-7.00000,33.00000,1.00000,-40),(277,24,-6.00000,34.00000,1.00000,-40),(278,24,-5.00000,35.00000,1.00000,-40),(279,24,-4.00000,36.00000,1.00000,-40),(280,24,-3.00000,37.00000,1.00000,-40),(281,24,-2.00000,38.00000,1.00000,-40),(282,24,-1.00000,39.00000,1.00000,-40),(283,24,0.00000,40.00000,1.00000,-40),(284,24,1.00000,41.00000,1.00000,-40),(285,24,2.00000,42.00000,1.00000,-40),(286,24,3.00000,43.00000,1.00000,-40),(287,24,4.00000,44.00000,1.00000,-40),(288,24,5.00000,45.00000,1.00000,-40),(289,24,6.00000,46.00000,1.00000,-40),(290,24,7.00000,47.00000,1.00000,-40),(291,24,8.00000,48.00000,1.00000,-40),(292,24,9.00000,49.00000,1.00000,-40),(293,24,10.00000,50.00000,1.00000,-40),(294,24,11.00000,51.00000,1.00000,-40),(295,24,12.00000,52.00000,1.00000,-40),(296,24,13.00000,53.00000,1.00000,-40),(297,24,14.00000,54.00000,1.00000,-40),(298,24,15.00000,55.00000,1.00000,-40),(299,24,16.00000,56.00000,1.00000,-40),(300,24,17.00000,57.00000,1.00000,-40),(301,24,18.00000,58.00000,1.00000,-40),(302,24,19.00000,59.00000,1.00000,-40),(303,24,20.00000,60.00000,1.00000,-40),(304,24,21.00000,61.00000,1.00000,-40),(305,24,22.00000,62.00000,1.00000,-40),(306,24,23.00000,63.00000,1.00000,-40),(307,24,24.00000,64.00000,1.00000,-40),(308,24,25.00000,65.00000,1.00000,-40),(309,24,26.00000,66.00000,1.00000,-40),(310,24,27.00000,67.00000,1.00000,-40),(311,24,28.00000,68.00000,1.00000,-40),(312,24,29.00000,69.00000,1.00000,-40),(313,24,30.00000,70.00000,1.00000,-40),(314,24,31.00000,71.00000,1.00000,-40),(315,24,32.00000,72.00000,1.00000,-40),(316,24,33.00000,73.00000,1.00000,-40),(317,24,34.00000,74.00000,1.00000,-40),(318,24,35.00000,75.00000,1.00000,-40),(319,24,36.00000,76.00000,1.00000,-40),(320,24,37.00000,77.00000,1.00000,-40),(321,24,38.00000,78.00000,1.00000,-40),(322,24,39.00000,79.00000,1.00000,-40),(323,24,40.00000,80.00000,1.00000,-40),(324,24,41.00000,81.00000,1.00000,-40),(325,24,42.00000,82.00000,1.00000,-40),(326,24,43.00000,83.00000,1.00000,-40),(327,24,44.00000,84.00000,1.00000,-40),(328,24,45.00000,85.00000,1.00000,-40),(329,24,46.00000,86.00000,1.00000,-40),(330,24,47.00000,87.00000,1.00000,-40),(331,24,48.00000,88.00000,1.00000,-40),(332,24,49.00000,89.00000,1.00000,-40),(333,24,50.00000,90.00000,1.00000,-40),(334,24,51.00000,91.00000,1.00000,-40),(335,24,52.00000,92.00000,1.00000,-40),(336,24,53.00000,93.00000,1.00000,-40),(337,24,54.00000,94.00000,1.00000,-40),(338,24,55.00000,95.00000,1.00000,-40),(339,24,56.00000,96.00000,1.00000,-40),(340,24,57.00000,97.00000,1.00000,-40),(341,24,58.00000,98.00000,1.00000,-40),(342,24,59.00000,99.00000,1.00000,-40),(343,24,60.00000,100.00000,1.00000,-40),(344,24,61.00000,101.00000,1.00000,-40),(345,24,62.00000,102.00000,1.00000,-40),(346,24,63.00000,103.00000,1.00000,-40),(347,24,64.00000,104.00000,1.00000,-40),(348,24,65.00000,105.00000,1.00000,-40),(349,24,66.00000,106.00000,1.00000,-40),(350,24,67.00000,107.00000,1.00000,-40),(351,24,68.00000,108.00000,1.00000,-40),(352,24,69.00000,109.00000,1.00000,-40),(353,24,70.00000,110.00000,1.00000,-40),(354,24,71.00000,111.00000,1.00000,-40),(355,24,72.00000,112.00000,1.00000,-40),(356,24,73.00000,113.00000,1.00000,-40),(357,24,74.00000,114.00000,1.00000,-40),(358,24,75.00000,115.00000,1.00000,-40),(359,24,76.00000,116.00000,1.00000,-40),(360,24,77.00000,117.00000,1.00000,-40),(361,24,78.00000,118.00000,1.00000,-40),(362,24,79.00000,119.00000,1.00000,-40),(363,24,80.00000,120.00000,1.00000,-40),(364,25,-40.00000,0.00000,1.00000,-40),(365,25,-39.00000,1.00000,1.00000,-40),(366,25,-38.00000,2.00000,1.00000,-40),(367,25,-37.00000,3.00000,1.00000,-40),(368,25,-36.00000,4.00000,1.00000,-40),(369,25,-35.00000,5.00000,1.00000,-40),(370,25,-34.00000,6.00000,1.00000,-40),(371,25,-33.00000,7.00000,1.00000,-40),(372,25,-32.00000,8.00000,1.00000,-40),(373,25,-31.00000,9.00000,1.00000,-40),(374,25,-30.00000,10.00000,1.00000,-40),(375,25,-29.00000,11.00000,1.00000,-40),(376,25,-28.00000,12.00000,1.00000,-40),(377,25,-27.00000,13.00000,1.00000,-40),(378,25,-26.00000,14.00000,1.00000,-40),(379,25,-25.00000,15.00000,1.00000,-40),(380,25,-24.00000,16.00000,1.00000,-40),(381,25,-23.00000,17.00000,1.00000,-40),(382,25,-22.00000,18.00000,1.00000,-40),(383,25,-21.00000,19.00000,1.00000,-40),(384,25,-20.00000,20.00000,1.00000,-40),(385,25,-19.00000,21.00000,1.00000,-40),(386,25,-18.00000,22.00000,1.00000,-40),(387,25,-17.00000,23.00000,1.00000,-40),(388,25,-16.00000,24.00000,1.00000,-40),(389,25,-15.00000,25.00000,1.00000,-40),(390,25,-14.00000,26.00000,1.00000,-40),(391,25,-13.00000,27.00000,1.00000,-40),(392,25,-12.00000,28.00000,1.00000,-40),(393,25,-11.00000,29.00000,1.00000,-40),(394,25,-10.00000,30.00000,1.00000,-40),(395,25,-9.00000,31.00000,1.00000,-40),(396,25,-8.00000,32.00000,1.00000,-40),(397,25,-7.00000,33.00000,1.00000,-40),(398,25,-6.00000,34.00000,1.00000,-40),(399,25,-5.00000,35.00000,1.00000,-40),(400,25,-4.00000,36.00000,1.00000,-40),(401,25,-3.00000,37.00000,1.00000,-40),(402,25,-2.00000,38.00000,1.00000,-40),(403,25,-1.00000,39.00000,1.00000,-40),(404,25,0.00000,40.00000,1.00000,-40),(405,25,1.00000,41.00000,1.00000,-40),(406,25,2.00000,42.00000,1.00000,-40),(407,25,3.00000,43.00000,1.00000,-40),(408,25,4.00000,44.00000,1.00000,-40),(409,25,5.00000,45.00000,1.00000,-40),(410,25,6.00000,46.00000,1.00000,-40),(411,25,7.00000,47.00000,1.00000,-40),(412,25,8.00000,48.00000,1.00000,-40),(413,25,9.00000,49.00000,1.00000,-40),(414,25,10.00000,50.00000,1.00000,-40),(415,25,11.00000,51.00000,1.00000,-40),(416,25,12.00000,52.00000,1.00000,-40),(417,25,13.00000,53.00000,1.00000,-40),(418,25,14.00000,54.00000,1.00000,-40),(419,25,15.00000,55.00000,1.00000,-40),(420,25,16.00000,56.00000,1.00000,-40),(421,25,17.00000,57.00000,1.00000,-40),(422,25,18.00000,58.00000,1.00000,-40),(423,25,19.00000,59.00000,1.00000,-40),(424,25,20.00000,60.00000,1.00000,-40),(425,25,21.00000,61.00000,1.00000,-40),(426,25,22.00000,62.00000,1.00000,-40),(427,25,23.00000,63.00000,1.00000,-40),(428,25,24.00000,64.00000,1.00000,-40),(429,25,25.00000,65.00000,1.00000,-40),(430,25,26.00000,66.00000,1.00000,-40),(431,25,27.00000,67.00000,1.00000,-40),(432,25,28.00000,68.00000,1.00000,-40),(433,25,29.00000,69.00000,1.00000,-40),(434,25,30.00000,70.00000,1.00000,-40),(435,25,31.00000,71.00000,1.00000,-40),(436,25,32.00000,72.00000,1.00000,-40),(437,25,33.00000,73.00000,1.00000,-40),(438,25,34.00000,74.00000,1.00000,-40),(439,25,35.00000,75.00000,1.00000,-40),(440,25,36.00000,76.00000,1.00000,-40),(441,25,37.00000,77.00000,1.00000,-40),(442,25,38.00000,78.00000,1.00000,-40),(443,25,39.00000,79.00000,1.00000,-40),(444,25,40.00000,80.00000,1.00000,-40),(445,25,41.00000,81.00000,1.00000,-40),(446,25,42.00000,82.00000,1.00000,-40),(447,25,43.00000,83.00000,1.00000,-40),(448,25,44.00000,84.00000,1.00000,-40),(449,25,45.00000,85.00000,1.00000,-40),(450,25,46.00000,86.00000,1.00000,-40),(451,25,47.00000,87.00000,1.00000,-40),(452,25,48.00000,88.00000,1.00000,-40),(453,25,49.00000,89.00000,1.00000,-40),(454,25,50.00000,90.00000,1.00000,-40),(455,25,51.00000,91.00000,1.00000,-40),(456,25,52.00000,92.00000,1.00000,-40),(457,25,53.00000,93.00000,1.00000,-40),(458,25,54.00000,94.00000,1.00000,-40),(459,25,55.00000,95.00000,1.00000,-40),(460,25,56.00000,96.00000,1.00000,-40),(461,25,57.00000,97.00000,1.00000,-40),(462,25,58.00000,98.00000,1.00000,-40),(463,25,59.00000,99.00000,1.00000,-40),(464,25,60.00000,100.00000,1.00000,-40),(465,25,61.00000,101.00000,1.00000,-40),(466,25,62.00000,102.00000,1.00000,-40),(467,25,63.00000,103.00000,1.00000,-40),(468,25,64.00000,104.00000,1.00000,-40),(469,25,65.00000,105.00000,1.00000,-40),(470,25,66.00000,106.00000,1.00000,-40),(471,25,67.00000,107.00000,1.00000,-40),(472,25,68.00000,108.00000,1.00000,-40),(473,25,69.00000,109.00000,1.00000,-40),(474,25,70.00000,110.00000,1.00000,-40),(475,25,71.00000,111.00000,1.00000,-40),(476,25,72.00000,112.00000,1.00000,-40),(477,25,73.00000,113.00000,1.00000,-40),(478,25,74.00000,114.00000,1.00000,-40),(479,25,75.00000,115.00000,1.00000,-40),(480,25,76.00000,116.00000,1.00000,-40),(481,25,77.00000,117.00000,1.00000,-40),(482,25,78.00000,118.00000,1.00000,-40),(483,25,79.00000,119.00000,1.00000,-40),(484,25,80.00000,120.00000,1.00000,-40);

--
-- Table structure for table `sensordata`
--

CREATE TABLE `sensordata` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `datagps_id` int(10) unsigned NOT NULL,
  `sensor_id` int(10) unsigned NOT NULL,
  `Value` double(10,2) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `Index_2` (`datagps_id`,`sensor_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `sensordata`
--


--
-- Table structure for table `sensors`
--

CREATE TABLE `sensors` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `mobitel_id` int(11) NOT NULL,
  `Name` varchar(45) NOT NULL,
  `Description` varchar(200) NOT NULL,
  `StartBit` int(10) unsigned NOT NULL,
  `Length` int(10) unsigned NOT NULL,
  `NameUnit` varchar(45) NOT NULL,
  `K` double(10,5) NOT NULL DEFAULT '0.00000',
  `B` double DEFAULT '0' COMMENT 'Shift coefficient',
  `S` tinyint(1) DEFAULT '0' COMMENT 'Sign arifmetic',
  PRIMARY KEY (`id`),
  KEY `Index_2` (`mobitel_id`)
) ENGINE=InnoDB AUTO_INCREMENT=32 DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `sensors`
--

INSERT INTO `sensors` VALUES (2,97,'бортмережа','',32,8,'В',0.11810,0,0),(3,98,'бортсеть','',32,8,'В',0.11810,0,0),(4,97,'зажигание','',60,1,'',1.00000,0,0),(5,98,'зажигание','',60,1,'',1.00000,0,0),(6,99,'бортмережа','',32,8,'В',0.11810,0,0),(7,100,'бортмережа','',32,8,'В',0.11810,0,0),(8,101,'бортмережа','',32,8,'В',0.11810,0,0),(9,100,'зажигание','Default',60,1,'--',1.00000,0,0),(10,102,'бак','',0,8,'%',0.39220,0,0),(11,102,'бортсеть','',8,8,'В',0.11810,0,0),(12,102,'расход','',16,32,'л',0.10000,0,0),(13,102,'одометр по штатному датчику скорости','',48,32,'км',1.00000,0,0),(14,102,'обороты двигателя','',80,16,'rpm',0.25000,0,0),(15,102,'расчётное значение нагрузки на двигатель','',96,8,'%',0.39220,0,0),(16,102,'температура охлаждающей жидкости','',104,8,'°C',0.00000,0,0),(17,102,'температура всасываемого воздуха','',112,8,'°C',0.00000,0,0),(18,102,'зажигание','',199,1,'#',1.00000,0,0),(20,103,'бортсеть','',8,8,'В',0.11810,0,0),(21,103,'расход','',16,32,'л',0.10000,0,0),(22,103,'одометр по штатному датчику скорости','',48,32,'км',1.00000,0,0),(23,103,'обороты двигателя','',80,16,'rpm',0.25000,0,0),(24,103,'расчётное значение нагрузки на двигатель','',96,8,'%',0.39220,0,0),(25,103,'температура охлаждающей жидкости','',104,8,'°C',0.00000,0,0),(26,103,'температура всасываемого воздуха','',112,8,'°C',0.00000,0,0),(27,103,'зажигание','',199,1,'#',1.00000,0,0),(28,104,'бортмережа','',32,8,'В',0.11810,0,0),(29,101,'запалювання','Default',60,1,'--',0.00000,0,0),(30,104,'запалювання','Default',60,1,'--',1.00000,0,0),(31,99,'запалювання','Default',60,1,'--',1.00000,0,0);

--
-- Table structure for table `serviceinit`
--

CREATE TABLE `serviceinit` (
  `ServiceInit_ID` int(11) NOT NULL AUTO_INCREMENT,
  `Name` char(50) DEFAULT NULL,
  `Descr` char(200) DEFAULT NULL,
  `ID` int(11) DEFAULT '0',
  `Flags` int(11) DEFAULT '0',
  `ServiceType_ID` int(11) DEFAULT '0',
  `A1` char(50) DEFAULT NULL,
  `A2` char(50) DEFAULT NULL,
  `A3` char(50) DEFAULT NULL,
  `A4` char(50) DEFAULT NULL,
  `A5` char(50) DEFAULT NULL,
  `A6` char(50) DEFAULT NULL,
  `A7` char(50) DEFAULT NULL,
  `A8` char(50) DEFAULT NULL,
  `A9` char(50) DEFAULT NULL,
  `A10` char(200) DEFAULT NULL,
  `CAtoSAint` int(11) DEFAULT '0',
  `CAtoSAtime` int(11) DEFAULT '0',
  `SAtoCAint` int(11) DEFAULT '0',
  `SAtoCAtime` int(11) DEFAULT '0',
  `SAtoCAtext` char(50) DEFAULT 'STOPPED',
  `CAtoSAtext` char(50) DEFAULT 'STOPPED',
  `MobitelActive_ID` int(11) NOT NULL DEFAULT '0',
  `Active` tinyint(3) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`ServiceInit_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=30 DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `serviceinit`
--

INSERT INTO `serviceinit` VALUES (1,'Direct Cable','Сервис для прямого кабельного соединения',0,0,5,'COM1','115200','','','','','','','','xxx',0,0,4,1284657437,'Failed Run',NULL,98,0),(7,'GSM модем','Отправка SMS по  GSM каналу',0,0,2,'COM2','115200','','','','','','','','xxx',0,0,1,1284657437,'Running',NULL,75,0),(29,'EMail','Сервис отправки данных через E-mail',29,1125886839,6,'p016@lwco.biz','p016@lwco.biz','VilnE123','smtp.lwco.biz','pop.lwco.biz','25','110','100','','',0,0,1,1315821577,'Running',NULL,68,0);

--
-- Table structure for table `servicesend`
--

CREATE TABLE `servicesend` (
  `ServiceSend_ID` int(11) NOT NULL AUTO_INCREMENT,
  `Name` varchar(50) DEFAULT NULL,
  `Descr` varchar(200) DEFAULT NULL,
  `ID` int(11) DEFAULT '0',
  `Flags` int(11) DEFAULT '0',
  `telMobitel` varchar(64) DEFAULT NULL,
  `smsMobitel` varchar(64) DEFAULT NULL,
  `emailMobitel` varchar(64) DEFAULT NULL,
  `IPMobitel` varchar(64) DEFAULT NULL,
  `URLMobitel` varchar(64) DEFAULT NULL,
  `PortMobitel` int(11) DEFAULT '0',
  `RfMobitel` varchar(50) DEFAULT NULL,
  `Message_ID` int(11) DEFAULT '0',
  PRIMARY KEY (`ServiceSend_ID`),
  KEY `Index_2` (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=279 DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `servicesend`
--

INSERT INTO `servicesend` VALUES (250,'Record 22.09.2005 12:14:57','Description for record created at 22.09.2005 12:14:57',250,0,'115',NULL,NULL,NULL,NULL,0,NULL,0),(252,'Record 22.09.2005 12:14:57','Description for record created at 22.09.2005 12:14:57',250,0,'98','106','3051@p314.net','',NULL,0,'',200892),(255,'Record 22.09.2005 12:14:57','Description for record created at 22.09.2005 12:14:57',250,0,'96','80','','',NULL,0,'',218879),(256,'Record 22.09.2005 12:14:57','Description for record created at 22.09.2005 12:14:57',250,0,'75','89','c385@lwco.biz','',NULL,0,'',8),(257,'Record 21.06.2010 8:46:43','Description for record created at 21.06.2010 8:46:43',257,0,'104',NULL,NULL,NULL,NULL,0,NULL,0),(258,'Record 21.06.2010 8:46:43','Description for record created at 21.06.2010 8:46:43',257,0,'74','91','C384@lwco.biz','',NULL,0,'',41),(259,'Record 22.09.2005 12:14:57','Description for record created at 22.09.2005 12:14:57',250,0,'75','89','C385@lwco.biz','',NULL,0,'',75),(260,'Record 17.05.2013 19:22:54','Description for record created at 17.05.2013 19:22:54',260,0,'116',NULL,NULL,NULL,NULL,0,NULL,0),(261,'Record 17.05.2013 19:22:54','Description for record created at 17.05.2013 19:22:54',260,0,'102','92','0918@lwco.biz','',NULL,0,'',89),(262,'Record 21.05.2013 22:33:51','Description for record created at 21.05.2013 22:33:51',262,0,'117',NULL,NULL,NULL,NULL,0,NULL,0),(263,'Record 21.05.2013 22:33:51','Description for record created at 21.05.2013 22:33:51',262,0,'103','93','0685@lwco.biz','',NULL,0,'',93),(264,'Record 20.06.2015 15:49:54','Description for record created at 20.06.2015 15:49:54',264,0,'118',NULL,NULL,NULL,NULL,0,NULL,0),(265,'Record 20.06.2015 15:49:54','Description for record created at 20.06.2015 15:49:54',264,0,'73','94','','',NULL,0,'',98),(266,'5519','Desctiption for Teletrack registered at 20.03.2018 18:31:17',266,0,'113',NULL,NULL,NULL,NULL,0,NULL,0),(267,'set','phone',250,0,'105',NULL,NULL,NULL,NULL,0,NULL,0),(268,'set','phone',257,0,'106',NULL,NULL,NULL,NULL,0,NULL,0),(269,'set','phone',257,0,'107',NULL,NULL,NULL,NULL,0,NULL,0),(270,'set','phone',250,0,'108',NULL,NULL,NULL,NULL,0,NULL,0),(271,'set','phone',260,0,'109',NULL,NULL,NULL,NULL,0,NULL,0),(272,'set','phone',262,0,'110',NULL,NULL,NULL,NULL,0,NULL,0),(273,'set','phone',264,0,'111',NULL,NULL,NULL,NULL,0,NULL,0),(274,'set','phone',266,0,'112',NULL,NULL,NULL,NULL,0,NULL,0),(275,'9546','Desctiption for Teletrack registered at 31.05.2018 17:09:48',275,0,'119',NULL,NULL,NULL,NULL,0,NULL,0),(276,'set','phone',275,0,'114',NULL,NULL,NULL,NULL,0,NULL,0),(277,'5072','Desctiption for Teletrack registered at 24.06.2020 11:30:11',277,0,'121',NULL,NULL,NULL,NULL,0,NULL,0),(278,'set','phone',277,0,'120',NULL,NULL,NULL,NULL,0,NULL,0);

--
-- Table structure for table `servicetypes`
--

CREATE TABLE `servicetypes` (
  `ServiceType_ID` int(11) NOT NULL AUTO_INCREMENT,
  `Name` char(50) DEFAULT NULL,
  `Descr` char(200) DEFAULT NULL,
  `Flags` int(11) DEFAULT '0',
  `D1` char(200) DEFAULT NULL,
  `D2` char(200) DEFAULT NULL,
  `D3` char(200) DEFAULT NULL,
  `D4` char(200) DEFAULT NULL,
  `D5` char(200) DEFAULT NULL,
  `D6` char(200) DEFAULT NULL,
  `D7` char(200) DEFAULT NULL,
  `D8` char(200) DEFAULT NULL,
  `D9` char(200) DEFAULT NULL,
  `D10` char(200) DEFAULT NULL,
  PRIMARY KEY (`ServiceType_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `servicetypes`
--

INSERT INTO `servicetypes` VALUES (1,'reserved','Зарезервировано',0,'Parameter 1','Parameter 2','Parameter 3','','','','','','',''),(2,'GSM','Тип сервиса для отправки SMS через GSM соединение',0,'Номер порта','Скорость порта','','','','','','','',''),(3,'Online','Online',0,'IP','Port','Login','Password','','','','','',''),(4,'RF modem','Радиомодем (не реализовано)',0,'Номер порта','Скорость порта','','','','','','','',''),(5,'DC','Тип сервиса \"прямое кабельное соединения\"',0,'Номер порта','Скорость порта',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),(6,'E-Mail','Тип сервиса \" E-Mail \" для отправки SMS через электронную почту',0,'EMAIL','Login','Password','Smtp Server','Pop3 Server','Smtp Port','Pop3 Port','Check Out time',NULL,NULL);

--
-- Table structure for table `setting`
--

CREATE TABLE `setting` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `TimeBreak` time DEFAULT '00:01:00' COMMENT 'Минимальное время остановки',
  `RotationMain` int(11) DEFAULT '100' COMMENT 'Обороты основного двигателя',
  `RotationAdd` int(11) DEFAULT '100' COMMENT 'Обороты доп. двигателя',
  `FuelingEdge` int(11) DEFAULT '0' COMMENT 'Минимальная заправка',
  `band` int(11) DEFAULT '25' COMMENT 'Полоса осреднения',
  `FuelingDischarge` int(11) DEFAULT '0' COMMENT 'Минимальный слив топлива',
  `accelMax` double DEFAULT '1' COMMENT 'Максимальное ускорение',
  `breakMax` double DEFAULT '1' COMMENT 'Максимальное торможение',
  `speedMax` double DEFAULT '70' COMMENT 'Максимальная скорость',
  `idleRunningMain` int(11) DEFAULT '0' COMMENT 'Холостой ход основного двигателя',
  `idleRunningAdd` int(11) DEFAULT '0' COMMENT 'Холосой ход доп. двигателя',
  `Name` char(20) DEFAULT 'Установки' COMMENT 'Название',
  `Desc` char(80) DEFAULT 'Описание установки' COMMENT 'Описание ',
  `AvgFuelRatePerHour` double(10,5) NOT NULL DEFAULT '30.00000' COMMENT 'Средний расход топлива в час',
  `FuelApproximationTime` time NOT NULL DEFAULT '00:10:00' COMMENT 'Временной интервал перед стоянкой, по точка которого уточняется уровень топлива в начале стоянки',
  `TimeGetFuelAfterStop` time NOT NULL DEFAULT '00:00:00' COMMENT 'Временной интервал между началом стоянки и замером уровня топлива',
  `TimeGetFuelBeforeMotion` time NOT NULL DEFAULT '00:00:00' COMMENT 'Временной интервал между замером уровня топлива и началом движения',
  `CzMinCrossingPairTime` time NOT NULL DEFAULT '00:01:00' COMMENT 'Min временной интервал между двумя пересечениями КЗ',
  `FuelerRadiusFinds` int(11) NOT NULL DEFAULT '10' COMMENT 'Радиус поиска заправляемых ТС вокруг топливозаправщика',
  `FuelerMaxTimeStop` time NOT NULL DEFAULT '00:02:00' COMMENT 'Минимальное время до заправки следующего ТС',
  `FuelerMinFuelrate` int(11) NOT NULL DEFAULT '1' COMMENT 'Минимальная величина заправки, что будет попадать в отчет',
  `FuelerCountInMotion` int(11) NOT NULL DEFAULT '0' COMMENT 'Считать ли заправки, при не нулевой скорости',
  `FuelrateWithDischarge` int(11) NOT NULL DEFAULT '0' COMMENT 'Считать ли в расходе сливы',
  `FuelingMinMaxAlgorithm` int(11) NOT NULL DEFAULT '0' COMMENT 'Считать заправки по MAX-MIN',
  `TimeBreakMaxPermitted` time NOT NULL DEFAULT '03:00:00' COMMENT 'Макс. время разрешенной стоянки',
  `InclinometerMaxAngleAxisX` double NOT NULL DEFAULT '5' COMMENT 'Предельный угол наклона относительно продольной оси Х ',
  `InclinometerMaxAngleAxisY` double NOT NULL DEFAULT '5' COMMENT 'Предельный угол наклона относительно продольной оси Y ',
  `speedMin` float NOT NULL DEFAULT '0' COMMENT 'Минимальная скорость в км/ч',
  `TimeMinimMovingSize` time NOT NULL DEFAULT '00:00:00' COMMENT 'Минимальное время движения в начале смены',
  `MinTimeSwitch` int(11) NOT NULL DEFAULT '0' COMMENT 'Минимальное время между двумя событиями датчика',
  PRIMARY KEY (`id`),
  UNIQUE KEY `id` (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `setting`
--

INSERT INTO `setting` VALUES (1,'00:01:00',100,100,20,4,10,1,1,90,0,0,'Настройка 1','Настройка по умолчанию',30.00000,'00:10:00','00:00:00','00:00:00','00:01:00',10,'00:02:00',1,0,1,0,'03:00:00',5,5,0,'00:00:00',0);

--
-- Table structure for table `smsnumbers`
--

CREATE TABLE `smsnumbers` (
  `SmsNumber_ID` int(11) NOT NULL AUTO_INCREMENT,
  `Name` char(50) DEFAULT NULL,
  `Descr` char(200) DEFAULT NULL,
  `ID` int(11) DEFAULT '0',
  `Flags` int(11) DEFAULT '0',
  `smsNumber` char(14) DEFAULT NULL,
  PRIMARY KEY (`SmsNumber_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=95 DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `smsnumbers`
--

INSERT INTO `smsnumbers` VALUES (9,'UMC SMS Center','UMC SMS Center descr',0,0,'+380500005010'),(42,'Golden SMS Center','Golden SMS Center descr',0,0,'+380390001008'),(53,'GOLDEN SMS Шлюз','Номер телефона, на который отправляются данные с ТТ через E_MAIL',0,0,'025'),(80,'SMS',' (SMS)',0,0,'+38067'),(81,'RCSB (SMS)','Телефон (SMS)',0,0,'+380672452724'),(82,'RCSB2 (SMS)',' (SMS)',0,0,'+380672452734'),(83,'RCS1 (SMS)',' (SMS)',0,0,'+380637562677'),(84,'RCS2 (SMS)',' (SMS)',0,0,'+380933222277'),(85,'RCS3 (SMS)',' (SMS)',0,0,'+380637562678'),(86,'MNK (SMS)','Телефон (SMS)',0,0,'+380673933874'),(87,'Shlyuz (SMS)',' (SMS)',0,0,'+380673602088'),(88,'Volodya (SMS)',' (SMS)',0,0,'+380673620909'),(89,'1 (SMS)',' (SMS)',0,0,'+380673632235'),(90,'Roman (SMS)',' (SMS)',0,0,'+380678029367'),(91,'2 (SMS)','Телефон (SMS)',0,0,'+380673604814'),(92,'0918 (SMS)','ID_0918 (SMS)',0,0,'+380673621991'),(93,'0685 (SMS)','ID_0685_PRO (SMS)',0,0,'+380673622209'),(94,'9042 (SMS)','ID_9042 (SMS)',0,0,'+380673620192');

--
-- Table structure for table `sources`
--

CREATE TABLE `sources` (
  `Source_ID` int(11) NOT NULL AUTO_INCREMENT,
  `SourceText` char(200) DEFAULT NULL,
  `SourceError` char(200) DEFAULT NULL,
  PRIMARY KEY (`Source_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=92 DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `sources`
--

INSERT INTO `sources` VALUES (1,'d016@lwco.biz %%AAiAAAAyCABDZMMQNQbCdYb-LYaaeAACAAAAAAAAnicAAv+REAfyZMMQNQbCdYb-LYaaeA0S3XALC-EoA2rwX032XAACAAAAAniA03XtAAAAAAAAAAXwXXX-XXX-XXX-XXX-XXX-XXX-XXX-',''),(2,'d016@lwco.biz %%AAiAAAAyCABDZMMQNQbCdYb-LYaaeAACAAAAAAAAnicAAv+REAfyZMMQNQbCdYb-LYaaeA0S3XALC-EoA2rwX032XAACAAAAAniA03XtAAAAAAAAAAXwXXX-XXX-XXX-XXX-XXX-XXX-XXX-',''),(3,'d016@lwco.biz %%AAiAAAAyCABDZMMQNQbCdYb-LYaaeAACAAAAAAAAnicAAv+REAfyZMMQNQbCdYb-LYaaeA0S3XALC-EoA2rwX032XAACAAAAAniA03XtAAAAAAAAAAXwXXX-XXX-XXX-XXX-XXX-XXX-XXX-',''),(4,'a@abc.net     %%AAiAAAATNAASAVLQSTSZVAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAcAbcLjbdY8bLYraeAJAAAAAAAAAAAAAAAAXXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-',''),(5,'a@abc.net     %%AAiAAAAGMAAjcbdHcLbIdYb-LYaaeAACAAAAAAAAAAAAAAbgbbAKAAAAAAAAddd-AAAAAAAAcbcMLbdyYbLvYaemAAAAAAAAAAAAAAAAAYM8ONQEAZAEAAVgabbhZMONNAABXXX-XXX-XXX-',''),(6,'a@abc.net     %%AAiAAAAqMAAyACd4ddLvaeaXdcdOYcLpbZdGAAAAAAAAAAAAaZcNccAOAAAAAabkdZckbZdGAAMQOMLtNMLkNMLiNNAFAAAAALMENNLeMMMAMMaQbdZScbZadAAAaeaXdcdOYcAJAXX8XXX-',''),(7,'a@abc.net     %%..i.z41cEACRYMOPNAABAAAAAAAAAAAAAAAAAA-w-------------------------MLnMOABAAAAAAnAigAYAA-w-XX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-',''),(8,'a@abc.net     %%..i.z41wDABxAADzB0ADyAAQABAEAAAQABAEAAAAAAAEAAARAAAEAAGBAGAAGAGAAEAREAAQAAAEAAABAA-0---------+vH+fjPB9wAAQABAAWKAPAAAXX9XXX-XXX-XXX-XXX-XXX-XXX-',''),(9,'a@abc.net     %%..i.z41mDABggZNsACjS8AAiAAgAZNILkn8kAAAIAgZwOMh9T8AJAAACgZOcMhTf8AvCwQAHUabDedelAAVgbbbzZeYUATTkSAAD4uY4gZNsIknQ8AvCwQX3XXX-XXX-XXX-XXX-XXX-XXX-',''),(10,'a@abc.net     %%..i.z41yJAChXXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-',''),(11,'d016@lwco.biz %%..i.z41SCABTZMMQNQbCdYb-LYaaeA-y----------APAv+QEAfyZMMQNQbCdYb-LYaaeA0S3XALC-EoA2rwXogOZOM3hT8XfqY603XtAAAAAAAAA-X8XXX-XXX-XXX-XXX-XXX-XXX-XXX-',''),(12,'              %%..i.z41WNACyAVLQSTSZVAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAcAbcLjbdY8bLYraeAJAAAAAAAAAAAAAAAAXXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-',''),(13,'              %%..i.z412MADDcbdHcLbIdYb-LYaaeAACAAAAAAAAAAAAAAbgbbAKAAAAAAAAddd-AAAAAAAAcbcMLbdyYbLvYaemAAAAAAAAAAAAAAAAAYM8ONQEAZAEAAVgabbhZMONNAABXXX-XXX-XXX-',''),(14,'              %%..i.z416MADTcbdHcLbIdYb-LYaaeAACAAAAAAAAAAAAAAbgbbAKAAAAAAAAddd-AAAAAAAAcbcMLbdyYbLvYaemAAAAAAAAAAAAAAAAAYM8ONQEAZAEAAVgabbhZMONNAABXXX-XXX-XXX-',''),(15,'              %%..i.z41fMADiACd4ddLvaeaXdcdOYcLpbZdGAAAAAAAAAAAAaZcNccAOAAAAAabkdZckbZdGAAMQOMLtNMLkNMLiNNAFAAAAALMENNLeMMMAMMaQbdZScbZadAAAaeaXdcdOYcAJAXX8XXX-',''),(16,'d016@lwco.biz %%..i.z41cCADzZMMQNQbCdYb-LYaaeA-y----------APAv+QEAfyZMMQNQbCdYb-LYaaeA0S3XALC-EoA2rwXogOZOM3hT8XfqY603XtAAAAAAAAA-X8XXX-XXX-XXX-XXX-XXX-XXX-XXX-',''),(17,'              %%..i.z41dDAEAgZNsACjS8AAiAAgAZNILkn8kAAAIAgZwOMh9T8AJAAACgZOcMhTf8AvCwQAHUabDedelAAVgbbbzZeYUATTkSAAD4uY4gZNsIknQ8AvCwQX3XXX-XXX-XXX-XXX-XXX-XXX-',''),(18,'              %%..i.z41oDAERAADzB0ADyAAQABAEBAARABAEAAAAAAAEAAARAAAEAAGBAGAAGAGAAEAREAAQAAAEAAABAA-0---------+vH+fjPB9wAAQABAAWKAPAAAXX9XXX-XXX-XXX-XXX-XXX-XXX-',''),(19,'a@abc.net     %%..i<z41kEAEhQMOPNAABAAAAAAAAAAAAAAAAAA-w-------------------------MLnMOABAAAAAAnAigAYAA-w-XX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-',''),(20,'a@abc.net     %%..i<z416JAExXXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-',''),(21,'              %%..i<z41cLAEzQMOPNOMVMMOAMMVKVMMoMAABdp-9-------------------------NLjMMICIIIAIIIAIIIAIA-w-XX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-','No error'),(22,'a@abc.net     %%..i<z41NNAFCAVLQSTSZVAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAcAbcLjbdY8bLYraeAJAAAAAAAAAAAAAAAAXXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-',''),(23,'              %%..i<z41NQAFAAVLQSTSZVAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAcAbcLjbdY8bLYraeAJAAAAAAAAAAAAAAAAXXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-','No error'),(24,'a@abc.net     %%..i<z41+MAFTcbdHcLbIdYb-LYaaeAACAAAAAAAAAAAAAAbgbbAKAAAAAAAAddd-AAAAAAAAcbcMLbdyYbLvYaemAAAAAAAAAAAAAAAAAYM8ONQEAZAEAAVgabbhZMONNAABXXX-XXX-XXX-',''),(25,'a@abc.net     %%..i<z41jMAFiACd4ddLvaeaXdcdOYcLpbZdGAAAAAAAAAAAAaZcNccAOAAAAAabkdZckbZdGAAMQOMLtNMLkNMLiNNAFAAAAALMENNLeMMMAMMaQbdZScbZadAAAaeaXdcdOYcAJAXX8XXX-',''),(26,'d016@lwco.biz %%..i<z41gCAFzZMMQNQbCdYb-LYaaeA-y----------APAv+QEAfyZMMQNQbCdYb-LYaaeA0S3XALC-EoA2rwXogOZOM3hT8XfqY603XtAAAAAAAAA-X8XXX-XXX-XXX-XXX-XXX-XXX-XXX-',''),(27,'              %%..i<z41-PAFRcbdHcLbIdYb-LYaaeAACAAAAAAAAAAAAAAbgbbAKAAAAAAAAddd-AAAAAAAAcbcMLbdyYbLvYaemAAAAAAAAAAAAAAAAAYM8ONQEAZAEAAVgabbhZMONNAABXXX-XXX-XXX-','No error'),(28,'              %%..i<z41kPAFgACd4ddLvaeaXdcdOYcLpbZdGAAAAAAAAAAAAaZcNccAOAAAAAabkdZckbZdGAAMQOMLtNMLkNMLiNNAFAAAAALMENNLeMMMAMMaQbdZScbZadAAAaeaXdcdOYcAJAXX8XXX-','No error'),(29,'d016@lwco.biz %%..i<z41gFAFxZMMQNQbCdYb-LYaaeA-y----------APAv+QEAfyZMMQNQbCdYb-LYaaeA0S3XALC-EoA2rwXogOZOM3hT8XfqY603XtAAAAAAAAA-X8XXX-XXX-XXX-XXX-XXX-XXX-XXX-','No error'),(30,'              %%..i<z41hDAGAgZNsACjS8AAiAAgAZNILkn8kAAAIAgZwOMh9T8AJAAACgZOcMhTf8AvCwQAHUabDedelAAVgbbbzZeYUATTkSAAD4uY4gZNsIknQ8AvCwQX3XXX-XXX-XXX-XXX-XXX-XXX-',''),(31,'d016@lwco.biz %%..i<z41iFAGCgZNsACjS8AAiAAgAZNILkn8kAAAIAgZwOMh9T8AJAAACgZOcMhTf8AvCwQAHUabDedelAAVgbbbzZeYUATTkSAAD4uY4gZNsIknQ8AvCwQX3XXX-XXX-XXX-XXX-XXX-XXX-','No error'),(32,'              %%..i<z41sDAGRAADzB0ADyAAQABAEBAARABAEAAAAAAAEAAARAAAEAAGBAGAAGAGAAEAREAAQAAAEAAABAA-0---------+vH+fjPB9wAAQABAAWKAPAAAXX9XXX-XXX-XXX-XXX-XXX-XXX-',''),(33,'d016@lwco.biz %%..i<z41tFAGTAADzB0ADyAAQABAEBAARABAEAAAAAAAEAAARAAAEAAGBAGAAGAGAAEAREAAQAAAEAAABAA-0---------+vH+fjPB9wAAQABAAWKAPAAAXX9XXX-XXX-XXX-XXX-XXX-XXX-','No error'),(34,'a@abc.net     %%..i<z41xDAGhAADzB0ADyAAQABAEAAAQABAEAAAAAAAEAAARAAAEAAGBAGAAGAGAAEAREAAQAAAEAAABAA-0---------+vH+fjPB9wAAQABAAWKAPAAAXX9XXX-XXX-XXX-XXX-XXX-XXX-',''),(35,'d016@lwco.biz %%..i<z41yFAGjAADzB0ADyAAQABAEAAAQABAEAAAAAAAEAAARAAAEAAGBAGAAGAGAAEAREAAQAAAEAAABAA-0---------+vH+fjPB9wAAQABAAWKAPAAAXX9XXX-XXX-XXX-XXX-XXX-XXX-\r\n','No error'),(36,'d016@lwco.biz %%..i<z41yFAGjAADzB0ADyAAQABAEAAAQABAEAAAAAAAEAAARAAAEAAGBAGAAGAGAAEAREAAQAAAEAAABAA-0---------+vH+fjPB9wAAQABAAWKAPAAAXX9XXX-XXX-XXX-XXX-XXX-XXX-\r\n','No error'),(37,'a@abc.net     %%..i<z411DAGxAADzB0ADyAAQABAEAAAQABAEAAAAAAAEAAARAAAEAAGBAGAAGAGAAEAREAAQAAAEAAABAA-0---------+vH+fjPB9wAAQABAIKOAPAAAXX9XXX-XXX-XXX-XXX-XXX-XXX-',''),(38,'a@abc.net     %%..i<z41GDAHAgZNsACjS8AAiAAgAZNILkn8kAAAIAgZwgKNkf8AJAAACgZOcMhTf8AvCwQAHUabDedelAAVgbbbzZeYUAUb4bYblAuY4gZNsIknQ8AvCwQX3XXX-XXX-XXX-XXX-XXX-XXX-',''),(39,'d016@lwco.biz %%..i<z412FAGzAADzB0ADyAAQABAEAAAQABAEAAAAAAAEAAARAAAEAAGBAGAAGAGAAEAREAAQAAAEAAABAA-0---------+vH+fjPB9wAAQABAIKOAPAAAXX9XXX-XXX-XXX-XXX-XXX-XXX-\r\n','No error'),(40,'d016@lwco.biz %%..i<z41HFAHCgZNsACjS8AAiAAgAZNILkn8kAAAIAgZwgKNkf8AJAAACgZOcMhTf8AvCwQAHUabDedelAAVgbbbzZeYUAUb4bYblAuY4gZNsIknQ8AvCwQX3XXX-XXX-XXX-XXX-XXX-XXX-\r\n','No error'),(41,'a@abc.net     %%AAiAAAAZNAAiAVLQSTSZVAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAcAbcLjbdY8bLYraeAJAAAAAAAAAAAAAAAAXXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-',''),(42,'a@abc.net     %%AAi<z40LEAAxQMOPNAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAnAigAUAAAAAXX8XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-',''),(43,'a@abc.net     %%AAi<z401JABBXXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-',''),(44,'              %%..i<z408LABDQMOPNOMUMMOAMMVGVMMoMAABg1-4-------------------------NLjMMICIIIAIIIAIIIAIA-w-XX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-','No error'),(45,'a@abc.net     %%AAi<z40ZNABSAVLQSTSZVAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAcAbcLjbdY8bLYraeAJAAAAAAAAAAAAAAAAXXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-',''),(46,'              %%..i<z40QQABQAVLQSTSZVAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAcAbcLjbdY8bLYraeAJAAAAAAAAAAAAAAAAXXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-','No error'),(47,'a@abc.net     %%AAi<z40SMABjcbdHcLbIdYb-LYaaeAACAAAAAAAAAAAAAAbgbbAKAAAAAAAAddd-AAAAAAAAcbcMLbdyYbLvYaemAAAAAAAAAAAAAAAAAAdAXbYbbZAFAAAAdXcMYcd9AAAAXXX-XXX-XXX-',''),(48,'              %%..i<z40JPABhcbdHcLbIdYb-LYaaeAACAAAAAAAAAAAAAAbgbbAKAAAAAAAAddd-AAAAAAAAcbcMLbdyYbLvYaemAAAAAAAAAAAAAAAAAAdAXbYbbZAFAAAAdXcMYcd9AAAAXXX-XXX-XXX-','No error'),(49,'a@abc.net     %%AAi<z406MABzcbdHcLbIdYb-LYaaeAACAAAAAAAAAAAAAAbgbbAKAAAAAAAAddd-AAAAAAAAcbcMLbdyYbLvYaemAAAAAAAAAAAAAAAAAYM8ONQAAZAEAAAAdXcMYcd9AAAAXXX-XXX-XXX-',''),(50,'              %%..i<z40xPABxcbdHcLbIdYb-LYaaeAACAAAAAAAAAAAAAAbgbbAKAAAAAAAAddd-AAAAAAAAcbcMLbdyYbLvYaemAAAAAAAAAAAAAAAAAYM8ONQAAZAEAAAAdXcMYcd9AAAAXXX-XXX-XXX-','No error'),(51,'a@abc.net     %%AAi<z40CMACDcbdHcLbIdYb-LYaaeAACAAAAAAAAAAAAAAbgbbAKAAAAAAAAddd-AAAAAAAAcbcMLbdyYbLvYaemAAAAAAAAAAAAAAAAAYM8ONQAAZAEAAVgabbhZMONNAAAXXX-XXX-XXX-',''),(52,'a@abc.net     %%AAi<z40mMACSACd4ddLvaeaXdcdOYcLpbZdGAAAAAAAAAAAAaZcNccAOAAAAAabkdZckbZdGAAMQOMLtNMLkNMLiNNAFAAAAALMENNLeMMMAMMaQbdZScbZadAAAaeaXdcdOYcAJAXX8XXX-',''),(53,'              %%..i<z404PACBcbdHcLbIdYb-LYaaeAACAAAAAAAAAAAAAAbgbbAKAAAAAAAAddd-AAAAAAAAcbcMLbdyYbLvYaemAAAAAAAAAAAAAAAAAYM8ONQAAZAEAAVgabbhZMONNAAAXXX-XXX-XXX-','No error'),(54,'              %%..i<z40dPACQACd4ddLvaeaXdcdOYcLpbZdGAAAAAAAAAAAAaZcNccAOAAAAAabkdZckbZdGAAMQOMLtNMLkNMLiNNAFAAAAALMENNLeMMMAMMaQbdZScbZadAAAaeaXdcdOYcAJAXX8XXX-','No error'),(55,'              %%AAi<z40WCACjAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv+QEAfyAAAAAAAAAAAAAAnAig0U3XALC-EoA2rwXogOZOM3hT8XfqY603XtAAAAAAAAAAXwXXX-XXX-XXX-XXX-XXX-XXX-XXX-',''),(56,'              %%..i<z40NFAChAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv+QEAfyAAAAAAAAAAAAAAnAig0U3XALC-EoA2rwXogOZOM3hT8XfqY603XtAAAAAAAAAAXwXXX-XXX-XXX-XXX-XXX-XXX-XXX-','No error'),(57,'d016@lwco.biz %%AAi<z40jCACzZMMQNQbCdYb-LYaaeAACAAAAAAAAAAAAAv+QEAfyZMMQNQbCdYb-LYaaeA0S3XALC-EoA2rwXogOZOM3hT8XfqY603XtAAAAAAAAAAXwXXX-XXX-XXX-XXX-XXX-XXX-XXX-',''),(58,'d016@lwco.biz %%..i<z40aFACxZMMQNQbCdYb-LYaaeAACAAAAAAAAAAAAAv+QEAfyZMMQNQbCdYb-LYaaeA0S3XALC-EoA2rwXogOZOM3hT8XfqY603XtAAAAAAAAAAXwXXX-XXX-XXX-XXX-XXX-XXX-XXX-','No error'),(59,'              %%AAi<z40KDADAgZNsACjS8AAiAAgAZNILkn8kAAAIAgZwgKNkf8AJAAACgZOcMhTf8AvCwQAHUabDedelAAVgbbbzZeYUAUb4bYblAuY4gZOcMhTf8AvCwQX3XXX-XXX-XXX-XXX-XXX-XXX-',''),(60,'d016@lwco.biz %%..i<z40BFADCgZNsACjS8AAiAAgAZNILkn8kAAAIAgZwgKNkf8AJAAACgZOcMhTf8AvCwQAHUabDedelAAVgbbbzZeYUAUb4bYblAuY4gZOcMhTf8AvCwQX3XXX-XXX-XXX-XXX-XXX-XXX-','No error'),(61,'              %%AAi<z40rDADRAADzB0ADyAAQABAEAAAQABAEAAAAAAAEAAARAAAEAAGBAGAAGAGAAEAREAAQAAAEAAABAAAEAAAAAAAAA+vE+fjPB9wAAQABAIKOAPAAAXX9XXX-XXX-XXX-XXX-XXX-XXX-',''),(62,'d016@lwco.biz %%..i<z40iFADTAADzB0ADyAAQABAEAAAQABAEAAAAAAAEAAARAAAEAAGBAGAAGAGAAEAREAAQAAAEAAABAAAEAAAAAAAAA+vE+fjPB9wAAQABAIKOAPAAAXX9XXX-XXX-XXX-XXX-XXX-XXX-','No error'),(63,'              %%AAi<z40xDADhAADzB0ADyAAQABAEBAARABAEAAAAAAAEAAARAAAEAAGBAGAAGAGAAEAREAAQAAAEAAABAAAEAAAAAAAAA+vE+fjPB9wAAQABAIKOAHAIAXX9XXX-XXX-XXX-XXX-XXX-XXX-',''),(64,'d016@lwco.biz %%..i<z40oFADjAADzB0ADyAAQABAEBAARABAEAAAAAAAEAAARAAAEAAGBAGAAGAGAAEAREAAQAAAEAAABAAAEAAAAAAAAA+vE+fjPB9wAAQABAIKOAHAIAXX9XXX-XXX-XXX-XXX-XXX-XXX-','No error'),(65,'a@abc.net     %%AAi<z400DADxAADzB0ADyAAQABAEAAAQABAEAAAAAAAEAAARAAAEAAGBAGAAGAGAAEAREAAQAAAEAAABAAAEAAAAAAAAA+vE+fjPB9wAAQABAIKOAHAIAXX9XXX-XXX-XXX-XXX-XXX-XXX-',''),(66,'d016@lwco.biz %%..i<z40sFADzAADzB0ADyAAQABAEAAAQABAEAAAAAAAEAAARAAAEAAGBAGAAGAGAAEAREAAQAAAEAAABAAAEAAAAAAAAA+vE+fjPB9wAAQABAIKOAHAIAXX9XXX-XXX-XXX-XXX-XXX-XXX-\r\n','No error'),(67,'a@abc.net     %%AAi<z400DAERAADzB0ADyAAQABAEAAARABAEAAAAAAAEAAARAAAEAAGBAGAAGAGAAEAREAAQAAAEAAABAAAEAAAAAAAAA+vE+fjPB9wAAQABAIKOAtAAAXX9XXX-XXX-XXX-XXX-XXX-XXX-',''),(68,'a@abc.net     %%..i<z411DAHRAADzB0ADyAAQABAEAAARABAEAAAAAAAEAAARAAAEAAGBAGAAGAGAAEAREAAQAAAEAAABAA-0---------+vH+fjPB9wAAQABAIKOAtAAAXX9XXX-XXX-XXX-XXX-XXX-XXX-',''),(69,'              %%AAi<z40FDAEBAADzB0ADyAAQABAEAAARABAEAAAAAAAEAAARAAAEAAGBAGAAGAGAAEAREAAQAAAEAAABAAAEAAAAAAAAAAAAAAAAAAAAAAAAAIKOAtAAAXX8XXX-XXX-XXX-XXX-XXX-XXX-','No error'),(70,'a@abc.net     %%..i<z41GMAHzcbdHcLbIdYb-LYaaeAACAAAAAAAAAAAAAAbgbbAKAAAAAAAAddd-AAAAAAAAcbcMLbdyYbLvYaemAAAAAAAAAAAAAAAAAQM8ONQEAZAEAAVgabbhZMONNAABXXX-XXX-XXX-',''),(71,'a@abc.net     %%AAi<z40OMAEzcbdHcLbIdYb-LYaaeAACAAAAAAAAAAAAAAbgbbAKAAAAAAAAddd-AAAAAAAAcbcMLbdyYbLvYaemAAAAAAAAAAAAAAAAAQM8ONQAAZAEAAVgabbhZMONNAAAXXX-XXX-XXX-',''),(72,'d016@lwco.biz %%..i<z40sFAETAADzB0ADyAAQABAEAAARABAEAAAAAAAEAAARAAAEAAGBAGAAGAGAAEAREAAQAAAEAAABAAAEAAAAAAAAA+vE+fjPB9wAAQABAIKOAtAAAXX9XXX-XXX-XXX-XXX-XXX-XXX-\r\n','No error'),(73,'d016@lwco.biz %%..i<z412FAHTAADzB0ADyAAQABAEAAARABAEAAAAAAAEAAARAAAEAAGBAGAAGAGAAEAREAAQAAAEAAABAA-0---------+vH+fjPB9wAAQABAIKOAtAAAXX9XXX-XXX-XXX-XXX-XXX-XXX-\r\n','No error'),(74,'              %%AAi<z41LMAHjcbdHcLbIdYb-LYaaeAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAcbcMLbdyYbLvYaemAAAAAAAAAAAAAAAAAQM8ONQEAAAAAAVgabbhZMONNAABXXX-XXX-XXX-','No error'),(75,'              %%AAi<z40IMAEjcbdHcLbIdYb-LYaaeAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAcbcMLbdyYbLvYaemAAAAAAAAAAAAAAAAAQM8ONQAAAAAAAVgabbhZMONNAAAXXX-XXX-XXX-','No error'),(76,'d016@lwco.biz %%..i<z41BPAHhcbdHcLbIdYb-LYaaeAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAcbcMLbdyYbLvYaemAAAAAAAAAAAAAAAAAQM8ONQEAAAAAAVgabbhZMONNAABXXX-XXX-XXX\0','No error'),(77,'d016@lwco.biz %%..i<z40-PAEhcbdHcLbIdYb-LYaaeAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAcbcMLbdyYbLvYaemAAAAAAAAAAAAAAAAAQM8ONQAAAAAAAVgabbhZMONNAAAXXX-XXX-XXX\0','No error'),(78,'a@abc.net     %%AAi<z40tDAFBAADzB0ADyAAQABAEAAARABAEAAAAAAAEAAARAAAEAAGBAGAAGAGAAEAREAAQAAAEAAABAAAEAAAAAAAAA+vE+fjPB9wAAQABADEKAtAAAXX9XXX-XXX-XXX-XXX-XXX-XXX-',''),(79,'a@abc.net     %%..i<z41yDAIRAADzB0ADyAAQABAEAAARABAEAAAAAAAEAAARAAAEAAGBAGAAGAGAAEAREAAQAAAEAAABAA-0---------+vH+fjPB9wAAQABADEKAtAAAXX9XXX-XXX-XXX-XXX-XXX-XXX-',''),(80,'d016@lwco.biz %%..i<z40kFAFDAADzB0ADyAAQABAEAAARABAEAAAAAAAEAAARAAAEAAGBAGAAGAGAAEAREAAQAAAEAAABAAAEAAAAAAAAA+vE+fjPB9wAAQABADEKAtAAAXX9XXX-XXX-XXX-XXX-XXX-XXX-\r\n','No error'),(81,'d016@lwco.biz %%..i<z41zFAITAADzB0ADyAAQABAEAAARABAEAAAAAAAEAAARAAAEAAGBAGAAGAGAAEAREAAQAAAEAAABAA-0---------+vH+fjPB9wAAQABADEKAtAAAXX9XXX-XXX-XXX-XXX-XXX-XXX\0','No error'),(82,'a@abc.net     %%..i<z41xDAIhAADzB0ADyAAQABAEAAARABAEAAAAAAAEAAARAAAEAAGBAGAAGAGAAEAREAAQAAAEAAABAA-0---------+vH+fjPB9wAAQABAB3GAtAAAXX9XXX-XXX-XXX-XXX-XXX-XXX-',''),(83,'a@abc.net     %%AAi<z40rDAFRAADzB0ADyAAQABAEAAARABAEAAAAAAAEAAARAAAEAAGBAGAAGAGAAEAREAAQAAAEAAABAAAEAAAAAAAAA+vE+fjPB9wAAQABAB3GAtAAAXX9XXX-XXX-XXX-XXX-XXX-XXX-',''),(84,'d016@lwco.biz %%..i<z41yFAIjAADzB0ADyAAQABAEAAARABAEAAAAAAAEAAARAAAEAAGBAGAAGAGAAEAREAAQAAAEAAABAA-0---------+vH+fjPB9wAAQABAB3GAtAAAXX9XXX-XXX-XXX-XXX-XXX-XXX-\r\n','No error'),(85,'d016@lwco.biz %%..i<z40iFAFTAADzB0ADyAAQABAEAAARABAEAAAAAAAEAAARAAAEAAGBAGAAGAGAAEAREAAQAAAEAAABAAAEAAAAAAAAA+vE+fjPB9wAAQABAB3GAtAAAXX9XXX-XXX-XXX-XXX-XXX-XXX-\r\n','No error'),(86,'d016@lwco.biz %%AAi<z40cCAGDZMMQNQbCdYb-LYaaeAACAAAAAAAAAAAAAT+QGAfwZMMQNQbCdYb-LYaaeA0S3XALFDNnA2rwXogOZOM3hT8nfqY603XtAAAAAAAAAAXwXXX-XXX-XXX-XXX-XXX-XXX-XXX-',''),(87,'d016@lwco.biz %%AAi<z40pCAFzZMMQNQbCdYb-LYaaeAACAAAAAAAAAAAAAT+QGAfwZMMQNQbCdYb-LYaaeA0S3XALFDNnA2rwXogOZOM3hT8nfqY603XtAAAAAAAAAAXwXXX-XXX-XXX-XXX-XXX-XXX-XXX-',''),(88,'              %%AAi<z40YDAFhAADDB3AByAAQABAEAAAQABAEAAAAAAAEAAARAAAEAAGBAGAAGAGAAEAREAAQAAAEAAABAAAEAAAAAAAAA+TE+fjPB9UAAQABAAPCAtAAAXX9XXX-XXX-XXX-XXX-XXX-XXX-',''),(89,'              %%AAi<z40SDAGRAADDB3AByAAQABAEAAAQABAEAAAAAAAEAAARAAAEAAGBAGAAGAGAAEAREAAQAAAEAAABAAAEAAAAAAAAA+TE+fjPB9UAAQABAAPCAtAAAXX9XXX-XXX-XXX-XXX-XXX-XXX-',''),(90,'              %%AAi<z40PDAGhAADDB3AByAAQABAEAAARABAEAAAAAAAEAAARAAAEAAGBAGAAGAGAAEAREAAQAAAEAAABAAAEAAAAAAAAA+TE+fjPB9UAAQABAALGAPAAAXX9XXX-XXX-XXX-XXX-XXX-XXX-',''),(91,'              %%AAi<z40TDAGxAADDB3AByAAQABAEAAARABAEAAAAAAAEAAARAAAEAAGBAGAAGAGAAEAREAAQAAAEAAABAAAEAAAAAAAAA+TE+fjPB9UAAQABAALGAPAAAXX9XXX-XXX-XXX-XXX-XXX-XXX-','');

--
-- Table structure for table `specialmessages`
--

CREATE TABLE `specialmessages` (
  `SpecMessage_ID` int(11) NOT NULL AUTO_INCREMENT,
  `DataString` char(50) DEFAULT NULL,
  `DataInteger` int(11) DEFAULT '0',
  `unixtime` char(50) DEFAULT NULL,
  `isNew` int(11) DEFAULT '0',
  PRIMARY KEY (`SpecMessage_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `specialmessages`
--


--
-- Table structure for table `state`
--

CREATE TABLE `state` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `MinValue` double NOT NULL,
  `MaxValue` double NOT NULL,
  `Title` varchar(50) NOT NULL,
  `SensorId` int(11) DEFAULT NULL,
  PRIMARY KEY (`Id`),
  KEY `State_FK` (`SensorId`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=cp1251 COMMENT='Состояния автомобиля';

--
-- Dumping data for table `state`
--

INSERT INTO `state` VALUES (1,0,0.1,'выкл.',4),(2,1,1.1,'вкл.',4),(3,0,0.1,'выкл.',5),(4,1,1.1,'вкл.',5),(5,0,0.1,'0',9),(6,1,1.1,'1',9),(7,0,0.1,'0',18),(8,1,1.1,'1',18),(9,0,0.1,'0',27),(10,1,1.1,'1',27),(11,0,0.1,'0',29),(12,1,1.1,'1',29),(13,0,0.1,'0',30),(14,1,1.1,'1',30),(15,0,0.1,'0',31),(16,1,1.1,'1',31);

--
-- Table structure for table `swupdate`
--

CREATE TABLE `swupdate` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `ShortID` char(4) NOT NULL COMMENT 'Идентификатор телетрека(логин)',
  `Soft` mediumtext NOT NULL COMMENT 'Прошивка',
  `InsertTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Дата и время вставки в таблицу',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=cp1251 COMMENT='Обновление прошивки телетрека';

--
-- Dumping data for table `swupdate`
--


--
-- Table structure for table `team`
--

CREATE TABLE `team` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `Name` varchar(50) DEFAULT NULL,
  `Descr` text COMMENT 'Описание',
  `Setting_id` int(11) DEFAULT NULL,
  `OutLinkId` varchar(20) DEFAULT NULL COMMENT 'Код внешней базы',
  `FuelWayKmGrp` double DEFAULT '0' COMMENT 'Норма расхода топлива л/100 км',
  `FuelMotoHrGrp` double DEFAULT '0' COMMENT 'Норма расхода топлива на холостом ходу л/моточас',
  PRIMARY KEY (`id`),
  UNIQUE KEY `id` (`id`) USING BTREE,
  KEY `Setting_id` (`Setting_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `team`
--

INSERT INTO `team` VALUES (1,'Авто','null',1,NULL,0,0),(2,'Трактор','null',1,NULL,0,0),(3,'Комбайн','null',1,NULL,0,0),(4,'Заправщик','null',1,NULL,0,0),(5,'Кран','null',1,NULL,0,0);

--
-- Table structure for table `telnumbers`
--

CREATE TABLE `telnumbers` (
  `TelNumber_ID` int(11) NOT NULL AUTO_INCREMENT,
  `Name` char(50) DEFAULT NULL,
  `Descr` char(200) DEFAULT NULL,
  `ID` int(11) DEFAULT '0',
  `Flags` int(11) DEFAULT '0',
  `TelNumber` char(50) DEFAULT NULL,
  PRIMARY KEY (`TelNumber_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=122 DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `telnumbers`
--

INSERT INTO `telnumbers` VALUES (56,'MNK','Телефон',0,0,'80673933874'),(57,'Телефон','Телефон',0,0,'22222222222'),(58,'Телефон','Телефон',0,0,'33333333333'),(59,'Телефон','Телефон',0,0,'44444444444'),(68,'Телефон','Телефон',0,0,'55555555555'),(71,'Телефон','',0,0,'66666666666'),(73,'9042','ID_9042',0,0,'80673620192'),(74,'2','Телефон',0,0,'80673604814'),(75,'1','',0,0,'80673632235'),(81,'RCS3','',0,0,'80637562678'),(89,'Roman','',0,0,'80678029367'),(90,'Volodya','',0,0,'80673620909'),(97,'Shlyuz','',0,0,'80673602088'),(101,'Телефон','',0,0,'1'),(102,'0918','ID_0918',0,0,'80673621991'),(103,'0685','ID_0685_PRO',0,0,'80673622209'),(104,'rcs','mtel',0,0,'+380673604814'),(105,'C385',NULL,0,0,'+3880673632235'),(106,'C384',NULL,0,0,'+3880673604814'),(107,'C384',NULL,0,0,'+380673604814'),(108,'C385',NULL,0,0,'+380673632235'),(109,'0918',NULL,0,0,'+380673621991'),(110,'0685',NULL,0,0,'+380673622209'),(111,'9042',NULL,0,0,'+380673620192'),(112,'5519',NULL,0,0,'+380981881670'),(113,'rcs','mtel',0,0,'+380981881670'),(114,'9546',NULL,0,0,'+380679247895'),(115,'rcs','mtel',0,0,'+380673632235'),(116,'rcs','mtel',0,0,'+380673621991'),(117,'rcs','mtel',0,0,'+380673622209'),(118,'rcs','mtel',0,0,'+380673620192'),(119,'rcs','mtel',0,0,'+380679247895'),(120,'5072',NULL,0,0,'+380673665681'),(121,'rcs','mtel',0,0,'+380673665681');

--
-- Table structure for table `temp`
--

CREATE TABLE `temp` (
  `datagps_id` int(10) unsigned NOT NULL DEFAULT '0',
  `sensor_id` int(10) unsigned NOT NULL DEFAULT '0',
  `Value` double(10,2) NOT NULL DEFAULT '0.00'
) ENGINE=MEMORY DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `temp`
--


--
-- Table structure for table `tmpdatagps`
--

CREATE TABLE `tmpdatagps` (
  `DataGps_ID` int(11) NOT NULL DEFAULT '0',
  `Mobitel_ID` int(11) DEFAULT '0',
  `Message_ID` int(11) DEFAULT '0',
  `Latitude` int(11) DEFAULT '0',
  `Longitude` int(11) DEFAULT '0',
  `Altitude` int(11) DEFAULT NULL,
  `UnixTime` int(11) DEFAULT '0',
  `Speed` smallint(6) DEFAULT '0',
  `Direction` int(11) NOT NULL DEFAULT '0',
  `Valid` tinyint(4) DEFAULT '1',
  `InMobitelID` int(11) DEFAULT NULL,
  `Events` int(10) unsigned DEFAULT '0',
  `Sensor1` tinyint(4) unsigned DEFAULT '0',
  `Sensor2` tinyint(4) unsigned DEFAULT '0',
  `Sensor3` tinyint(4) unsigned DEFAULT '0',
  `Sensor4` tinyint(4) unsigned DEFAULT '0',
  `Sensor5` tinyint(4) unsigned DEFAULT '0',
  `Sensor6` tinyint(4) unsigned DEFAULT '0',
  `Sensor7` tinyint(4) unsigned DEFAULT '0',
  `Sensor8` tinyint(4) unsigned DEFAULT '0',
  `LogID` int(11) DEFAULT '0',
  `isShow` tinyint(4) DEFAULT '0',
  `whatIs` smallint(6) unsigned DEFAULT '0',
  `Counter1` int(11) NOT NULL DEFAULT '-1',
  `Counter2` int(11) NOT NULL DEFAULT '-1',
  `Counter3` int(11) NOT NULL DEFAULT '-1',
  `Counter4` int(11) NOT NULL DEFAULT '-1',
  `SrvPacketID` bigint(20) NOT NULL DEFAULT '0' COMMENT 'ID серверного пакета в состав которого входит эта запись'
) ENGINE=MEMORY DEFAULT CHARSET=utf8;

--
-- Dumping data for table `tmpdatagps`
--


--
-- Table structure for table `transition`
--

CREATE TABLE `transition` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `InitialStateId` int(11) DEFAULT NULL,
  `FinalStateId` int(11) DEFAULT NULL,
  `Title` varchar(50) NOT NULL,
  `SensorId` int(11) DEFAULT NULL,
  `IconName` varchar(50) NOT NULL,
  `SoundName` varchar(50) NOT NULL,
  `Enabled` tinyint(1) NOT NULL,
  `ViewInReport` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`Id`),
  KEY `Sensors_FK` (`SensorId`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=cp1251 COMMENT='Переходы между состояниями';

--
-- Dumping data for table `transition`
--

INSERT INTO `transition` VALUES (1,1,2,'вкл.',4,'Default','Default',0,1),(2,2,1,'выкл.',4,'Default','Default',0,0),(3,3,4,'вкл.',5,'Default','Default',0,1),(4,4,3,'выкл.',5,'Default','Default',0,1),(5,5,6,'вкл.',9,'Default','Default',0,1),(6,6,5,'выкл.',9,'Default','Default',0,1),(7,7,8,'вкл.',18,'Default','Default',0,1),(8,8,7,'выкл.',18,'Default','Default',0,1),(9,9,10,'вкл.',27,'Default','Default',0,1),(10,10,9,'выкл.',27,'Default','Default',0,1),(11,11,12,'увімк.',29,'Default','Default',0,1),(12,12,11,'вимк.',29,'Default','Default',0,1),(13,13,14,'увімк.',30,'Default','Default',0,1),(14,14,13,'вимк.',30,'Default','Default',0,1),(15,15,16,'увімк.',31,'Default','Default',0,1),(16,16,15,'вимк.',31,'Default','Default',0,1);

--
-- Table structure for table `users_acs_objects`
--

CREATE TABLE `users_acs_objects` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Id_role` int(11) NOT NULL,
  `Id_type` int(11) NOT NULL,
  `Id_object` int(11) NOT NULL,
  PRIMARY KEY (`Id`),
  KEY `FK_users_acs_objects_users_acs_roles_Id` (`Id_role`),
  CONSTRAINT `FK_users_acs_objects_users_acs_roles_Id` FOREIGN KEY (`Id_role`) REFERENCES `users_acs_roles` (`Id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `users_acs_objects`
--

INSERT INTO `users_acs_objects` VALUES (1,2,3,4),(2,2,3,5),(3,2,3,6),(4,2,3,10),(5,2,3,11),(6,2,3,12),(7,2,3,13),(8,2,3,16),(9,2,3,17),(10,2,3,18),(11,2,3,21),(12,2,3,22),(13,2,3,26),(14,2,3,27),(15,2,3,28),(16,2,3,29),(17,2,3,30),(18,2,3,31),(19,2,3,32),(20,2,3,33);

--
-- Table structure for table `users_acs_roles`
--

CREATE TABLE `users_acs_roles` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Name` varchar(255) NOT NULL,
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `users_acs_roles`
--

INSERT INTO `users_acs_roles` VALUES (1,'Администратор'),(2,'gemini');

--
-- Table structure for table `users_actions_log`
--

CREATE TABLE `users_actions_log` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `TypeLog` int(11) NOT NULL DEFAULT '0',
  `DateAction` datetime NOT NULL,
  `Id_document` int(11) NOT NULL DEFAULT '0',
  `TextLog` varchar(255) NOT NULL,
  `User` varchar(127) NOT NULL,
  `Computer` varchar(63) NOT NULL,
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `users_actions_log`
--

INSERT INTO `users_actions_log` VALUES (1,6,'2016-12-15 15:19:39',354,'Удаление','admin','ROMAGEMINI'),(2,8,'2017-10-19 17:26:05',0,'70->90 Максимальная скорость движения, км/ч','admin','MNK'),(3,8,'2018-03-20 18:36:20',0,'25->4 Полоса сглаживания','admin','MNK'),(4,8,'2018-03-20 18:36:20',0,'50->20 Порог заправки','admin','MNK'),(5,8,'2018-03-20 18:36:20',0,'0->1 Не учитывать сливы в расходе','admin','MNK'),(6,9,'2018-03-20 18:39:33',16,'Вход','admin','MNK'),(7,9,'2018-03-20 18:39:36',16,'Загрузить','admin','MNK'),(8,9,'2018-03-20 18:40:03',17,'Вход','admin','MNK'),(9,9,'2018-03-20 18:40:05',17,'Загрузить','admin','MNK'),(10,9,'2018-05-31 17:20:54',24,'Вход','admin','MNK'),(11,9,'2018-05-31 17:20:55',24,'Загрузить','admin','MNK'),(12,9,'2018-05-31 17:21:06',25,'Вход','admin','MNK'),(13,9,'2018-05-31 17:21:08',25,'Загрузить','admin','MNK');

--
-- Table structure for table `users_list`
--

CREATE TABLE `users_list` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Name` varchar(255) NOT NULL,
  `WinLogin` varchar(50) DEFAULT NULL,
  `Password` blob NOT NULL,
  `Admin` tinyint(1) NOT NULL DEFAULT '0',
  `Id_role` int(11) DEFAULT '0' COMMENT 'Код роли пользователя',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `users_list`
--

INSERT INTO `users_list` VALUES (1,'Администратор',NULL,_binary '�e�Y B/�A~Hg\�\�O��J?��~������z\�',1,1),(2,'gemini','',_binary '�e�Y B/�A~Hg\�\�O��J?��~������z\�',0,2);

--
-- Table structure for table `users_reports_list`
--

CREATE TABLE `users_reports_list` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `ReportType` varchar(127) NOT NULL,
  `ReportCaption` varchar(127) NOT NULL,
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `users_reports_list`
--

INSERT INTO `users_reports_list` VALUES (1,'KilometrageC','Пробег'),(2,'KilometrageDay','Пробег суточный'),(3,'KilometrageTotal','Пробег общий'),(4,'FuelControl','Заправки'),(5,'DevFuelExpensesCtrlDutDay','Топливо суточный ДУТ'),(6,'DevFuelExpensesCtrlDut','Общий расход ДУТ'),(7,'DevFlowmeterCntrl','Расход'),(8,'DevFuelExpensesCntrlDrt','Общий расход ДРТ'),(9,'DevRoadSafetyCtrl','Безопасность'),(10,'DevParamOfMovingCtrl','Параметры движения'),(11,'DevCzDetailed','КЗ Детальный'),(12,'DevFuelCZ_Inkom_DRT','ДРТ - КЗ'),(13,'DevFuelCZ_Inkom_DUT','ДУТ - КЗ'),(14,'SensorEventsControl','События датчиков'),(15,'RotationControl','Обороты'),(16,'PassTrafficDaily','Пассажиры суточный'),(17,'FuelerControlDrt','Заправщик'),(18,'ReportDrivers','Водители (RFID)'),(19,'KilometrageControl','Пробег'),(20,'KilometrageDayControl','Пробег суточный'),(21,'FuelExpensesControlDutDay','Топливо суточный ДУТ'),(22,'FuelExpensesControlDut','Общий расход ДУТ'),(23,'FlowmeterControl','Расход'),(24,'FuelExpensesControlDrt','Общий расход ДРТ'),(25,'RoadSafetyControl','Безопасность'),(26,'ParamOfMovingControl','Параметры движения'),(27,'CzDetailed','КЗ Детальный'),(28,'FuelCZ_Inkom_DRT','ДРТ - КЗ'),(29,'FuelCZ_Inkom_DUT','ДУТ - КЗ'),(30,'CZ_Detailed_General','КЗ Групповой'),(31,'GrainLevel','Уровень зерна'),(32,'KilometrageControlDut','Пробег+ДУТ'),(33,'ReportVehicles','Идентификация ТС'),(34,'FuelControlOnes','Заправки (раздельные ДУТ)');

--
-- Table structure for table `vehicle`
--

CREATE TABLE `vehicle` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `MakeCar` text COMMENT 'Марка автомобиля',
  `NumberPlate` text COMMENT 'Номерной знак',
  `Team_id` int(11) DEFAULT NULL,
  `Mobitel_id` int(11) DEFAULT NULL,
  `Odometr` int(11) DEFAULT '0' COMMENT 'Показания одометра',
  `CarModel` text COMMENT 'Модель',
  `setting_id` int(11) DEFAULT '1',
  `odoTime` datetime DEFAULT NULL COMMENT 'Дата и время сверки одометра',
  `driver_id` int(11) DEFAULT '-1',
  `OutLinkId` varchar(20) DEFAULT NULL COMMENT 'Код внешней базы',
  `Category_id` int(11) DEFAULT NULL COMMENT 'Категория транспортая',
  `Category_id2` int(11) DEFAULT NULL COMMENT 'Категория2 транспорта',
  `PcbVersionId` int(11) DEFAULT '-1' COMMENT 'Версия плат датчика назначенная на машину',
  `FuelWayLiter` double DEFAULT '0' COMMENT 'Расход топлива л/100 км',
  `FuelMotorLiter` double DEFAULT '0' COMMENT 'Расход топлива л/моточас',
  `Identifier` int(11) DEFAULT '0' COMMENT 'Идентификатор машины',
  `Category_id3` int(11) DEFAULT NULL COMMENT 'Категория3 транспорта',
  `Category_id4` int(11) DEFAULT NULL COMMENT 'Категория4 транспорта',
  PRIMARY KEY (`id`),
  UNIQUE KEY `id` (`id`) USING BTREE,
  KEY `Mobitel_id` (`Mobitel_id`) USING BTREE,
  KEY `Team_id` (`Team_id`) USING BTREE,
  KEY `setting_id` (`setting_id`) USING BTREE,
  KEY `FK_vehicle_vehicle_category_Id` (`Category_id`),
  KEY `FK_vehicle_vehicle_category_Id2` (`Category_id2`),
  KEY `FK_vehicle_vehicle_category_Id3` (`Category_id3`),
  KEY `FK_vehicle_vehicle_category_Id4` (`Category_id4`),
  CONSTRAINT `FK_vehicle_vehicle_category_Id` FOREIGN KEY (`Category_id`) REFERENCES `vehicle_category` (`Id`),
  CONSTRAINT `FK_vehicle_vehicle_category_Id2` FOREIGN KEY (`Category_id2`) REFERENCES `vehicle_category2` (`Id`),
  CONSTRAINT `FK_vehicle_vehicle_category_Id3` FOREIGN KEY (`Category_id3`) REFERENCES `vehicle_category3` (`Id`),
  CONSTRAINT `FK_vehicle_vehicle_category_Id4` FOREIGN KEY (`Category_id4`) REFERENCES `vehicle_category4` (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `vehicle`
--

INSERT INTO `vehicle` VALUES (1,'Пежо_3','BK 9079 AO',1,97,0,'',1,NULL,1,'',NULL,NULL,-1,0,0,0,NULL,NULL),(2,'Пежо_1','BK 7245 ВО',1,98,0,'',1,NULL,1,'',NULL,NULL,-1,0,0,0,NULL,NULL),(3,'Mersedes','BK 6483 BH',1,99,0,'',1,NULL,1,'',NULL,NULL,-1,0,0,0,NULL,NULL),(4,'Пежо_2','BK 8639 BC',1,100,0,'',1,NULL,1,'',NULL,NULL,-1,0,0,0,NULL,NULL),(5,'Пежо_4','BK 5897 BM',1,101,0,'',1,NULL,1,'',NULL,NULL,-1,6,0,0,NULL,NULL),(6,'Пежо_5','BK 7142 CA',1,102,0,'',1,NULL,1,'',NULL,NULL,6,0,0,0,NULL,NULL),(7,'Пежо_6','BK 0471 CB',1,103,0,'',1,NULL,1,'',NULL,NULL,6,0,0,0,NULL,NULL),(8,'Пежо_7','BK 0668 CO',1,104,0,'',1,NULL,1,'',NULL,NULL,7,0,0,0,NULL,NULL);

--
-- Table structure for table `vehicle_category`
--

CREATE TABLE `vehicle_category` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Name` varchar(50) NOT NULL COMMENT 'Категория транспортного средства',
  `Tonnage` decimal(10,3) NOT NULL DEFAULT '0.000' COMMENT 'Грузоподъемность,  тонн',
  `FuelNormMoving` double NOT NULL DEFAULT '0' COMMENT 'норма расхода топлива в движении л/100 км',
  `FuelNormParking` double NOT NULL DEFAULT '0' COMMENT 'норма расхода топлива на холостых оборотах л/час',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `vehicle_category`
--


--
-- Table structure for table `vehicle_category2`
--

CREATE TABLE `vehicle_category2` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Name` varchar(255) NOT NULL COMMENT 'Категория2 транспортного средства',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `vehicle_category2`
--


--
-- Table structure for table `vehicle_category3`
--

CREATE TABLE `vehicle_category3` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Name` varchar(255) NOT NULL COMMENT 'Категория3 транспортного средства',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `vehicle_category3`
--


--
-- Table structure for table `vehicle_category4`
--

CREATE TABLE `vehicle_category4` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Name` varchar(255) NOT NULL COMMENT 'Категория4 транспортного средства',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `vehicle_category4`
--


--
-- Table structure for table `vehicle_commentary`
--

CREATE TABLE `vehicle_commentary` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Comment` varchar(255) DEFAULT NULL,
  `Mobitel_id` int(11) NOT NULL,
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=cp1251 COMMENT='Комментарий для машины';

--
-- Dumping data for table `vehicle_commentary`
--


--
-- Table structure for table `ver`
--

CREATE TABLE `ver` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `Num` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Номер текущей сборки БД',
  `Desc` text NOT NULL COMMENT 'Описание текущей сборки БД',
  `time` datetime DEFAULT NULL COMMENT 'Время обновления',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `ver`
--

INSERT INTO `ver` VALUES (1,1,'Сборка от 9.12.2008','2008-12-09 00:00:00'),(2,2,'Сборка от 10.02.2009','2009-02-10 00:00:00');

--
-- Table structure for table `zone_category`
--

CREATE TABLE `zone_category` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Name` varchar(255) DEFAULT NULL COMMENT 'Категория зоны',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=cp1251 COMMENT='Категории для зон';

--
-- Dumping data for table `zone_category`
--


--
-- Table structure for table `zone_category2`
--

CREATE TABLE `zone_category2` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Name` varchar(255) DEFAULT NULL COMMENT 'Категория2 зоны',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=cp1251 COMMENT='Категории2 для зон';

--
-- Dumping data for table `zone_category2`
--


--
-- Table structure for table `zonerelations`
--

CREATE TABLE `zonerelations` (
  `ZoneRelation_ID` int(11) NOT NULL AUTO_INCREMENT,
  `Zone_ID` int(11) DEFAULT '0',
  `ConfigZoneSet_ID` int(11) DEFAULT '0',
  `In_flag` tinyint(4) NOT NULL DEFAULT '0',
  `Out_flag` tinyint(4) NOT NULL DEFAULT '0',
  `In_flag2` tinyint(4) NOT NULL DEFAULT '0',
  `Out_flag2` tinyint(4) NOT NULL DEFAULT '0',
  PRIMARY KEY (`ZoneRelation_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=222 DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `zonerelations`
--

INSERT INTO `zonerelations` VALUES (220,78,248,1,0,0,0),(221,78,249,1,0,0,0);

--
-- Table structure for table `zones`
--

CREATE TABLE `zones` (
  `Zone_ID` int(11) NOT NULL AUTO_INCREMENT,
  `Name` char(50) DEFAULT NULL,
  `Descr` text,
  `ID` int(11) DEFAULT '0',
  `Status` tinyint(4) DEFAULT '0',
  `Square` double(14,5) DEFAULT '0.00000' COMMENT 'Площадь контрольной зоны',
  `ZoneColor` int(11) DEFAULT '0' COMMENT 'Цвет контрольной зоны',
  `TextColor` int(11) DEFAULT '0' COMMENT 'Цвет подписи контрольной зоны',
  `TextFontName` char(50) DEFAULT 'Microsoft Sans Serif' COMMENT 'Шрирфт подписи контрольной зоны',
  `TextFontSize` double(5,2) DEFAULT '25.00' COMMENT 'Размер шрирфта подписи контрольной зоны',
  `TextFontParams` char(8) DEFAULT '0;0;0;0;' COMMENT 'Параметры шрирфта подписи контрольной зоны',
  `Icon` blob COMMENT 'Иконка контрольной зоны',
  `HatchStyle` int(11) DEFAULT '0' COMMENT 'Текстура контрольной зоны',
  `DateCreate` datetime DEFAULT NULL COMMENT 'Дата создания',
  `Id_main` int(11) DEFAULT '0' COMMENT 'Ссылка на элемент верхнего уровня в иерархии',
  `Level` tinyint(4) DEFAULT '1' COMMENT 'Уровень в иерархии',
  `StyleId` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'ID стиля зоны',
  `ZonesGroupId` int(10) unsigned NOT NULL DEFAULT '1' COMMENT 'ID Группы зон',
  `OutLinkId` varchar(20) DEFAULT NULL COMMENT 'Код внешней базы',
  `Category_id` int(11) DEFAULT NULL COMMENT 'Категория для зоны',
  `Category_id2` int(11) DEFAULT NULL COMMENT 'Категория2 для зоны',
  PRIMARY KEY (`Zone_ID`),
  KEY `FK_zones_zonesgroup` (`ZonesGroupId`),
  CONSTRAINT `FK_zones_zonesgroup` FOREIGN KEY (`ZonesGroupId`) REFERENCES `zonesgroup` (`Id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=521 DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `zones`
--

INSERT INTO `zones` VALUES (9,'Дом','',0,1,0.18000,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-06-22 10:53:52',0,2,0,1,NULL,NULL,NULL),(13,'Анастасія','',0,1,0.00530,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-06-29 11:41:01',0,2,0,1,NULL,NULL,NULL),(15,'Затишок','',0,1,0.04010,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-06-29 16:50:30',0,2,0,1,NULL,NULL,NULL),(16,'САТ','',0,1,0.00250,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-05 09:38:59',0,2,0,1,NULL,NULL,NULL),(19,'Чемпіон','',0,1,0.00370,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-05 09:47:38',0,2,0,1,NULL,NULL,NULL),(23,'Дикий','',0,1,0.00670,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-05 17:52:19',0,2,0,1,NULL,NULL,NULL),(24,'Віліс','',0,1,0.00350,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-05 17:57:57',0,2,0,1,NULL,NULL,NULL),(33,'Газ на млинівській','',0,1,0.00250,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-06 13:53:09',0,2,0,1,NULL,NULL,NULL),(34,'Автовокзал','',0,1,0.04600,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-06 13:54:20',0,2,0,1,NULL,NULL,NULL),(37,'Магніт','',0,1,0.00720,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-06 14:01:41',0,2,0,1,NULL,NULL,NULL),(42,'Пивна Лавка','',0,1,0.00840,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-06 14:14:56',0,2,0,1,NULL,NULL,NULL),(43,'Акорд-С + Інсайт','',0,1,0.00430,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-06 14:17:12',0,2,0,1,NULL,NULL,NULL),(44,'Мийка Луцьк','',0,1,0.01380,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-06 14:22:54',0,2,0,1,NULL,NULL,NULL),(47,'Мийка Лівіт Луцьк','',0,1,0.00510,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-06 14:25:39',0,2,0,1,NULL,NULL,NULL),(52,'Зор.Еделю Луцьк','',0,1,0.01180,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-06 14:34:46',0,2,0,1,NULL,NULL,NULL),(56,'Вітко','',0,1,0.01110,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-06 14:59:38',0,2,0,1,NULL,NULL,NULL),(58,'АПК Зоря','',0,1,0.00060,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-06 15:02:14',0,2,0,1,NULL,NULL,NULL),(62,'Ніка Клевань','',0,1,0.00290,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-06 15:35:23',0,2,0,1,NULL,NULL,NULL),(63,'Каприз Клевань','',0,1,0.00090,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-06 15:36:05',0,2,0,1,NULL,NULL,NULL),(64,'Гост.Двір Тростянець','',0,1,0.44000,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-06 15:53:27',0,2,0,1,NULL,NULL,NULL),(65,'Вулик Колки','',0,1,0.10000,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-06 15:54:58',0,2,0,1,NULL,NULL,NULL),(66,'Журавл.Манев.','',0,1,0.02830,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-06 15:59:36',0,2,0,1,NULL,NULL,NULL),(68,'Оскар Манев.','',0,1,0.00730,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-06 16:04:33',0,2,0,1,NULL,NULL,NULL),(69,'Хортиця Манев.','',0,1,0.00400,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-06 16:06:45',0,2,0,1,NULL,NULL,NULL),(70,'Корчма Манев.','',0,1,0.00130,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-06 16:07:30',0,2,0,1,NULL,NULL,NULL),(71,'Ластівка Колки','',0,1,0.01250,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-06 16:14:16',0,2,0,1,NULL,NULL,NULL),(76,'Ярмарок','',0,1,0.01270,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-06 16:46:10',0,2,0,1,NULL,NULL,NULL),(77,'Міськрада','',0,1,0.00480,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-06 17:30:34',0,2,0,1,NULL,NULL,NULL),(78,'Коз.Двір Луцьк','',0,1,0.00100,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-07 11:40:46',0,2,0,1,NULL,NULL,NULL),(81,'Невже Костопіль','',0,1,0.01440,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-07 12:43:29',0,2,0,1,NULL,NULL,NULL),(82,'АГНКС Костопіль','',0,1,0.01730,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-07 12:44:12',0,2,0,1,NULL,NULL,NULL),(83,'101км Луцьк','',0,1,0.00090,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-07 12:51:20',0,2,0,1,NULL,NULL,NULL),(84,'Лагуна Клевань','',0,1,0.00240,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-07 12:53:50',0,2,0,1,NULL,NULL,NULL),(85,'Червона Калина','',0,1,1.99000,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-07 12:55:28',0,2,0,1,NULL,NULL,NULL),(87,'50/50 Луцьк','',0,1,0.01030,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-07 13:01:04',0,2,0,1,NULL,NULL,NULL),(89,'Зелений Гай','',0,1,0.79000,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-07 13:16:46',0,2,0,1,NULL,NULL,NULL),(91,'Лагуна Сарни','',0,1,0.00180,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-08 17:14:34',0,2,0,1,NULL,NULL,NULL),(93,'Мийка Сарни','',0,1,0.00130,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-08 17:16:59',0,2,0,1,NULL,NULL,NULL),(98,'Яринівка Сарни','',0,1,0.00640,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-08 17:27:54',0,2,0,1,NULL,NULL,NULL),(99,'Рута Березне','',0,1,0.00490,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-08 17:29:33',0,2,0,1,NULL,NULL,NULL),(102,'Случ Березне','',0,1,0.00220,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-08 17:47:35',0,2,0,1,NULL,NULL,NULL),(103,'В Десятку Березне','',0,1,0.00620,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-08 17:48:39',0,2,0,1,NULL,NULL,NULL),(104,'Піцерія+ КГХ Березне','',0,1,0.00680,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-08 17:50:02',0,2,0,1,NULL,NULL,NULL),(110,'Віват','',0,1,0.00390,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-13 12:30:56',0,2,0,1,NULL,NULL,NULL),(113,'Тойота','',0,1,0.00610,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-13 12:43:03',0,2,0,1,NULL,NULL,NULL),(115,'Вулик Луцьк','',0,1,0.03290,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-13 13:03:44',0,2,0,1,NULL,NULL,NULL),(116,'Міні Маркет','',0,1,0.00550,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-13 13:06:52',0,2,0,1,NULL,NULL,NULL),(117,'Рівень 2','',0,1,0.00160,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-13 13:12:23',0,2,0,1,NULL,NULL,NULL),(119,'Ковчег','',0,1,0.00780,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-13 13:21:35',0,2,0,1,NULL,NULL,NULL),(122,'Фонтан Славута','',0,1,0.01150,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-13 13:25:44',0,2,0,1,NULL,NULL,NULL),(127,'Привільне База','',0,1,0.12000,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-14 17:33:20',0,2,0,1,NULL,NULL,NULL),(128,'Курьєр','',0,1,0.00350,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-20 09:59:49',0,2,0,1,NULL,NULL,NULL),(131,'Євро','',0,1,0.01640,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-20 10:13:37',0,2,0,1,NULL,NULL,NULL),(132,'Зустріч','',0,1,0.01310,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-20 10:16:07',0,2,0,1,NULL,NULL,NULL),(133,'Трансметал','',0,1,0.01880,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-20 10:17:56',0,2,0,1,NULL,NULL,NULL),(134,'Е-40','',0,1,0.22000,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-20 10:19:27',0,2,0,1,NULL,NULL,NULL),(135,'Мийка Новоград','',0,1,0.03300,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-20 10:20:08',0,2,0,1,NULL,NULL,NULL),(136,'Дарія Новоград','',0,1,0.08650,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-20 10:21:25',0,2,0,1,NULL,NULL,NULL),(137,'Крамниця Луцьк','',0,1,0.09320,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-27 16:21:19',0,2,0,1,NULL,NULL,NULL),(138,'Едем Кременець','',0,1,0.03220,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-29 09:41:56',0,2,0,1,NULL,NULL,NULL),(139,'Гост.Двір 2 Кременець','',0,1,0.00840,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-29 09:42:49',0,2,0,1,NULL,NULL,NULL),(140,'Рутенія Кременець','',0,1,0.02170,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-29 09:44:15',0,2,0,1,NULL,NULL,NULL),(141,'Гост.Двір Кременець','',0,1,0.00420,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-29 09:47:42',0,2,0,1,NULL,NULL,NULL),(142,'АЗС ОМІ','',0,1,0.01020,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-29 09:52:13',0,2,0,1,NULL,NULL,NULL),(143,'Діана Костопіль','',0,1,0.00530,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-29 10:00:04',0,2,0,1,NULL,NULL,NULL),(145,'Сапфір','',0,1,0.20000,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-29 10:15:41',0,2,0,1,NULL,NULL,NULL),(147,'Еліт Кузнецовськ','',0,1,0.01080,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-29 10:29:59',0,2,0,1,NULL,NULL,NULL),(148,'Журавлина Кузнецовськ','',0,1,0.05670,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-29 10:31:27',0,2,0,1,NULL,NULL,NULL),(149,'Янтар Кузнецовськ','',0,1,0.00500,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-29 10:33:11',0,2,0,1,NULL,NULL,NULL),(150,'Файна Окрайна','',0,1,0.00240,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-29 10:41:05',0,2,0,1,NULL,NULL,NULL),(151,'Шатер Луцьк','',0,1,0.00380,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-29 10:43:08',0,2,0,1,NULL,NULL,NULL),(152,'Сх.Експрес Луцьк','',0,1,0.00630,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-29 10:45:20',0,2,0,1,NULL,NULL,NULL),(153,'Від ковбаски  Луцьк','',0,1,0.00560,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-29 10:47:01',0,2,0,1,NULL,NULL,NULL),(154,'Норд','',0,1,0.00430,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-29 11:26:59',0,2,0,1,NULL,NULL,NULL),(155,'Явір Луцьк','',0,1,0.14000,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-30 10:20:38',0,2,0,1,NULL,NULL,NULL),(156,'Сузірья Колки','',0,1,0.00060,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-30 10:22:05',0,2,0,1,NULL,NULL,NULL),(158,'Кемпінг Маневичі','',0,1,0.04750,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-30 10:23:57',0,2,0,1,NULL,NULL,NULL),(161,'Камелія Маневичі','',0,1,0.00110,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-30 10:26:56',0,2,0,1,NULL,NULL,NULL),(162,'Околиця Маневичі','',0,1,0.05220,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-30 10:31:44',0,2,0,1,NULL,NULL,NULL),(163,'Криничка Маневичі','',0,1,0.00280,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-30 10:33:14',0,2,0,1,NULL,NULL,NULL),(164,'Кавуся Горбаків','',0,1,0.01420,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-30 10:37:32',0,2,0,1,NULL,NULL,NULL),(165,'Азс Маршал Корець','',0,1,0.05720,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-30 10:38:21',0,2,0,1,NULL,NULL,NULL),(169,'Транзіт + Форнетті','',0,1,0.00900,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-30 10:46:06',0,2,0,1,NULL,NULL,NULL),(172,'Перлина Новоград','',0,1,0.00350,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-30 10:50:38',0,2,0,1,NULL,NULL,NULL),(173,'Радуга Новоград','',0,1,0.03350,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-30 10:51:32',0,2,0,1,NULL,NULL,NULL),(176,'Світ Продуктів Новоград','',0,1,0.00610,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-30 11:01:56',0,2,0,1,NULL,NULL,NULL),(179,'Гольфстрім Новоград','',0,1,0.02090,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-30 11:04:43',0,2,0,1,NULL,NULL,NULL),(180,'ПП Шапран Новоград','',0,1,0.00320,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-30 11:05:38',0,2,0,1,NULL,NULL,NULL),(181,'Гарячі Страви Гоща','',0,1,0.01490,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-30 11:07:39',0,2,0,1,NULL,NULL,NULL),(182,'Парус Обарів','',0,1,0.01610,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-30 11:09:59',0,2,0,1,NULL,NULL,NULL),(183,'Макс','',0,1,0.00250,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-07-30 11:11:16',0,2,0,1,NULL,NULL,NULL),(186,'Пивзавод Офіс','',0,1,0.00270,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-08-04 10:10:43',0,2,0,1,NULL,NULL,NULL),(187,'Акватон','',0,1,0.00440,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-08-04 10:12:25',0,2,0,1,NULL,NULL,NULL),(189,'Десна Березне','',0,1,0.02570,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-08-05 09:46:20',0,2,0,1,NULL,NULL,NULL),(190,'Млин Дубровиця','',0,1,0.00410,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-08-05 09:50:11',0,2,0,1,NULL,NULL,NULL),(191,'Імпульс Броди','',0,1,0.02270,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-08-05 09:59:24',0,2,0,1,NULL,NULL,NULL),(192,'Сосн. Бір Броди','',0,1,0.00250,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-08-05 10:00:12',0,2,0,1,NULL,NULL,NULL),(193,'Експрес Броди','',0,1,0.00300,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-08-05 10:05:37',0,2,0,1,NULL,NULL,NULL),(194,'Голда Броди','',0,1,0.00440,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-08-05 10:06:58',0,2,0,1,NULL,NULL,NULL),(196,'Мисливець Радивилів','',0,1,0.00760,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-08-05 10:09:00',0,2,0,1,NULL,NULL,NULL),(197,'Галичина Радивилів','',0,1,0.00130,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-08-05 10:09:49',0,2,0,1,NULL,NULL,NULL),(199,'Вікторія Дубно','',0,1,0.01360,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-08-05 10:19:58',0,2,0,1,NULL,NULL,NULL),(201,'Мар*яна Дубно','',0,1,0.05930,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-08-05 10:21:47',0,2,0,1,NULL,NULL,NULL),(202,'Продукти КХП Дубно','',0,1,0.00970,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-08-05 10:22:17',0,2,0,1,NULL,NULL,NULL),(203,'Бістро Дубрівка','',0,1,0.00040,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-08-05 10:23:22',0,2,0,1,NULL,NULL,NULL),(205,'Козацький Дубно','',0,1,0.01350,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-08-05 10:25:45',0,2,0,1,NULL,NULL,NULL),(207,'Паненський Дубно','',0,1,0.03570,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-08-06 12:16:27',0,2,0,1,NULL,NULL,NULL),(208,'Вогник Дубно','',0,1,0.00110,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-08-06 12:17:23',0,2,0,1,NULL,NULL,NULL),(217,'Рівень 1','',0,1,0.00370,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-01 09:01:18',0,2,0,1,NULL,NULL,NULL),(220,'Мехзавод Дукбно','',0,1,0.00480,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-01 09:07:37',0,2,0,1,NULL,NULL,NULL),(223,'Юлена Дубно','',0,1,0.03440,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-01 10:11:37',0,2,0,1,NULL,NULL,NULL),(224,'РОМ','',0,1,0.00410,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-01 12:08:12',0,2,0,1,NULL,NULL,NULL),(225,'Офіс','',0,1,0.00870,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-01 12:10:24',0,2,0,1,NULL,NULL,NULL),(227,'Мисливець Ковель','',0,1,0.00560,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-01 12:14:06',0,2,0,1,NULL,NULL,NULL),(228,'Реноме Ковель','',0,1,0.00600,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-01 12:15:08',0,2,0,1,NULL,NULL,NULL),(229,'Текіла Ковель','',0,1,0.00660,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-01 12:18:37',0,2,0,1,NULL,NULL,NULL),(230,'Флінт Млинів','',0,1,0.01050,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-01 14:45:00',0,2,0,1,NULL,NULL,NULL),(232,'Анастася','',0,1,0.00480,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-01 15:35:17',0,2,0,1,NULL,NULL,NULL),(234,'Асторія Костопіль','',0,1,0.01590,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-02 08:47:02',0,2,0,1,NULL,NULL,NULL),(235,'Колиба Костопіль','',0,1,0.28000,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-02 08:49:29',0,2,0,1,NULL,NULL,NULL),(236,'Гопак Костопіль','',0,1,0.16000,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-02 08:50:00',0,2,0,1,NULL,NULL,NULL),(237,'Мандарин Костопіль','',0,1,0.01830,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-02 08:50:29',0,2,0,1,NULL,NULL,NULL),(239,'Зірне','',0,1,0.64000,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-02 08:52:10',0,2,0,1,NULL,NULL,NULL),(240,'Соланж Березне','',0,1,0.00280,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-02 08:55:32',0,2,0,1,NULL,NULL,NULL),(241,'Радіозавод','',0,1,0.02470,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-02 16:09:59',0,2,0,1,NULL,NULL,NULL),(243,'Бахус','',0,1,0.00130,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-02 16:13:53',0,2,0,1,NULL,NULL,NULL),(245,'Катрін','',0,1,0.00190,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-03 15:12:26',0,2,0,1,NULL,NULL,NULL),(246,'Аромати кави','',0,1,0.00100,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-03 15:14:09',0,2,0,1,NULL,NULL,NULL),(247,'ОГО','',0,1,0.00760,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-03 15:15:34',0,2,0,1,NULL,NULL,NULL),(248,'Інсеко','',0,1,0.05480,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-03 15:17:16',0,2,0,1,NULL,NULL,NULL),(249,'Наша Україна','',0,1,0.00270,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-03 15:18:32',0,2,0,1,NULL,NULL,NULL),(250,'Кармен Клевань','',0,1,0.00250,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-07 14:20:14',0,2,0,1,NULL,NULL,NULL),(251,'Ощадбанк','',0,1,0.00190,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-07 14:23:19',0,2,0,1,NULL,NULL,NULL),(252,'Фортем','',0,1,0.01620,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-07 14:24:49',0,2,0,1,NULL,NULL,NULL),(253,'Діоніс Здолбунів','',0,1,0.00760,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-07 14:31:22',0,2,0,1,NULL,NULL,NULL),(256,'Алькатрас Нетішин','',0,1,0.01130,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-07 14:33:40',0,2,0,1,NULL,NULL,NULL),(257,'Велес Нетішин','',0,1,0.01780,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-07 14:34:19',0,2,0,1,NULL,NULL,NULL),(260,'Нон-Стоп Нетішин','',0,1,0.00410,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-07 14:36:43',0,2,0,1,NULL,NULL,NULL),(261,'Корчма Славута','',0,1,0.00250,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-07 14:37:49',0,2,0,1,NULL,NULL,NULL),(262,'Корчма Нетішин','',0,1,0.03290,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-08 09:15:12',0,2,0,1,NULL,NULL,NULL),(264,'Валюша Здолбунів','',0,1,0.05740,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-08 09:35:05',0,2,0,1,NULL,NULL,NULL),(265,'Щербаков','',0,1,0.02660,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-08 09:35:41',0,2,0,1,NULL,NULL,NULL),(266,'Асторія Здолбунів','',0,1,0.00260,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-08 09:37:49',0,2,0,1,NULL,NULL,NULL),(267,'Ромашка Костопіль','',0,1,0.00510,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-09 09:14:46',0,2,0,1,NULL,NULL,NULL),(268,'Міраж Сарни','',0,1,0.00710,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-09 09:19:24',0,2,0,1,NULL,NULL,NULL),(269,'Кулінарія Сарни','',0,1,0.11000,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-09 09:22:05',0,2,0,1,NULL,NULL,NULL),(270,'КГХ Володимирець','',0,1,0.03430,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-09 09:24:01',0,2,0,1,NULL,NULL,NULL),(271,'Віденська Володимирець','',0,1,0.06080,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-09 09:26:17',0,2,0,1,NULL,NULL,NULL),(272,'Кури Гриль Кузнецовськ','',0,1,0.03380,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-09 09:27:46',0,2,0,1,NULL,NULL,NULL),(273,'Асторія Кузнецовськ','',0,1,0.01520,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-09 09:28:38',0,2,0,1,NULL,NULL,NULL),(274,'Полиці','',0,1,0.00270,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-09 09:30:07',0,2,0,1,NULL,NULL,NULL),(276,'Бістро','',0,1,0.00060,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-09 09:37:26',0,2,0,1,NULL,NULL,NULL),(277,'Медколедж Дубно','',0,1,0.00070,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-09 09:38:27',0,2,0,1,NULL,NULL,NULL),(278,'Солодкий Дім Дубно','',0,1,0.02830,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-09 09:40:08',0,2,0,1,NULL,NULL,NULL),(281,'Колос Кременець','',0,1,0.00630,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-09 09:44:04',0,2,0,1,NULL,NULL,NULL),(282,'Анастасія Кременець','',0,1,0.01800,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-09 09:45:09',0,2,0,1,NULL,NULL,NULL),(283,'Не Минай','',0,1,0.00490,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-09 09:46:24',0,2,0,1,NULL,NULL,NULL),(284,'Кристал Дубно','',0,1,0.11000,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-09 09:47:58',0,2,0,1,NULL,NULL,NULL),(286,'Автобазар Новоград','',0,1,0.48000,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-10 17:51:51',0,2,0,1,NULL,NULL,NULL),(287,'Журавичі','',0,1,0.12000,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-14 12:56:57',0,2,0,1,NULL,NULL,NULL),(288,'Бет','',0,1,0.00210,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-14 14:52:06',0,2,0,1,NULL,NULL,NULL),(289,'Фенікс Млинів','',0,1,0.03940,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-16 09:07:11',0,2,0,1,NULL,NULL,NULL),(290,'Журавлина Млинів','',0,1,0.01690,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-16 09:08:06',0,2,0,1,NULL,NULL,NULL),(291,'Три Сестри','',0,1,0.01180,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-16 09:17:01',0,2,0,1,NULL,NULL,NULL),(292,'Сурмичі','',0,1,0.00270,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-16 09:21:38',0,2,0,1,NULL,NULL,NULL),(293,'Олеся Сарни','',0,1,0.06850,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-16 09:25:27',0,2,0,1,NULL,NULL,NULL),(294,'0-24 Гоща','',0,1,0.00420,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-17 09:42:09',0,2,0,1,NULL,NULL,NULL),(295,'Дом .Кухня Нетішин','',0,1,0.00960,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-21 09:16:41',0,2,0,1,NULL,NULL,NULL),(297,'Україна Славута','',0,1,0.00980,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-21 09:21:48',0,2,0,1,NULL,NULL,NULL),(298,'Марсель квартира новоград','',0,1,0.02510,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-23 14:51:38',0,2,0,1,NULL,NULL,NULL),(299,'БЮТ','',0,1,0.00300,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-24 16:29:46',0,2,0,1,NULL,NULL,NULL),(300,'Рівнеборошно','',0,1,0.00400,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-24 16:31:26',0,2,0,1,NULL,NULL,NULL),(301,'Любава Рівне','',0,1,0.00270,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-24 16:32:15',0,2,0,1,NULL,NULL,NULL),(303,'Піт-Стоп','',0,1,0.32000,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-24 17:56:22',0,2,0,1,NULL,NULL,NULL),(304,'Меркурій Млинів','',0,1,0.00530,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-30 09:40:47',0,2,0,1,NULL,NULL,NULL),(305,'Зустріч Дубно','',0,1,0.02360,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-30 09:42:11',0,2,0,1,NULL,NULL,NULL),(306,'Продукти КХП 2','',0,1,0.00120,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-30 09:44:18',0,2,0,1,NULL,NULL,NULL),(307,'Лев Дубно','',0,1,0.00210,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-09-30 09:46:57',0,2,0,1,NULL,NULL,NULL),(308,'Турійськ Даринка','',0,1,0.00720,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-10-01 09:58:43',0,2,0,1,NULL,NULL,NULL),(309,'Турійськ Едем','',0,1,0.02420,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-10-01 09:59:44',0,2,0,1,NULL,NULL,NULL),(310,'Торнадо Ковель','',0,1,0.83000,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-10-01 10:00:22',0,2,0,1,NULL,NULL,NULL),(311,'Обл.лікарня','',0,1,0.02480,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-10-04 14:23:30',0,2,0,1,NULL,NULL,NULL),(312,'Укрінбанк','',0,1,0.01260,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-10-04 14:34:05',0,2,0,1,NULL,NULL,NULL),(314,'Тайм Аут','',0,1,0.00180,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-10-06 10:13:12',0,2,0,1,NULL,NULL,NULL),(316,'ІнвестінРівне','',0,1,0.00340,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-10-06 15:54:02',0,2,0,1,NULL,NULL,NULL),(319,'Едем Дубно','',0,1,0.00590,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-10-06 17:28:46',0,2,0,1,NULL,NULL,NULL),(320,'Світлана Дубно','',0,1,0.00320,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-10-06 17:31:44',0,2,0,1,NULL,NULL,NULL),(321,'Хлібзавод Кузнцовськ','',0,1,0.22000,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-10-07 08:53:46',0,2,0,1,NULL,NULL,NULL),(322,'Юлас','',0,1,0.01710,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-10-07 09:42:53',0,2,0,1,NULL,NULL,NULL),(323,'Едем Кремен','',0,1,0.00590,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-10-07 09:47:59',0,2,0,1,NULL,NULL,NULL),(324,'Мидловець+Шахта','',0,1,0.01150,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-10-07 15:42:34',0,2,0,1,NULL,NULL,NULL),(325,'Гощанка','',0,1,0.00540,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-10-07 15:43:53',0,2,0,1,NULL,NULL,NULL),(326,'Західний Маневичі','',0,1,0.07680,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-10-08 08:40:31',0,2,0,1,NULL,NULL,NULL),(327,'Більярд Корець','',0,1,0.00240,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-10-08 09:31:15',0,2,0,1,NULL,NULL,NULL),(328,'Рікос Корець','',0,1,0.00310,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-10-08 09:32:12',0,2,0,1,NULL,NULL,NULL),(329,'Укрнафта Корець','',0,1,0.06780,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-10-08 09:33:43',0,2,0,1,NULL,NULL,NULL),(330,'Аншлаг','',0,1,0.00430,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-10-13 08:50:36',0,2,0,1,NULL,NULL,NULL),(331,'Козацький Рівне','',0,1,0.00240,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-10-13 08:51:39',0,2,0,1,NULL,NULL,NULL),(332,'Ресторан  Корець','',0,1,0.00060,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-10-13 08:53:37',0,2,0,1,NULL,NULL,NULL),(333,'Лісовий Кіт Броди','',0,1,0.04530,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-10-14 09:03:05',0,2,0,1,NULL,NULL,NULL),(334,'Фараон Рівне','',0,1,0.00160,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-10-18 09:12:34',0,2,0,1,NULL,NULL,NULL),(338,'Карат Березне','',0,1,0.00180,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-10-28 10:41:52',0,2,0,1,NULL,NULL,NULL),(340,'Околиця Турійськ','',0,1,0.09480,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-10-30 12:41:48',0,2,0,1,NULL,NULL,NULL),(341,'Оріон Ковель','',0,1,0.59000,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-10-30 12:44:36',0,2,0,1,NULL,NULL,NULL),(342,'Дольче Віта Зоря','',0,1,0.00780,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-10-30 12:45:46',0,2,0,1,NULL,NULL,NULL),(343,'Пінгвін Остріг','',0,1,0.00170,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-11-02 09:18:43',0,2,0,1,NULL,NULL,NULL),(344,'Діскавері Нетішин','',0,1,0.01240,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-11-02 09:20:10',0,2,0,1,NULL,NULL,NULL),(345,'Діалог Нетішин','',0,1,0.03460,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-11-02 09:22:17',0,2,0,1,NULL,NULL,NULL),(346,'Обрій Луцьк','',0,1,0.00870,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-11-02 18:34:53',0,2,0,1,NULL,NULL,NULL),(347,'Гульськ','',0,1,0.00990,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-11-05 09:59:20',0,2,0,1,NULL,NULL,NULL),(348,'Ведмідь Ярунь','',0,1,0.48000,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-11-05 10:00:02',0,2,0,1,NULL,NULL,NULL),(350,'Влад Луцьк','',0,1,0.01180,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-11-09 17:58:46',0,2,0,1,NULL,NULL,NULL),(352,'Марсо Луцьк','',0,1,0.00710,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-11-09 18:01:23',0,2,0,1,NULL,NULL,NULL),(353,'Хутір Луцьк','',0,1,0.00160,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-11-09 18:04:36',0,2,0,1,NULL,NULL,NULL),(355,'Газ Боярка','',0,1,0.01620,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-11-11 17:39:42',0,2,0,1,NULL,NULL,NULL),(356,'Діана Дубно','',0,1,0.01140,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-11-11 17:41:50',0,2,0,1,NULL,NULL,NULL),(357,'Дует Березне','',0,1,0.00490,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-11-11 17:44:25',0,2,0,1,NULL,NULL,NULL),(358,'УЖКГ','',0,1,0.01770,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-11-17 09:52:27',0,2,0,1,NULL,NULL,NULL),(359,'Мирогоща Коледж','',0,1,0.12000,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-11-17 09:55:20',0,2,0,1,NULL,NULL,NULL),(360,'Газовщики','',0,1,0.00320,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-11-22 09:13:33',0,2,0,1,NULL,NULL,NULL),(361,'Остріг Рікос','',0,1,0.00150,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-11-22 09:14:52',0,2,0,1,NULL,NULL,NULL),(362,'Івіта 2','',0,1,0.01300,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-11-22 09:16:40',0,2,0,1,NULL,NULL,NULL),(363,'Івіта','',0,1,0.00450,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-11-22 17:44:52',0,2,0,1,NULL,NULL,NULL),(365,'Ресторан Спорт','',0,1,0.02480,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-11-30 15:47:31',0,2,0,1,NULL,NULL,NULL),(366,'Равлик Луцьк','',0,1,0.00710,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-12-01 09:18:06',0,2,0,1,NULL,NULL,NULL),(367,'Аркан Ковель','',0,1,0.03790,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-12-06 09:24:48',0,2,0,1,NULL,NULL,NULL),(368,'Союз Віктан','',0,1,0.00320,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-12-06 10:09:40',0,2,0,1,NULL,NULL,NULL),(369,'Кав.на Петлюри','',0,1,0.00460,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-12-06 10:13:41',0,2,0,1,NULL,NULL,NULL),(370,'Каштан Костопіль','',0,1,0.00390,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-12-09 09:30:26',0,2,0,1,NULL,NULL,NULL),(371,'Ізотерм-С','',0,1,0.00340,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-12-14 09:29:30',0,2,0,1,NULL,NULL,NULL),(372,'Смачна Зупинка','',0,1,0.00500,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-12-14 09:31:47',0,2,0,1,NULL,NULL,NULL),(373,'Старий Томас','',0,1,0.00390,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-12-14 09:34:04',0,2,0,1,NULL,NULL,NULL),(374,'Реноме Рівне','',0,1,0.01020,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-12-14 16:45:25',0,2,0,1,NULL,NULL,NULL),(375,'Кришталь Луцьк','',0,1,0.01880,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-12-15 09:39:55',0,2,0,1,NULL,NULL,NULL),(376,'Підкова Березне','',0,1,0.02640,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-12-23 10:34:42',0,2,0,1,NULL,NULL,NULL),(377,'Експрес Березне','',0,1,0.00230,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-12-23 10:35:55',0,2,0,1,NULL,NULL,NULL),(378,'Піцерія Володимирець','',0,1,0.01010,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-12-23 10:41:09',0,2,0,1,NULL,NULL,NULL),(379,'Зол.Лев Новоград','',0,1,0.45000,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2010-12-24 09:44:18',0,2,0,1,NULL,NULL,NULL),(381,'Теплотранссервіс','',0,1,0.00090,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-01-05 09:21:23',0,2,0,1,NULL,NULL,NULL),(382,'Медлайф','',0,1,0.00720,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-01-05 10:31:01',0,2,0,1,NULL,NULL,NULL),(383,'Горинь Славута','',0,1,0.00640,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-01-11 09:22:51',0,2,0,1,NULL,NULL,NULL),(384,'Кулінарія Березне','',0,1,0.00160,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-01-13 09:24:53',0,2,0,1,NULL,NULL,NULL),(385,'ПідковаБерезне','',0,1,0.02080,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-01-13 09:25:39',0,2,0,1,NULL,NULL,NULL),(386,'Піцерія Луцк','',0,1,0.03930,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-01-19 09:26:15',0,2,0,1,NULL,NULL,NULL),(387,'Людмила Сарни','',0,1,0.00240,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-01-20 09:15:01',0,2,0,1,NULL,NULL,NULL),(389,'АВС Славута','',0,1,0.00950,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-01-25 09:24:30',0,2,0,1,NULL,NULL,NULL),(391,'Стоянка дом','',0,1,0.01960,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-01-26 09:18:51',0,2,0,1,NULL,NULL,NULL),(393,'Воловікова','',0,1,0.02250,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-01-28 09:08:20',0,2,0,1,NULL,NULL,NULL),(394,'Случ Новоград','',0,1,0.06440,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-01-28 09:09:44',0,2,0,1,NULL,NULL,NULL),(395,'Хамеліон Костопіль','',0,1,0.03390,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-02-04 09:10:42',0,2,0,1,NULL,NULL,NULL),(396,'ДБК Костопіль','',0,1,0.01590,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-02-04 09:11:26',0,2,0,1,NULL,NULL,NULL),(397,'Далас Сарни','',0,1,0.04390,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-02-04 09:12:03',0,2,0,1,NULL,NULL,NULL),(398,'Супер Володимирець','',0,1,0.00740,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-02-04 09:12:37',0,2,0,1,NULL,NULL,NULL),(399,'УКБ+ОЦЗ','',0,1,0.00300,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-02-04 09:19:26',0,2,0,1,NULL,NULL,NULL),(400,'Світахо','',0,1,0.00470,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-02-08 09:06:53',0,2,0,1,NULL,NULL,NULL),(402,'Фортеця Славута','',0,1,0.06360,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-02-08 09:10:41',0,2,0,1,NULL,NULL,NULL),(403,'Журавлина Сарни','',0,1,0.00220,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-02-10 09:16:18',0,2,0,1,NULL,NULL,NULL),(404,'Автоленд','',0,1,0.00480,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-02-22 08:47:24',0,2,0,1,NULL,NULL,NULL),(406,'Преподобний','',0,1,0.01660,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-02-22 08:50:30',0,2,0,1,NULL,NULL,NULL),(407,'Метро','',0,1,0.01530,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-03-01 08:55:10',0,2,0,1,NULL,NULL,NULL),(408,'Епіцентр','',0,1,0.02550,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-03-01 08:55:42',0,2,0,1,NULL,NULL,NULL),(409,'Мік Макс','',0,1,0.00160,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-03-03 14:30:19',0,2,0,1,NULL,NULL,NULL),(410,'Стоянка Сергій','',0,1,0.00500,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-03-07 10:04:29',0,2,0,1,NULL,NULL,NULL),(411,'Дім2 Сергій','',0,1,0.00550,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-03-07 10:05:26',0,2,0,1,NULL,NULL,NULL),(412,'Гост.Двір Привільне','',0,1,0.00890,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-03-15 09:22:50',0,2,0,1,NULL,NULL,NULL),(413,'Флеш Стар','',0,1,0.00050,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-03-15 13:21:03',0,2,0,1,NULL,NULL,NULL),(414,'Маршал Користь','',0,1,0.00960,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-03-15 13:22:40',0,2,0,1,NULL,NULL,NULL),(415,'Діамант Клевань','',0,1,0.00260,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-03-16 09:12:41',0,2,0,1,NULL,NULL,NULL),(416,'Хабанера','',0,1,0.00190,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-03-16 09:57:04',0,2,0,1,NULL,NULL,NULL),(417,'Ласунка Кузнецовськ','',0,1,0.05260,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-03-18 09:19:08',0,2,0,1,NULL,NULL,NULL),(418,'Інсеко Славута','',0,1,0.00310,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-03-22 09:08:43',0,2,0,1,NULL,NULL,NULL),(419,'Веч.Квартал Новоград','',0,1,0.00150,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-03-22 09:13:26',0,2,0,1,NULL,NULL,NULL),(420,'Княжий Новоград','',0,1,0.00100,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-03-22 09:16:04',0,2,0,1,NULL,NULL,NULL),(422,'Візит Грушвиця','',0,1,0.00110,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-03-23 09:22:34',0,2,0,1,NULL,NULL,NULL),(424,'Сяйво Дубно','',0,1,0.00080,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-03-23 09:25:04',0,2,0,1,NULL,NULL,NULL),(425,'Їдальня Обленерго','',0,1,0.00060,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-03-25 16:04:17',0,2,0,1,NULL,NULL,NULL),(426,'Хлібодар','',0,1,0.00650,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-04-01 14:57:28',0,2,0,1,NULL,NULL,NULL),(427,'Батискаф Славута','',0,1,0.00230,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-04-04 17:28:05',0,2,0,1,NULL,NULL,NULL),(428,'Карамелька','',0,1,0.01840,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-04-04 17:32:02',0,2,0,1,NULL,NULL,NULL),(429,'Велес Дубно','',0,1,0.00130,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-04-06 09:23:26',0,2,0,1,NULL,NULL,NULL),(430,'Чебуречна+Городок Новоград','',0,1,0.00130,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-04-19 09:29:25',0,2,0,1,NULL,NULL,NULL),(431,'Ольвія Рівне','',0,1,0.00060,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-05-05 17:28:52',0,2,0,1,NULL,NULL,NULL),(433,'Мередіан Рівне','',0,1,0.00920,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-05-30 09:45:09',0,2,0,1,NULL,NULL,NULL),(434,'Хімік','',0,1,0.00020,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-05-31 10:02:12',0,2,0,1,NULL,NULL,NULL),(435,'УА Сервіс','',0,1,0.00930,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-06-15 17:17:50',0,2,0,1,NULL,NULL,NULL),(437,'Затишок Колки','',0,1,0.00150,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-07-28 15:12:35',0,2,0,1,NULL,NULL,NULL),(439,'Екватор Клуб','',0,1,0.00020,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-08-01 17:50:33',0,2,0,1,NULL,NULL,NULL),(441,'ПП Попова','',0,1,0.00010,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-08-16 09:35:15',0,2,0,1,NULL,NULL,NULL),(442,'Колиба Броди','',0,1,0.00160,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-08-17 09:05:53',0,2,0,1,NULL,NULL,NULL),(443,'Лендел Костопіль','',0,1,0.00320,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-08-18 09:34:06',0,2,0,1,NULL,NULL,NULL),(444,'Лілія Турійськ','',0,1,0.00050,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-08-23 08:23:24',0,2,0,1,NULL,NULL,NULL),(446,'Піцерія Дубровиця','',0,1,0.00020,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-08-25 09:25:24',0,2,0,1,NULL,NULL,NULL),(448,'Лілея Орвяниця','',0,1,0.00110,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-08-25 09:27:25',0,2,0,1,NULL,NULL,NULL),(449,'Шиномонтаж Рівне','',0,1,0.00090,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-08-25 09:29:13',0,2,0,1,NULL,NULL,NULL),(451,'Казка Зоря','',0,1,0.00070,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-09-20 17:35:58',0,2,0,1,NULL,NULL,NULL),(452,'Мирослава Маневичі','',0,1,0.00120,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-09-23 08:57:31',0,2,0,1,NULL,NULL,NULL),(453,'Піца-Парк','',0,1,0.00220,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-10-07 17:40:24',0,2,0,1,NULL,NULL,NULL),(454,'Полісянка','',0,1,0.02120,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-10-07 17:41:58',0,2,0,1,NULL,NULL,NULL),(455,'Про100','',0,1,0.01200,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-10-07 17:42:45',0,2,0,1,NULL,NULL,NULL),(456,'Каміни Рівне','',0,1,0.00040,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-10-07 17:45:41',0,2,0,1,NULL,NULL,NULL),(457,'Мальвіна Луцьк','',0,1,0.00560,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-10-11 15:04:11',0,2,0,1,NULL,NULL,NULL),(458,'Комер.Коледж Рівне','',0,1,0.00180,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-10-11 15:06:56',0,2,0,1,NULL,NULL,NULL),(460,'Стелс Луцьк','',0,1,0.00020,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-10-18 12:50:18',0,2,0,1,NULL,NULL,NULL),(462,'ПП Дейнеко','',0,1,0.00650,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-12-08 08:49:14',0,2,0,1,NULL,NULL,NULL),(463,'Маєток Кузнецовськ','',0,1,0.00040,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2011-12-08 08:50:03',0,2,0,1,NULL,NULL,NULL),(464,'Панама Рівне','',0,1,0.00060,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-01-04 15:47:35',0,2,0,1,NULL,NULL,NULL),(465,'Лівас Рівне','',0,1,0.00320,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-01-04 15:48:27',0,2,0,1,NULL,NULL,NULL),(466,'Маяк Рівне','',0,1,0.00700,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-01-04 15:49:46',0,2,0,1,NULL,NULL,NULL),(467,'Шиномонтаж Сарни','',0,1,0.00030,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-01-12 08:45:12',0,2,0,1,NULL,NULL,NULL),(468,'Поліс Сарни','',0,1,0.00360,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-01-12 08:46:03',0,2,0,1,NULL,NULL,NULL),(469,'Кречко Зарічне','',0,1,0.00260,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-01-12 08:48:00',0,2,0,1,NULL,NULL,NULL),(471,'Валентина Зарічне','',0,1,0.00540,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-01-12 08:51:08',0,2,0,1,NULL,NULL,NULL),(472,'Серники','',0,1,0.00000,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-01-12 08:52:11',0,2,0,1,NULL,NULL,NULL),(473,'Серники Бродниця','',0,1,0.00080,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-01-12 08:52:50',0,2,0,1,NULL,NULL,NULL),(474,'Лілія Дубровиця','',0,1,0.00410,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-01-12 08:56:41',0,2,0,1,NULL,NULL,NULL),(476,'Роксолана Зарічне','',0,1,0.00030,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-01-12 09:00:21',0,2,0,1,NULL,NULL,NULL),(478,'Бруклін Рівне','',0,1,0.00110,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-01-23 13:34:55',0,2,0,1,NULL,NULL,NULL),(479,'Саманта Рівне','',0,1,0.00090,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-03-27 18:33:06',0,2,0,1,NULL,NULL,NULL),(480,'Політон Рівне','',0,1,0.00320,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-03-27 18:34:53',0,2,0,1,NULL,NULL,NULL),(481,'Унісон Рівне','',0,1,0.00150,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-03-27 18:36:13',0,2,0,1,NULL,NULL,NULL),(482,'Сіріус Рівне','',0,1,0.00040,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-03-27 18:37:55',0,2,0,1,NULL,NULL,NULL),(483,'Василина Цумань','',0,1,0.00110,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-04-06 10:25:30',0,2,0,1,NULL,NULL,NULL),(484,'Словянка Колки','',0,1,0.00190,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-04-06 10:28:19',0,2,0,1,NULL,NULL,NULL),(485,'Юність Дубровиця','',0,1,0.00300,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-04-06 10:32:26',0,2,0,1,NULL,NULL,NULL),(486,'Клєтка Володимирець','',0,1,0.00770,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-05-10 17:56:23',0,2,0,1,NULL,NULL,NULL),(487,'Імбекс Кузнецовськ','',0,1,0.00140,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-05-10 17:57:11',0,2,0,1,NULL,NULL,NULL),(488,'Таверна Рівне','',0,1,0.00100,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-05-31 12:54:33',0,2,0,1,NULL,NULL,NULL),(489,'Румянець завод','',0,1,0.00160,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-05-31 12:56:27',0,2,0,1,NULL,NULL,NULL),(490,'Дім Сергій','',0,1,0.00490,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-06-13 09:59:17',0,2,0,1,NULL,NULL,NULL),(491,'Дует Сарни','',0,1,0.00480,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-06-13 10:02:06',0,2,0,1,NULL,NULL,NULL),(492,'Айвенго Рівне','',0,1,0.01450,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-06-13 10:06:38',0,2,0,1,NULL,NULL,NULL),(493,'Мерлоуз Рівне','',0,1,0.00300,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-06-13 10:07:24',0,2,0,1,NULL,NULL,NULL),(494,'Офіс Радіозавод','',0,1,0.01010,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-06-13 10:08:09',0,2,0,1,NULL,NULL,NULL),(495,'Козацькі Забави Рівне','',0,1,0.00160,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-06-13 10:08:51',0,2,0,1,NULL,NULL,NULL),(496,'Офіс РОМ','',0,1,0.00210,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-06-13 10:12:41',0,2,0,1,NULL,NULL,NULL),(497,'КГХ Дубровиця','',0,1,0.00090,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-06-13 14:59:15',0,2,0,1,NULL,NULL,NULL),(498,'Адоней Рівне','',0,1,0.00280,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-06-25 12:35:08',0,2,0,1,NULL,NULL,NULL),(499,'Буковинський Рівне','',0,1,0.00820,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-06-25 12:36:08',0,2,0,1,NULL,NULL,NULL),(500,'Україна  Зарічне','',0,1,0.00220,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-08-08 16:11:01',0,2,0,1,NULL,NULL,NULL),(501,'Експрес Сарни приват','',0,1,0.00760,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-08-08 16:13:17',0,2,0,1,NULL,NULL,NULL),(502,'Пан Халявський','',0,1,0.01530,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-08-08 16:14:40',0,2,0,1,NULL,NULL,NULL),(503,'Віденський Рівне','',0,1,0.00710,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-08-08 16:17:19',0,2,0,1,NULL,NULL,NULL),(504,'Анастасія Рівне','',0,1,0.00300,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-08-08 16:17:55',0,2,0,1,NULL,NULL,NULL),(505,'Авеню Рівне','',0,1,0.00170,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-10-11 14:25:12',0,2,0,1,NULL,NULL,NULL),(506,'Кіноцентр Ера','',0,1,0.00510,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-10-11 14:25:44',0,2,0,1,NULL,NULL,NULL),(507,'Дім Ігор','',0,1,0.00060,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-10-11 14:26:26',0,2,0,1,NULL,NULL,NULL),(508,'Автосервіс Сарни','',0,1,0.11000,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2012-10-11 14:28:27',0,2,0,1,NULL,NULL,NULL),(509,'Лісники','',0,1,0.00080,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2013-01-15 11:37:45',0,2,0,1,NULL,NULL,NULL),(510,'Євро Клуб','',0,1,0.00110,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2013-01-15 11:41:52',0,2,0,1,NULL,NULL,NULL),(511,'Цукерочка Рівне','',0,1,0.00100,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2013-01-18 10:24:47',0,2,0,1,NULL,NULL,NULL),(512,'Піцерія Метро','',0,1,0.00030,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2013-01-21 18:07:49',0,2,0,1,NULL,NULL,NULL),(513,'ОДА','',0,1,0.01150,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2013-01-22 11:42:21',0,2,0,1,NULL,NULL,NULL),(514,'Кратос Румянець','',0,1,0.00270,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2013-01-22 11:43:15',0,2,0,1,NULL,NULL,NULL),(515,'Коффета','',0,1,0.00470,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2013-01-22 11:48:31',0,2,0,1,NULL,NULL,NULL),(516,'Жармоленко','',0,1,0.00160,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2013-01-22 18:28:56',0,2,0,1,NULL,NULL,NULL),(517,'Дует сарни 2','',0,1,0.02460,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2013-01-23 11:50:53',0,2,0,1,NULL,NULL,NULL),(518,'Оберіг Сарни','',0,1,0.00200,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2013-01-23 16:27:01',0,2,0,1,NULL,NULL,NULL),(519,'Здоровя Сарни','',0,1,0.00250,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2013-01-23 17:57:13',0,2,0,1,NULL,NULL,NULL),(520,'Тополя Зарічне','',0,1,0.00420,-65536,-32944,'Microsoft Sans Serif',26.00,'0;0;0;0;',NULL,3,'2013-02-20 16:41:19',0,2,0,1,NULL,NULL,NULL);

--
-- Table structure for table `zonesgroup`
--

CREATE TABLE `zonesgroup` (
  `Id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `Title` varchar(50) NOT NULL,
  `Description` varchar(200) NOT NULL,
  `OutLinkId` varchar(20) DEFAULT NULL COMMENT 'Код внешней базы',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=cp1251;

--
-- Dumping data for table `zonesgroup`
--

INSERT INTO `zonesgroup` VALUES (1,'Все зоны','НЕ УДАЛЯТЬ! Корневой элемент дерева контрольных зон',NULL);

--
-- Dumping events for database 'pryvilne'
--

--
-- Dumping routines for database 'pryvilne'
--
/*!50003 DROP FUNCTION IF EXISTS `CheckVersion` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `CheckVersion`(maskVersion TINYTEXT) RETURNS tinyint(4)
    SQL SECURITY INVOKER
    COMMENT 'Проверка версии СУБД. Должна быть maskVersion или выше. Результа'
BEGIN
  DECLARE currentVersion TINYTEXT;
  SELECT Left(VERSION(), Length(maskVersion)) INTO currentVersion;
  RETURN currentVersion >= maskVersion;
END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `HaveSuperPrivileges` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `HaveSuperPrivileges`() RETURNS tinyint(4)
    SQL SECURITY INVOKER
    COMMENT 'Проверка, имеет ли пользователь привилегию SUPER. Результат: 1 -'
BEGIN
  DECLARE usrstr TINYTEXT DEFAULT '';

  DECLARE usr TINYTEXT DEFAULT '';
  DECLARE hst TINYTEXT DEFAULT '';
  DECLARE pos TINYINT;

  SELECT USER() INTO usrstr;

  SELECT INSTR(usrstr, '@') INTO pos;


  SELECT Left(usrstr, pos - 1), Right(usrstr, Length(usrstr) - pos) INTO usr, hst;

  RETURN (
    SELECT COUNT(*) > 0
    FROM mysql.`user` u
    WHERE u.`User` = usr AND u.Host = hst AND Super_priv = 'Y'
  );
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `BMCTransferBuffer` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `BMCTransferBuffer`(IN DatagpsIsUpdated INT, IN Datagps64IsUpdated INT)
    COMMENT 'Обновление online* для BMC'
BEGIN
	DECLARE MobitelID INT;
	DECLARE done INT DEFAULT FALSE;
	DECLARE CursorMobitels CURSOR FOR SELECT Mobitel_ID FROM datagpsbuffer_bmc WHERE `Online`=1;
	DECLARE CursorMobitels64 CURSOR FOR SELECT Mobitel_ID FROM datagpsbuffer_bmc64 WHERE `Online`=1;
	DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
    
	/* datagps */
	IF DatagpsIsUpdated THEN
		OPEN CursorMobitels;
		read_loop: LOOP
			FETCH CursorMobitels INTO MobitelID;
			IF done THEN
				LEAVE read_loop;
			END IF;
			DELETE FROM `online` WHERE Mobitel_ID=MobitelID AND UnixTime <= (SELECT COALESCE(UnixTime, 0) FROM (SELECT UnixTime FROM `online` WHERE Mobitel_ID=MobitelID ORDER BY UnixTime DESC LIMIT 100, 1) o);
		END LOOP;
		CLOSE CursorMobitels;
		UPDATE mobitels m,datagpsbuffer_bmc b SET m.LastInsertTime=b.UnixTime WHERE m.Mobitel_ID=b.Mobitel_ID AND m.LastInsertTime<b.UnixTime;
	END IF;
	/* datagps64 */
	IF Datagps64IsUpdated THEN
		OPEN CursorMobitels64;
		read_loop: LOOP
			FETCH CursorMobitels64 INTO MobitelID;
			IF done THEN
				LEAVE read_loop;
			END IF;
			DELETE FROM `online64` WHERE Mobitel_ID=MobitelID AND UnixTime <= (SELECT COALESCE(UnixTime, 0) FROM (SELECT UnixTime FROM `online64` WHERE Mobitel_ID=MobitelID ORDER BY UnixTime DESC LIMIT 100, 1) o);
		END LOOP;
		CLOSE CursorMobitels64;
		UPDATE mobitels m,datagpsbuffer_bmc64 b SET m.LastInsertTime=b.UnixTime WHERE m.Mobitel_ID=b.Mobitel_ID AND m.LastInsertTime<b.UnixTime;
	END IF;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `CheckDB` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CheckDB`()
    SQL SECURITY INVOKER
    COMMENT 'Проверка БД при подключении.'
BEGIN

  SELECT 'OK';

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `CheckOdo` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CheckOdo`(IN m_id INTEGER(11), IN end_time DATETIME)
    SQL SECURITY INVOKER
BEGIN

  SELECT 

   FROM_UNIXTIME(datagps.UnixTime) AS `time` ,

   (datagps.Latitude / 600000.00000) AS Lat,

   (datagps.Longitude / 600000.00000) AS Lon

  FROM

    datagps

  WHERE

    datagps.Mobitel_ID = m_id AND 

    datagps.UnixTime BETWEEN (SELECT UNIX_TIMESTAMP(odoTime)  FROM vehicle WHERE Mobitel_id = m_id) AND 

    UNIX_TIMESTAMP(end_time) AND 

    Valid = 1;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `CleaningDataGpsLostOn` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CleaningDataGpsLostOn`()
    SQL SECURITY INVOKER
    COMMENT 'Сия процедура удаляет не корректно оформленные диапазоны пропусков из таблицы datagpslost_on'
BEGIN

  /* удаляем записи у которых BeginSrvPacketId >= EndSrvPacketId */

  DELETE d FROM datagpslost_on d WHERE d.Begin_SrvPacketID >= d.End_SrvPacketID;

  /* удаляем записи у которых EndLogId - BeginLogId <= 1 */

  DELETE d FROM datagpslost_on d WHERE d.End_LogID - d.Begin_LogID <= 1;

  /* удаляем записи которые с заданным LogId и SrvPackId отсутвут в таблице datagps или datagps64 (фантомные записи) */



  CREATE TEMPORARY TABLE MobiTemp (Id bigint(20) UNSIGNED DEFAULT 0)ENGINE = INNODB

    CHARACTER SET cp1251

    COLLATE cp1251_general_ci

    COMMENT = 'Промежуточная временная таблица';



  INSERT INTO MobiTemp SELECT d.Id FROM datagpslost_on d WHERE 

  NOT EXISTS(SELECT NULL FROM datagps d1 WHERE (d.Mobitel_ID = d1.Mobitel_ID) AND ((d.Begin_LogID = d1.LogID) AND (d.Begin_SrvPacketID = d1.SrvPacketID))) AND 

  NOT EXISTS(SELECT NULL FROM datagps64 d2 WHERE (d.Mobitel_ID = d2.Mobitel_ID) AND ((d.Begin_LogID = d2.LogID) AND (d.Begin_SrvPacketID = d2.SrvPacketID))); 

  DELETE d FROM datagpslost_on d, MobiTemp m WHERE m.Id = d.Id;



  TRUNCATE MobiTemp;



  INSERT INTO MobiTemp SELECT d.Id FROM datagpslost_on d WHERE 

  NOT EXISTS(SELECT NULL FROM datagps d1 WHERE (d.Mobitel_ID = d1.Mobitel_ID) AND ((d.End_LogID = d1.LogID) AND (d.End_SrvPacketID = d1.SrvPacketID))) AND 

  NOT EXISTS(SELECT NULL FROM datagps64 d2 WHERE (d.Mobitel_ID = d2.Mobitel_ID) AND ((d.End_LogID = d2.LogID) AND (d.End_SrvPacketID = d2.SrvPacketID))); 

  DELETE d FROM datagpslost_on d, MobiTemp m WHERE m.Id = d.Id;



  DROP TEMPORARY TABLE MobiTemp;



  SELECT 1;

  

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `dataview` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `dataview`(

  IN m_id INTEGER(11), 

  IN val BOOL, 

  IN begin_time DATETIME, 

  IN end_time DATETIME)
    SQL SECURITY INVOKER
BEGIN

  SELECT DataGps_ID AS DataGps_ID,

    Mobitel_ID AS Mobitel_ID,

    ((Latitude * 1.0000) / 600000) AS Lat,

    ((Longitude * 1.0000) / 600000) AS Lon,

    Altitude AS Altitude,

    FROM_UNIXTIME(UnixTime) AS `time`,

    (Speed * 1.852) AS speed,

    ((Direction * 360) / 255) AS direction,

    Valid AS Valid,

    (Sensor8 + (Sensor7 << 8) + (Sensor6 << 16) + 

      (Sensor5 << 24) + (Sensor4 << 32) + (Sensor3 << 40) + 

      (Sensor2 << 48) + (Sensor1 << 56)) AS sensor,

    Events AS Events,

    LogID AS LogID 

  FROM datagps 

  WHERE Mobitel_ID = m_id AND  

    (UnixTime BETWEEN UNIX_TIMESTAMP(begin_time) AND UNIX_TIMESTAMP(end_time)) AND                                                                                                                                

    (Valid = val) AND NOT (Latitude = 0 AND Longitude =0)

  ORDER BY UnixTime;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `delDupSrvPacket` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `delDupSrvPacket`()
    SQL SECURITY INVOKER
    COMMENT 'Удаляет дубликаты SrvPacketID из таблицы datagpsbuffer_on64'
BEGIN

DROP TEMPORARY TABLE IF EXISTS tmp64;




CREATE TEMPORARY TABLE tmp64 SELECT Mobitel_ID,

  Latitude,

  Longitude,

  Direction,

  Acceleration,

  UnixTime,

  Speed,

  Valid,

  Satellites,

  RssiGsm,

  `Events`,

  SensorsSet,

  Sensors,

  Voltage,

  DGPS,

  LogID,

  SrvPacketID

FROM datagpsbuffer_on64 d

GROUP BY d.SrvPacketID;



  TRUNCATE TABLE datagpsbuffer_on64;



  INSERT INTO datagpsbuffer_on64 SELECT Mobitel_ID,

  Latitude,

  Longitude,

  Direction,

  Acceleration,

  UnixTime,

  Speed,

  Valid,

  Satellites,

  RssiGsm,

  `Events`,

  SensorsSet,

  Sensors,

  Voltage,

  DGPS,

  LogID,

  SrvPacketID

FROM tmp64 d;



DROP TEMPORARY TABLE IF EXISTS tmp64;


END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `DrListMobitelConfig` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `DrListMobitelConfig`()
    SQL SECURITY INVOKER
    COMMENT 'Выборка настроек телетреков в режиме DirectOnline'
BEGIN
  SELECT m.Mobitel_id AS MobitelID, 
    imc.DevIdShort AS DevIdShort,
    cge.Pop3un AS Login, 
    cge.Pop3pw AS Password
  FROM Mobitels m JOIN ConfigMain cm ON m.Mobitel_id = cm.Mobitel_ID
    JOIN ConfigGprsEmail cge ON cm.ConfigGprsEmail_ID = cge.ID
    JOIN internalmobitelconfig imc ON m.InternalMobitelConfig_ID = imc.ID 
  WHERE (cge.ConfigGprsEmail_ID = (
      SELECT MAX(intCge.ConfigGprsEmail_ID)
      FROM ConfigGprsEmail intCge
      WHERE intCge.ID = cge.ID)) AND
    (imc.InternalMobitelConfig_ID = (
      SELECT MAX(intConf.InternalMobitelConfig_ID)
      FROM internalmobitelconfig intConf
      WHERE intConf.ID = imc.ID)) AND 
    (imc.devIdShort IS NOT NULL) AND (imc.devIdShort <> _cp1251 '')	AND 
    (cge.Pop3un IS NOT NULL) AND (cge.Pop3un <> _cp1251 '') 
  ORDER BY m.Mobitel_ID;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `DrTransferBuffer` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `DrTransferBuffer`()
    SQL SECURITY INVOKER
    COMMENT 'Переносит GPS данные DirectOnline из буферной таблицы в datagps'
BEGIN
  DECLARE MobitelIDInCursor INT; 
  DECLARE DataExists TINYINT DEFAULT 1; 
  
  DECLARE TmpMaxUnixTime INT; 

  DECLARE CursorMobitels CURSOR FOR
    SELECT DISTINCT(Mobitel_ID) FROM datagpsbuffer_dr;

  
  DECLARE CONTINUE HANDLER FOR NOT FOUND SET DataExists = 0;


    
  
  
  DELETE o
  FROM online o, datagpsbuffer_dr dgb
  WHERE (o.Mobitel_ID = dgb.Mobitel_ID) AND (o.LogID = dgb.LogID);
  
  SET DataExists = 1;
  OPEN CursorMobitels;
  FETCH CursorMobitels INTO MobitelIDInCursor;
  WHILE DataExists = 1 DO
    
    SELECT COALESCE(MAX(UnixTime), 0) INTO TmpMaxUnixTime
    FROM online FORCE INDEX (IDX_Mobitelid)
    WHERE Mobitel_ID = MobitelIDInCursor;

    
    INSERT INTO online (
      Mobitel_ID, LogID, UnixTime, Latitude, Longitude, Altitude,
      Direction, Speed, Valid, `Events`,
      Sensor1, Sensor2, Sensor3, Sensor4, Sensor5, Sensor6, Sensor7, Sensor8,
      Counter1, Counter2, Counter3, Counter4, whatIs)
    SELECT
      Mobitel_ID, LogID, UnixTime, Latitude, Longitude, Altitude,
      Direction, Speed, Valid, `Events`,
      Sensor1, Sensor2, Sensor3, Sensor4, Sensor5, Sensor6, Sensor7, Sensor8,
      Counter1, Counter2, Counter3, Counter4, whatIs
    FROM (
      SELECT *
      FROM datagpsbuffer_dr
      WHERE (Mobitel_ID = MobitelIDInCursor)  AND 
        (UnixTime > TmpMaxUnixTime) AND (Valid = 1)
      GROUP BY Mobitel_ID, LogID
      ORDER BY UnixTime DESC
      LIMIT 100) AS T
    ORDER BY UnixTime ASC;

    
    DELETE FROM online
    WHERE (Mobitel_ID = MobitelIDInCursor) AND (UnixTime < 
      (SELECT COALESCE(MIN(UnixTime), 0) 
       FROM (
         SELECT UnixTime
         FROM online
         WHERE Mobitel_ID = MobitelIDInCursor 
         ORDER BY UnixTime DESC
         LIMIT 100) T1)); 
  
    FETCH CursorMobitels INTO MobitelIDInCursor;
  END WHILE;
  CLOSE CursorMobitels;
   


  
  UPDATE datagps d, datagpsbuffer_dr b SET
    d.Latitude = b.Latitude,
    d.Longitude = b.Longitude,
    d.Altitude = b.Altitude,
    d.UnixTime = b.UnixTime,
    d.Speed = b.Speed,
    d.Direction = b.Direction,
    d.Valid = b.Valid,
    d.InMobitelID = b.LogID,
    d.`Events` = b.`Events`,
    d.Sensor1 = b.Sensor1,
    d.Sensor2 = b.Sensor2,
    d.Sensor3 = b.Sensor3,
    d.Sensor4 = b.Sensor4,
    d.Sensor5 = b.Sensor5,
    d.Sensor6 = b.Sensor6,
    d.Sensor7 = b.Sensor7,
    d.Sensor8 = b.Sensor8,
    d.whatIs = b.whatIs,
    d.Counter1 = b.Counter1,
    d.Counter2 = b.Counter2,
    d.Counter3 = b.Counter3,
    d.Counter4 = b.Counter4
  WHERE (d.Mobitel_ID = b.Mobitel_ID) AND (d.LogID = b.LogID);

  
  DELETE b
  FROM datagps d, datagpsbuffer_dr b
  WHERE (d.Mobitel_ID = b.Mobitel_ID) AND (d.LogID = b.LogID);

  
  INSERT INTO datagps (
    Mobitel_ID, LogID, UnixTime, Latitude, Longitude, Altitude,
    Direction, Speed, Valid, `Events`, InMobitelID,
    Sensor1, Sensor2, Sensor3, Sensor4, Sensor5, Sensor6, Sensor7, Sensor8,
    Counter1, Counter2, Counter3, Counter4, whatIs)
  SELECT
    Mobitel_ID, LogID, UnixTime, Latitude, Longitude, Altitude,
    Direction, Speed, Valid, `Events`, LogID,
    Sensor1, Sensor2, Sensor3, Sensor4, Sensor5, Sensor6, Sensor7, Sensor8,
    Counter1, Counter2, Counter3, Counter4, whatIs
  FROM datagpsbuffer_dr
  GROUP BY Mobitel_ID, LogID;

  
  TRUNCATE TABLE datagpsbuffer_dr;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `ExecuteQuery` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ExecuteQuery`(IN sqlQuery TINYTEXT)
    SQL SECURITY INVOKER
BEGIN
  SET @s = sqlQuery;
  PREPARE stmt FROM @s;
  EXECUTE stmt;
  DEALLOCATE PREPARE stmt;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `getDiapasone` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `getDiapasone`(

  IN mobile INTEGER(11),  

  IN prevLogId int, 

  IN currLogId int)
    SQL SECURITY INVOKER
BEGIN

  SELECT DataGps_ID AS DataGps_ID,

    Mobitel_ID AS Mobitel_ID,

    ((Latitude * 1.0000) / 600000) AS Lat,

    ((Longitude * 1.0000) / 600000) AS Lon,

    Altitude AS Altitude,

    FROM_UNIXTIME(UnixTime) AS `time`,

    (Speed * 1.852) AS speed,

    ((Direction * 360) / 255) AS direction,

    Valid AS Valid,

    (Sensor8 + (Sensor7 << 8) + (Sensor6 << 16) + 

      (Sensor5 << 24) + (Sensor4 << 32) + (Sensor3 << 40) + 

      (Sensor2 << 48) + (Sensor1 << 56)) AS sensor,

    Events AS Events,

    LogID AS LogID, 

    SrvPacketID AS srvPack

  FROM datagps 

  WHERE Mobitel_ID = mobile AND  Valid = 1 AND  

    (LogID BETWEEN prevLogId AND currLogId) ORDER BY UnixTime;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `getDiapasone64` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `getDiapasone64`(

  IN mobile INTEGER(11),  

  IN prevLogId int, 

  IN currLogId int)
    SQL SECURITY INVOKER
BEGIN

  SELECT  DataGps_ID, Mobitel_ID,

    ((Latitude * 1.000) / 10000000) AS Lat,

    ((Longitude * 1.000) / 10000000) AS Lng,

    Acceleration , 

    FROM_UNIXTIME(UnixTime) AS `time` , 

    Speed /10 AS Speed, 

    Valid,

    Sensors AS sensor, 

  `Events`, 

  LogID ,

  Voltage,

  DGPS,

  Direction,

  Satellites,

  SensorsSet,

  RssiGsm,

  SrvPacketID AS srvPack FROM datagps64 d WHERE Mobitel_ID = mobile AND d.Valid = 1 AND  

    (LogID BETWEEN prevLogId AND currLogId) ORDER BY UnixTime;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `hystoryOnline` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `hystoryOnline`(IN id INTEGER(11))
    SQL SECURITY INVOKER
BEGIN

  SELECT LogID, Mobitel_Id, 

    FROM_UNIXTIME(unixtime)  AS `time`,

    ROUND((Latitude / 600000.00000), 6) AS Lat,

    ROUND((Longitude / 600000.00000), 6)  AS Lon,

    Altitude  AS Altitude,

    (Speed * 1.852) AS speed,

    ((Direction * 360) / 255) AS direction,

    Valid AS Valid,

    (Sensor8 + (Sensor7 << 8) + (Sensor6 << 16) + 

      (Sensor5 << 24) + (Sensor4 << 32) + (Sensor3 << 40) + 

      (Sensor2 << 48) + (Sensor1 << 56)) AS sensor,

    Events AS Events,

    DataGPS_ID  AS 'DataGPS_ID'

  FROM online

  WHERE  datagps_id > id

  ORDER BY datagps_id DESC;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `IsTeletrackDatabase` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `IsTeletrackDatabase`()
    SQL SECURITY INVOKER
    COMMENT 'Проверка базы данных на соответствие структуре системы Teletrack'
BEGIN
  DECLARE i TINYINT;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `new_proc` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `new_proc`(IN sensor INTEGER(11), IN m_id INTEGER(11), IN s_id INTEGER(11), IN begin_time DATETIME, IN end_time DATETIME)
    READS SQL DATA
    SQL SECURITY INVOKER
BEGIN                                                                                                                                      
select                                                                                                                                     
    round((`datagps`.`Longitude` / 600000),6) AS `lon`,                                                                                    
    round((`datagps`.`Latitude` / 600000),6) AS `lat`,                                                                                     
    `datagps`.`Mobitel_ID` AS `Mobitel_ID`,                                                                                                
    `sensordata`.`Value` AS `Value`,                                                                                                       
    (`datagps`.`Speed` * 1.852) AS `speed`,                                                                                                
    from_unixtime(`datagps`.`UnixTime`) AS `time`,                                                                                         
    `sensordata`.`sensor_id` AS `sensor_id`,                                                                                               
    `datagps`.`DataGps_ID` AS `datagps_id`,                                                                                                
    `datagps`.`Sensor1`&`sensor` AS `sensor`                                                                                              
  from                                                                                                                                     
    (`sensordata` join `datagps` on((`sensordata`.`datagps_id` = `datagps`.`DataGps_ID`)))                                                 
  where                                                                                                                                    
    (`datagps`.`Valid` = 1) and                                                                                                            
    ( datagps.UnixTime BETWEEN UNIX_TIMESTAMP(begin_time) and UNIX_TIMESTAMP(end_time))                                                    
    and datagps.Mobitel_ID = m_id AND sensordata.sensor_id = s_id                                                                          
  order by                                                                                                                                 
    `datagps`.`UnixTime`,`datagps`.`Mobitel_ID`,`sensordata`.`sensor_id`;                                                                  
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `OnCorrectInfotrackLogId` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `OnCorrectInfotrackLogId`()
    SQL SECURITY INVOKER
    COMMENT 'Корректировка значений LogId и InMobitelID в данных инфотреков'
BEGIN

  DECLARE MobitelIDInCursor INT; /* Текущее значение MobitelID */

  DECLARE DataExists TINYINT DEFAULT 1; /* Флаг наличия данных после фетча */

  DECLARE MaxLogId INT DEFAULT 0; /* Максимальный LogId для данного дивайса */

  DECLARE SrvPacketIDInCursor BIGINT DEFAULT 0; /* Текущее значение серверного пакета */

    

  /* Курсор по инфотрекам в множестве новых данных. 

     Все инфотреки начинаются с буквы I */

  DECLARE CursorInfoTrack CURSOR FOR

    SELECT DISTINCT buf.Mobitel_ID

    FROM datagpsbuffer_on buf 

      JOIN mobitels m ON (buf.mobitel_id = m.mobitel_id)

      JOIN internalmobitelconfig c ON (c.ID = m.InternalMobitelConfig_ID)

    WHERE (c.InternalMobitelConfig_ID = (

      SELECT intConf.InternalMobitelConfig_ID

      FROM internalmobitelconfig intConf

      WHERE (intConf.ID = c.ID) 

      ORDER BY intConf.InternalMobitelConfig_ID DESC

      LIMIT 1)) AND 

      (c.devIdShort LIKE "I%") AND (buf.LogId = 0)

    ORDER BY 1;

    

  /* Курсор по данным телетрека */

  DECLARE CursorInfoTrackUpdateSet CURSOR FOR

    SELECT SrvPacketID 

    FROM datagpsbuffer_on

    WHERE (Mobitel_ID = MobitelIDInCursor) AND (LogId = 0)

    ORDER BY UnixTime;  



  /* Обработчик отсутствующей записи при FETCH следующей записи */

  DECLARE CONTINUE HANDLER FOR NOT FOUND SET DataExists = 0;

  

  OPEN CursorInfoTrack;

  FETCH CursorInfoTrack INTO MobitelIDInCursor;

  WHILE DataExists = 1 DO

    /* Находим максимальный LogId для данного инфотрека */

    SELECT COALESCE(MAX(LogID), 0) INTO	MaxLogId

    FROM DataGps

    WHERE Mobitel_ID = MobitelIDInCursor;



    /* Обновляем LogId и InMobitelID в наборе новых данных текущего инфотрека */

    OPEN CursorInfoTrackUpdateSet;

    FETCH CursorInfoTrackUpdateSet INTO SrvPacketIDInCursor;

    WHILE DataExists = 1 DO

      SET MaxLogId = MaxLogId + 1;



      UPDATE datagpsbuffer_on

      SET LogId = MaxLogId, InMobitelID = MaxLogId

      WHERE SrvPacketID = SrvPacketIDInCursor;



      FETCH CursorInfoTrackUpdateSet INTO SrvPacketIDInCursor;

    END WHILE;

    CLOSE CursorInfoTrackUpdateSet;

 

    SET DataExists = 1;

    FETCH CursorInfoTrack INTO MobitelIDInCursor;

  END WHILE;

  CLOSE CursorInfoTrack;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `OnCorrectInfotrackLogId64` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `OnCorrectInfotrackLogId64`()
    SQL SECURITY INVOKER
    COMMENT 'РљРѕСЂСЂРµРєС‚РёСЂРѕРІРєР° Р·РЅР°С‡РµРЅРёР№ LogId Рё InMobitelID РІ РґР°РЅРЅС‹С… РёРЅС„РѕС‚СЂРµРєРѕРІ'
BEGIN

  DECLARE MobitelIDInCursor int; /* РўРµРєСѓС‰РµРµ Р·РЅР°С‡РµРЅРёРµ MobitelID */

  DECLARE DataExists tinyint DEFAULT 1; /* Р¤Р»Р°Рі РЅР°Р»РёС‡РёСЏ РґР°РЅРЅС‹С… РїРѕСЃР»Рµ С„РµС‚С‡Р° */

  DECLARE MaxLogId int DEFAULT 0; /* РњР°РєСЃРёРјР°Р»СЊРЅС‹Р№ LogId РґР»СЏ РґР°РЅРЅРѕРіРѕ РґРёРІР°Р№СЃР° */

  DECLARE SrvPacketIDInCursor bigint DEFAULT 0; /* РўРµРєСѓС‰РµРµ Р·РЅР°С‡РµРЅРёРµ СЃРµСЂРІРµСЂРЅРѕРіРѕ РїР°РєРµС‚Р° */



  /* РљСѓСЂСЃРѕСЂ РїРѕ РёРЅС„РѕС‚СЂРµРєР°Рј РІ РјРЅРѕР¶РµСЃС‚РІРµ РЅРѕРІС‹С… РґР°РЅРЅС‹С…. 

     Р’СЃРµ РёРЅС„РѕС‚СЂРµРєРё РЅР°С‡РёРЅР°СЋС‚СЃСЏ СЃ Р±СѓРєРІС‹ I */

  DECLARE CursorInfoTrack CURSOR FOR

  SELECT DISTINCT

    buf.Mobitel_ID

  FROM datagpsbuffer_on64 buf

    JOIN mobitels m

      ON (buf.mobitel_id = m.mobitel_id)

    JOIN internalmobitelconfig c

      ON (c.ID = m.InternalMobitelConfig_ID)

  WHERE (c.InternalMobitelConfig_ID = (SELECT

      intConf.InternalMobitelConfig_ID

    FROM internalmobitelconfig intConf

    WHERE (intConf.ID = c.ID)

    ORDER BY intConf.InternalMobitelConfig_ID DESC

    LIMIT 1)) AND

  (c.devIdShort LIKE "I%") AND (buf.LogId = 0)

  ORDER BY 1;



  /* РљСѓСЂСЃРѕСЂ РїРѕ РґР°РЅРЅС‹Рј С‚РµР»РµС‚СЂРµРєР° */

  DECLARE CursorInfoTrackUpdateSet CURSOR FOR

  SELECT

    SrvPacketID

  FROM datagpsbuffer_on64

  WHERE (Mobitel_ID = MobitelIDInCursor) AND (LogId = 0)

  ORDER BY UnixTime;



  /* РћР±СЂР°Р±РѕС‚С‡РёРє РѕС‚СЃСѓС‚СЃС‚РІСѓСЋС‰РµР№ Р·Р°РїРёСЃРё РїСЂРё FETCH СЃР»РµРґСѓСЋС‰РµР№ Р·Р°РїРёСЃРё */

  DECLARE CONTINUE HANDLER FOR NOT FOUND SET DataExists = 0;



  OPEN CursorInfoTrack;

  FETCH CursorInfoTrack INTO MobitelIDInCursor;

  WHILE DataExists = 1 DO

    /* РќР°С…РѕРґРёРј РјР°РєСЃРёРјР°Р»СЊРЅС‹Р№ LogId РґР»СЏ РґР°РЅРЅРѕРіРѕ РёРЅС„РѕС‚СЂРµРєР° */

    SELECT

      COALESCE(MAX(LogID), 0) INTO MaxLogId

    FROM DataGps

    WHERE Mobitel_ID = MobitelIDInCursor;



    /* РћР±РЅРѕРІР»СЏРµРј LogId Рё InMobitelID РІ РЅР°Р±РѕСЂРµ РЅРѕРІС‹С… РґР°РЅРЅС‹С… С‚РµРєСѓС‰РµРіРѕ РёРЅС„РѕС‚СЂРµРєР° */

    OPEN CursorInfoTrackUpdateSet;

    FETCH CursorInfoTrackUpdateSet INTO SrvPacketIDInCursor;

    WHILE DataExists = 1 DO

      SET MaxLogId = MaxLogId + 1;



      UPDATE datagpsbuffer_on64

      SET LogId = MaxLogId,

          InMobitelID = MaxLogId

      WHERE SrvPacketID = SrvPacketIDInCursor;



      FETCH CursorInfoTrackUpdateSet INTO SrvPacketIDInCursor;

    END WHILE;

    CLOSE CursorInfoTrackUpdateSet;



    SET DataExists = 1;

    FETCH CursorInfoTrack INTO MobitelIDInCursor;

  END WHILE;

  CLOSE CursorInfoTrack;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `OnDeleteDuplicates` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `OnDeleteDuplicates`()
    SQL SECURITY INVOKER
    COMMENT 'Удаление повторяющихся строк из datagpsbuffer_on'
BEGIN

  /* Удаляет дубликаты строк из таблицы datagpsbuffer_on. Критерием поиска

   являются одинаковые значения в полях Mobitel_Id + LogID. Из множества

   повторяющихся записей в таблице datagpsbuffer_on останется только одна - 

   последняя принятая телематическим сервером, т.е. с максимальным SrvPacketID. */

   

  /* Текущий MobitelId в курсоре CursorDuplicateGroups */

  DECLARE MobitelIdInCursor INT DEFAULT 0; 

  /* Текущий LogID в курсоре CursorDuplicateGroups */

  DECLARE LogIdInCursor INT DEFAULT 0; 

  /* Max SrvPacketId в множестве строк текущей группы дубликатов */

  DECLARE MaxSrvPacketId BIGINT DEFAULT 0; 

  DECLARE DataExists TINYINT DEFAULT 1;



  /* Курсор для прохода по всем группам дубликатов */  

  DECLARE CursorDuplicateGroups CURSOR FOR

    SELECT Mobitel_Id, LogId 

    FROM datagpsbuffer_on

    GROUP BY Mobitel_Id, LogId 

    HAVING COUNT(LogId) > 1;

    

  DECLARE CONTINUE HANDLER FOR NOT FOUND SET DataExists = 0;



  SET DataExists = 1;

  OPEN CursorDuplicateGroups;

  FETCH CursorDuplicateGroups INTO MobitelIdInCursor, LogIdInCursor;

  WHILE DataExists = 1 DO

    SELECT MAX(SrvPacketID) INTO MaxSrvPacketId

    FROM datagpsbuffer_on 

    WHERE (Mobitel_ID = MobitelIdInCursor) AND (LogId = LogIdInCursor);

         

    DELETE FROM datagpsbuffer_on  

    WHERE (Mobitel_ID = MobitelIdInCursor) AND (LogId = LogIdInCursor) 

      AND (SrvPacketID < MaxSrvPacketId);

        

    FETCH CursorDuplicateGroups INTO MobitelIdInCursor, LogIdInCursor;

  END WHILE;

  CLOSE CursorDuplicateGroups; 

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `OnDeleteDuplicates64` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `OnDeleteDuplicates64`()
    SQL SECURITY INVOKER
    COMMENT 'РЈРґР°Р»РµРЅРёРµ РїРѕРІС‚РѕСЂСЏСЋС‰РёС…СЃСЏ СЃС‚СЂРѕРє РёР· datagpsbuffer_on64'
BEGIN

  /* РЈРґР°Р»СЏРµС‚ РґСѓР±Р»РёРєР°С‚С‹ СЃС‚СЂРѕРє РёР· С‚Р°Р±Р»РёС†С‹ datagpsbuffer_on64. РљСЂРёС‚РµСЂРёРµРј РїРѕРёСЃРєР°

   СЏРІР»СЏСЋС‚СЃСЏ РѕРґРёРЅР°РєРѕРІС‹Рµ Р·РЅР°С‡РµРЅРёСЏ РІ РїРѕР»СЏС… Mobitel_Id + LogID. РР· РјРЅРѕР¶РµСЃС‚РІР°

   РїРѕРІС‚РѕСЂСЏСЋС‰РёС…СЃСЏ Р·Р°РїРёСЃРµР№ РІ С‚Р°Р±Р»РёС†Рµ datagpsbuffer_on64 РѕСЃС‚Р°РЅРµС‚СЃСЏ С‚РѕР»СЊРєРѕ РѕРґРЅР° - 

   РїРѕСЃР»РµРґРЅСЏСЏ РїСЂРёРЅСЏС‚Р°СЏ С‚РµР»РµРјР°С‚РёС‡РµСЃРєРёРј СЃРµСЂРІРµСЂРѕРј, С‚.Рµ. СЃ РјР°РєСЃРёРјР°Р»СЊРЅС‹Рј SrvPacketID. */



  /* РўРµРєСѓС‰РёР№ MobitelId РІ РєСѓСЂСЃРѕСЂРµ CursorDuplicateGroups */

  DECLARE MobitelIdInCursor int DEFAULT 0;

  /* РўРµРєСѓС‰РёР№ LogID РІ РєСѓСЂСЃРѕСЂРµ CursorDuplicateGroups */

  DECLARE LogIdInCursor int DEFAULT 0;

  /* Max SrvPacketId РІ РјРЅРѕР¶РµСЃС‚РІРµ СЃС‚СЂРѕРє С‚РµРєСѓС‰РµР№ РіСЂСѓРїРїС‹ РґСѓР±Р»РёРєР°С‚РѕРІ */

  DECLARE MaxSrvPacketId bigint DEFAULT 0;

  DECLARE DataExists tinyint DEFAULT 1;



  /* РљСѓСЂСЃРѕСЂ РґР»СЏ РїСЂРѕС…РѕРґР° РїРѕ РІСЃРµРј РіСЂСѓРїРїР°Рј РґСѓР±Р»РёРєР°С‚РѕРІ */

  DECLARE CursorDuplicateGroups CURSOR FOR

  SELECT

    Mobitel_Id,

    LogId

  FROM datagpsbuffer_on64

  GROUP BY Mobitel_Id,

           LogId

  HAVING COUNT(LogId) > 1;



  DECLARE CONTINUE HANDLER FOR NOT FOUND SET DataExists = 0;



  SET DataExists = 1;

  OPEN CursorDuplicateGroups;

  FETCH CursorDuplicateGroups INTO MobitelIdInCursor, LogIdInCursor;

  WHILE DataExists = 1 DO

    SELECT

      MAX(SrvPacketID) INTO MaxSrvPacketId

    FROM datagpsbuffer_on64

    WHERE (Mobitel_ID = MobitelIdInCursor) AND (LogId = LogIdInCursor);



    DELETE

      FROM datagpsbuffer_on64

    WHERE (Mobitel_ID = MobitelIdInCursor) AND (LogId = LogIdInCursor)

      AND (SrvPacketID < MaxSrvPacketId);



    FETCH CursorDuplicateGroups INTO MobitelIdInCursor, LogIdInCursor;

  END WHILE;

  CLOSE CursorDuplicateGroups;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `OnDeleteLostRange` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `OnDeleteLostRange`(IN MobitelID INTEGER(11), IN BeginSrvPacketID BIGINT)
    SQL SECURITY INVOKER
    COMMENT 'Удаление указанного диапазона пропусков из datagpslost_on.'
BEGIN

  /* Определяем является ли запись, предназначенная для удаления,

     первой в списке заданного телетрека. Если является - тогда

     внесем поправку в значение ConfirmedID */  

     

  DECLARE MinBeginSrvPacketID BIGINT; -- Минимальное значение Begin_SrvPacketID для данного телетрека

  DECLARE NewConfirmedID INT; -- Новое значение ConfirmedID  



  /* Нахождение минимального значения Begin_SrvPacketID */  

  SELECT MIN(Begin_SrvPacketID) INTO MinBeginSrvPacketID

  FROM datagpslost_on

  WHERE Mobitel_ID = MobitelID;

  

  /* Если есть данные о пропусках у телетрека - продолжим */

  IF MinBeginSrvPacketID IS NOT NULL THEN

    /* Если удаляем первую запись - запомним новое значение ConfirmedID */

    IF MinBeginSrvPacketID = BeginSrvPacketID  THEN

      SELECT End_LogID INTO NewConfirmedID

      FROM datagpslost_on

      WHERE (Mobitel_ID = MobitelID) AND (Begin_SrvPacketID = BeginSrvPacketID);

    END IF;

  

    /* Удаление записи */

    DELETE FROM  datagpslost_on

    WHERE (Mobitel_ID = MobitelID) AND (Begin_SrvPacketID = BeginSrvPacketID);

    

    /* Если удалили первую запись - обновим ConfirmedID */  

    IF MinBeginSrvPacketID = BeginSrvPacketID  THEN

      UPDATE mobitels

      SET ConfirmedID = NewConfirmedID

      WHERE (Mobitel_ID = MobitelID) AND (NewConfirmedID > ConfirmedID);

    END IF;

  END IF;  

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `OnInsertDatagpsLost` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `OnInsertDatagpsLost`(

  IN MobitelID INT, 

  IN BeginLogID INT, 

  IN EndLogID INT,

  IN BeginSrvPacketID BIGINT, 

  IN EndSrvPacketID BIGINT)
    SQL SECURITY INVOKER
    COMMENT 'Вставка данных в таблицу datagpslost_on.'
BEGIN

  /* Флаг существования записи с заданными Mobitel_ID и Begin_LogID

     в таблице datagpslost_on */

  DECLARE MobitelId_BeginLogID_Exists TINYINT DEFAULT 0; 

  /* Флаг существования записи с заданными Mobitel_ID и Begin_SrvPacketID

     в таблице datagpslost_on  */

  DECLARE MobitelId_BeginSrvPacketID_Exists TINYINT DEFAULT 0;

  

  DECLARE RowBeginSrvPacketID BIGINT; 

  

  IF EXISTS(

    SELECT NULL

    FROM datagpslost_on

    WHERE (Mobitel_ID = MobitelID) AND (Begin_LogID = BeginLogID))

  THEN

    SET MobitelId_BeginLogID_Exists = 1;

  END IF;



  IF EXISTS(

    SELECT NULL

    FROM datagpslost_on

    WHERE (Mobitel_ID = MobitelID) AND (Begin_SrvPacketID = BeginSrvPacketID))

  THEN

    SET MobitelId_BeginSrvPacketID_Exists = 1;

  END IF;



  IF (MobitelId_BeginLogID_Exists = 0) AND (MobitelId_BeginSrvPacketID_Exists = 0)

  THEN

    /* Вставка новой записи */

    INSERT INTO datagpslost_on(Mobitel_ID, Begin_LogID, End_LogID, Begin_SrvPacketID, End_SrvPacketID)

    VALUES (MobitelID, BeginLogID, EndLogID, BeginSrvPacketID, EndSrvPacketID);

  ELSE

    IF ((MobitelId_BeginLogID_Exists = 1) AND (MobitelId_BeginSrvPacketID_Exists = 1))

    THEN

      /* Обновление существующей записи */

      UPDATE datagpslost_on

      SET End_LogID = EndLogID, End_SrvPacketID = EndSrvPacketID

      WHERE (Mobitel_ID = MobitelID) AND (Begin_LogID = BeginLogID);

    ELSE

      /* Комбинацию MobitelId_BeginLogID_Exists = 0, MobitelId_BeginSrvPacketID_Exists = 1

         игнорируем - это исключительная ситуация, которая не должна возникать. */

      SELECT Begin_SrvPacketID

      INTO RowBeginSrvPacketID

      FROM datagpslost_on

      WHERE (Mobitel_ID = MobitelID) AND (Begin_LogID = BeginLogID)

      LIMIT 1;

      

      IF ((MobitelId_BeginLogID_Exists = 1) AND (MobitelId_BeginSrvPacketID_Exists = 0) AND

        (BeginSrvPacketID < RowBeginSrvPacketID))

      THEN

        /* В эту ветвь попадаем, если телетрек отдаст одну и ту же запись несколько раз 

           (LogID у записей один и тотже, а SrvPacketID различны) */

        UPDATE datagpslost_on

        SET End_LogID = EndLogID, Begin_SrvPacketID = BeginSrvPacketID, End_SrvPacketID = EndSrvPacketID

        WHERE (Mobitel_ID = MobitelID) AND (Begin_LogID = BeginLogID);

      END IF;

    END IF;

  END IF;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `online` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `online`()
    SQL SECURITY INVOKER
BEGIN

  SELECT Log_ID, MobitelId, 

    (SELECT DataGPS_ID

    FROM `online` 

    WHERE mobitel_id = MobitelId AND LogId = Log_ID Limit 1) AS 'DataGPS_ID',

      (SELECT from_unixtime(unixtime) 

      FROM `online` 

      WHERE mobitel_id = MobitelId AND LogId = Log_ID Limit 1) AS 'time',

        (SELECT ROUND((`Latitude` / 600000.00000),6)

        FROM `online` 

        WHERE mobitel_id = MobitelId AND LogId = Log_ID Limit 1) AS `Lat`,

          (SELECT ROUND((`Longitude` / 600000.00000),6) 

          FROM `online` 

          WHERE mobitel_id = MobitelId AND LogId = Log_ID Limit 1) AS `Lon`,

            (SELECT `Altitude` 

            FROM `online` 

            WHERE mobitel_id = MobitelId AND LogId = Log_ID Limit 1) AS `Altitude`,

              (SELECT (`Speed` * 1.852)

              FROM `online` 

              WHERE mobitel_id = MobitelId AND LogId = Log_ID Limit 1) AS `speed`,

                (SELECT ((`Direction` * 360) / 255)

                FROM `online` 

                WHERE mobitel_id = MobitelId AND LogId = Log_ID Limit 1) AS `direction`,

                  (SELECT `Valid`

                  FROM `online` 

                  WHERE mobitel_id = MobitelId AND LogId = Log_ID Limit 1) AS `Valid`,

                    (SELECT (((((((`Sensor8` + 

                    (`Sensor7` << 8)) + 

                    (`Sensor6` << 16)) + 

                    (`Sensor5` << 24)) + 

                    (`Sensor4` << 32)) + 

                    (`Sensor3` << 40)) + 

                    (`Sensor2` << 48)) + 

                    (`Sensor1` << 56)) 

                    FROM `online` 

                    WHERE mobitel_id = MobitelId AND LogId = Log_ID Limit 1) AS `sensor`,

                      (SELECT `Events`

                      FROM `online` 

                      WHERE mobitel_id = MobitelId AND LogId = Log_ID Limit 1) AS `Events`

   

  FROM (SELECT MAX(`LogID`) AS `Log_ID`, mobitel_id AS MobitelId

        FROM `online` 

        GROUP BY `Mobitel_ID`) T1;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `OnListMobitelConfig` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `OnListMobitelConfig`()
    SQL SECURITY INVOKER
    COMMENT 'Выборка настроек телетреков которые могут работать в online режиме'
BEGIN

  DECLARE MobitelIDInCursor INT;

  DECLARE DevIdShortInCursor CHAR(4);

  DECLARE DataExists TINYINT DEFAULT 1;



  /* Курсор в множестве настроенных телетреков */

  DECLARE CursorMobitels CURSOR FOR

    SELECT m.Mobitel_ID AS MobitelID, c.devIdShort AS DevIdShort

    FROM mobitels m

      JOIN internalmobitelconfig c ON (c.ID = m.InternalMobitelConfig_ID)

    WHERE (c.InternalMobitelConfig_ID = (

      SELECT intConf.InternalMobitelConfig_ID

      FROM internalmobitelconfig intConf

      WHERE (intConf.ID = c.ID)

      ORDER BY intConf.InternalMobitelConfig_ID DESC

      LIMIT 1)) AND

      (c.devIdShort IS NOT NULL) AND (c.devIdShort <> _cp1251'')

    ORDER BY m.Mobitel_ID;



  DECLARE CONTINUE HANDLER FOR NOT FOUND SET DataExists = 0;



  /* Временная таблица настроек телетрека */

  CREATE TEMPORARY TABLE tmpMobitelsConfig (

    MobitelID INT NOT NULL,

    DevIdShort CHAR(4) NOT NULL,

    LastPacketID BIGINT NOT NULL) ENGINE = MEMORY;



  OPEN CursorMobitels;

  FETCH CursorMobitels INTO MobitelIDInCursor, DevIdShortInCursor;

  WHILE DataExists = 1 DO



    INSERT INTO tmpMobitelsConfig SELECT MobitelIDInCursor, DevIdShortInCursor,

      (SELECT COALESCE(MAX(SrvPacketID), 0)

       FROM datagps

       WHERE Mobitel_ID = MobitelIDInCursor) AS LastPacketID;



    FETCH CursorMobitels INTO MobitelIDInCursor, DevIdShortInCursor;

  END WHILE;

  CLOSE CursorMobitels;



  SELECT MobitelID, DevIdShort, LastPacketID

  FROM tmpMobitelsConfig;



  DROP TEMPORARY TABLE tmpMobitelsConfig;  

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `OnListMobitelConfig64` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `OnListMobitelConfig64`()
    SQL SECURITY INVOKER
    COMMENT 'Выборка настроек телетреков которые могут работать в online режиме для datagps и datagps64'
BEGIN

  DECLARE MobitelIDInCursor INT;

  DECLARE Is64Cursor tinyint;

  DECLARE DevIdShortInCursor CHAR(4);

  DECLARE DataExists TINYINT DEFAULT 1;



  /* Курсор в множестве настроенных телетреков */

  DECLARE CursorMobitels CURSOR FOR

    SELECT m.Mobitel_ID AS MobitelID, m.Is64bitPackets AS Is64, c.devIdShort AS DevIdShort

    FROM mobitels m

      JOIN internalmobitelconfig c ON (c.ID = m.InternalMobitelConfig_ID)

    WHERE (c.InternalMobitelConfig_ID = (

      SELECT intConf.InternalMobitelConfig_ID

      FROM internalmobitelconfig intConf

      WHERE (intConf.ID = c.ID)

      ORDER BY intConf.InternalMobitelConfig_ID DESC

      LIMIT 1)) AND

      (c.devIdShort IS NOT NULL) AND (c.devIdShort <> _cp1251'')

    ORDER BY m.Mobitel_ID;



  DECLARE CONTINUE HANDLER FOR NOT FOUND SET DataExists = 0;



  /* Временная таблица настроек телетрека */

  CREATE TEMPORARY TABLE tmpMobitelsConfig (

    MobitelID INT NOT NULL,

    Is64 tinyint NOT NULL,

    DevIdShort CHAR(4) NOT NULL,

    LastPacketID BIGINT NOT NULL,

    LastPacketID64 BIGINT NOT NULL) ENGINE = MEMORY;



  OPEN CursorMobitels;

  FETCH CursorMobitels INTO MobitelIDInCursor, Is64Cursor, DevIdShortInCursor;

  WHILE DataExists = 1 DO



    INSERT INTO tmpMobitelsConfig SELECT MobitelIDInCursor, Is64Cursor, DevIdShortInCursor,

      (SELECT COALESCE(MAX(d.SrvPacketID), 0)

       FROM datagps d

       WHERE d.Mobitel_ID = MobitelIDInCursor) AS LastPacketID,

      (SELECT COALESCE(MAX(t.SrvPacketID), 0)

       FROM datagps64 t

       WHERE t.Mobitel_ID = MobitelIDInCursor) AS LastPacketID64;



    FETCH CursorMobitels INTO MobitelIDInCursor, Is64Cursor, DevIdShortInCursor;

  END WHILE;

  CLOSE CursorMobitels;



  SELECT MobitelID, Is64, DevIdShort, LastPacketID, LastPacketID64

  FROM tmpMobitelsConfig;



  DROP TEMPORARY TABLE tmpMobitelsConfig;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `OnLostDataGPS` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `OnLostDataGPS`(IN MobitelID INTEGER(11), OUT NeedOptimize TINYINT)
    SQL SECURITY INVOKER
    COMMENT 'Поиск пропусков в online данных заданного телетрека и заполнение таблиц.'
BEGIN



  /********** DECLARE **********/

  

  DECLARE CurrentConfirmedID INT DEFAULT 0; /* Текущее значение ConfirmedID */

  DECLARE NewConfirmedID INT DEFAULT 0; /* Новое значение ConfirmedID */

  DECLARE StartLogIDSelect INT DEFAULT 0; /* min LogID для выборки */

  DECLARE FinishLogIDSelect INT DEFAULT 0; /* max LogID для выборки */

  DECLARE MaxEndLogID INT DEFAULT 0; /* max End_LogID в пропущенных диапазонах данного телетрека */

  

  DECLARE MinLogID_n INT DEFAULT 0; /* Минимальный LogID после ConfirmedID в множестве новых данных */

  DECLARE MaxLogID_n INT DEFAULT 0; /* Максимальный LogID в множестве новых данных */

  

  DECLARE DataExists TINYINT DEFAULT 1; /* Флаг наличия данных после фетча */

    

  DECLARE NewLogID INT; /* Значение LogID в курсоре CursorNewLogID */

  DECLARE NewSrvPacketID BIGINT; /* Значение SrvPacketID в курсоре CursorNewLogID */

  DECLARE FirstLogID INT DEFAULT -9999999; /* Первое значение LogID для анализа */

  DECLARE SecondLogID INT; /* Второе значение LogID для анализа */

  DECLARE FirstSrvPacketID BIGINT; /* Первое значение SrvPacketID */

  DECLARE SecondSrvPacketID BIGINT; /* Второе значение SrvPacketID */

  

  DECLARE tmpSrvPacketID BIGINT DEFAULT 0; /* Значение SrvPacketID для первой искусственной записи в анализе новых данных, не пересекающихся с существующими */  

  

  /* Курсор для прохода по новым LogID */

  DECLARE CursorNewLogID CURSOR FOR

    SELECT LogID, SrvPacketID 

    FROM datagpslost_ontmp;

    

  /* Обработчик отсутствующей записи при FETCH следующей записи */

  DECLARE CONTINUE HANDLER FOR NOT FOUND SET DataExists = 0;

  

  /********** END DECLARE **********/



  SET NeedOptimize = 0;

 

  SELECT COALESCE(ConfirmedID, 0) INTO CurrentConfirmedID

  FROM mobitels

  WHERE Mobitel_ID = MobitelID;



  /* Минимальный LogID в новом наборе данных c которым будем работать */

  SELECT MIN(LogID) INTO MinLogID_n

  FROM datagpsbuffer_on

  WHERE (Mobitel_ID = MobitelID) AND (LogID > CurrentConfirmedID);

  

  /* Максимальный LogID в новом наборе данных c которым будем работать */

  SELECT MAX(LogID) INTO MaxLogID_n

  FROM datagpsbuffer_on 

  WHERE Mobitel_ID = MobitelID;  

  

  /* Максимальный End_LogID в пропущенных диапазонах данного телетрека */

  SELECT COALESCE(MAX(End_LogID), 0) INTO MaxEndLogID

  FROM datagpslost_on 

  WHERE Mobitel_ID = MobitelID;  

  

  /* Проверим есть ли данные для анализа */

  IF MinLogID_n IS NOT NULL THEN

  

    /********** PREPARE **********/

    

    TRUNCATE TABLE datagpslost_ontmp;

  

    IF MinLogID_n < MaxEndLogID THEN

      /* Если  MinLogID_n < MaxEndLogID значит пришли данные, 

       которые возможно закроют часть пропусков. */

       

      /* Находим стартовый LogID для пересчета. */

      SELECT COALESCE(Begin_LogID, MinLogID_n) INTO StartLogIDSelect

      FROM datagpslost_on

      WHERE (Mobitel_ID = MobitelID) AND (MinLogID_n > Begin_LogID) 

        AND (MinLogID_n < End_LogID);

      

      /* Находим последний LogID для пересчета. */  

      SELECT COALESCE(End_LogID, MaxLogID_n) INTO FinishLogIDSelect

      FROM datagpslost_on

      WHERE (Mobitel_ID = MobitelID) AND (MaxLogID_n > Begin_LogID) 

        AND (MaxLogID_n < End_LogID);

       

      /* Удалим старые записи из реестра пропущенных записей 

         (стали неактуальными, надо пересчитать) */

      DELETE FROM datagpslost_on

      WHERE (Mobitel_ID = MobitelID) AND (Begin_LogID >= StartLogIDSelect)

        AND (Begin_LogID <= FinishLogIDSelect);

      

      /* Если первая запись LogID = 0 и этой записи нет в DataGps, тогда

         надо добавить первую фиктивную запись для анализа. */

      IF (StartLogIDSelect = 0) AND (NOT EXISTS

        (Select 1 

         FROM datagps 

         WHERE (Mobitel_ID = MobitelID) AND (LogID = StartLogIDSelect))) THEN

      

        INSERT INTO datagpslost_ontmp(LogID, SrvPacketID) VALUES (0, 0);  

      END IF;       

    ELSE

      /* Пришли новые данные. Надо добавить для анализа искусственную запись - 

         нижнюю границу */

      

      /* Находим стартовый LogID для пересчета. */

      SELECT COALESCE(MAX(End_LogID), CurrentConfirmedID) INTO StartLogIDSelect

      FROM datagpslost_on

      WHERE Mobitel_ID = MobitelID;   

         

      /* Находим последний LogID для пересчета. */  

      SELECT MAX(LogID)  INTO FinishLogIDSelect

      FROM datagpsbuffer_on

      WHERE Mobitel_ID = MobitelID;

      

      /* Выбираем из datagps соответствующее значение SrvPacketID  для первой

         искусственной записи */

      SELECT COALESCE(SrvPacketID, 0) INTO tmpSrvPacketID

      FROM datagps

      WHERE (Mobitel_ID = MobitelID) AND (LogID = StartLogIDSelect);

      

      /* Помещаем в таблицу datagpslost_ontmp для анализа пропусков 

         дополнительную первую запись */

      INSERT INTO datagpslost_ontmp(LogID, SrvPacketID)

      VALUES (StartLogIDSelect, tmpSrvPacketID);

    END IF; -- IF MinLogID_n < MaxEndLogID   

    

    /********** END PREPARE **********/

    

    /**********  INSERT ROWS **********/

    

    /* Заполнение временной таблицы последними данными телетрека

       для анализа разрывов */

    INSERT INTO datagpslost_ontmp  (LogID, SrvPacketID)

      SELECT LogID, SrvPacketID

      FROM datagps

      WHERE (Mobitel_ID = MobitelID) AND (LogID >= StartLogIDSelect)

        AND (LogID <= FinishLogIDSelect)

      ORDER BY LogID;

            

    /* Формирование команды-вставки в таблицу пропущенных диапазонов */

    SET DataExists = 1;

    OPEN CursorNewLogID;

    FETCH CursorNewLogID INTO NewLogID, NewSrvPacketID;

    WHILE DataExists = 1 DO

      IF FirstLogID = -9999999 THEN

        /* Первое значение в списке */

        SET FirstLogID = NewLogID;

        SET FirstSrvPacketID = NewSrvPacketID;

      ELSE

        /* Основная ветка расчета*/

        SET SecondLogID = NewLogID;

        SET SecondSrvPacketID = NewSrvPacketID;

        

        IF (SecondLogID - FirstLogID) > 1 THEN

          /* Найден разрыв */

          /* Из-за всяких комбинаций состояний LogId и SrvPacketId из-за особенностей работы телематического сервера

          и ТДМ вводим дополнительный анализ вставляемых записей, если запись не соответсвует указаным правилам, она 

          отбрасывается */

          IF (SecondSrvPacketID > FirstSrvPacketID) THEN

            IF EXISTS(SELECT NULL FROM datagps d WHERE (d.Mobitel_ID = MobitelID) AND ((d.LogID = FirstLogID) AND (d.SrvPacketID = FirstSrvPacketID))) THEN 

              IF EXISTS(SELECT NULL FROM datagps d WHERE (d.Mobitel_ID = MobitelID) AND ((d.LogID = SecondLogID) AND (d.SrvPacketID = SecondSrvPacketID))) THEN 



                CALL OnInsertDatagpsLost(MobitelID, FirstLogID, SecondLogID, FirstSrvPacketID, SecondSrvPacketID);

                IF NeedOptimize = 0 THEN SET NeedOptimize = 1; END IF;

                

              END IF;

            END IF;

          END IF;

        END IF;

        /* Переместим текущее второе значение на первую позицию

           для участия в следующей итерации в качестве начального значения */

        SET  FirstLogID = SecondLogID;

        SET FirstSrvPacketID = SecondSrvPacketID;

      END IF;  

      FETCH CursorNewLogID INTO NewLogID, NewSrvPacketID;

    END WHILE;

    CLOSE CursorNewLogID;

 

    /********** END INSERT ROWS **********/

               

    /********** UPDATE MOBITELS **********/

    

    /* Если пропущенных записей у данного телетрека нет - 

       тогда ConfirmedID будет равен максимальному LogID 

       данного телетрека. Иначе - минимальный Begin_LogID

       из таблицы пропусков */

    SELECT MIN(Begin_LogID) INTO NewConfirmedID

    FROM datagpslost_on

    WHERE Mobitel_ID = MobitelID;

       

    IF NewConfirmedID IS NULL THEN

      SELECT MAX(LogID) INTO NewConfirmedID

      FROM datagps

      WHERE Mobitel_ID = MobitelID;

    END IF;  

    

    /* Обновим ConfirmedID если надо */

    UPDATE mobitels

    SET ConfirmedID = NewConfirmedID

    WHERE (Mobitel_ID = MobitelID) AND (ConfirmedID < NewConfirmedID);

    

    /********** END UPDATE MOBITELS **********/

        

    TRUNCATE TABLE datagpslost_ontmp;

  END IF; -- IF MaxEndLogID IS NOT NULL  

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `OnLostDataGPS2` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `OnLostDataGPS2`(IN MobitelID INTEGER(11), OUT NeedOptimize TINYINT)
    SQL SECURITY INVOKER
    COMMENT 'Модификация диапазонов пропусков. Анализ дублирующих данных заданного телетрека.'
BEGIN

    /********** DECLARE **********/

    

  DECLARE NewConfirmedID INT DEFAULT 0; /* Новое значение ConfirmedID */

  DECLARE BeginLogID INT; /* Begin_LogID в курсоре CursorLostRanges */

  DECLARE EndLogID INT; /* End_LogID в курсоре CursorLostRanges */

  DECLARE BeginSrvPacketID BIGINT; /* Begin_SrvPacketID в курсоре CursorLostRanges */

  DECLARE EndSrvPacketID BIGINT; /* End_SrvPacketID в курсоре CursorLostRanges */

  DECLARE RowCountForAnalyze INT DEFAULT 0; /* Количество записей для анализа */

  DECLARE DataExists TINYINT DEFAULT 1; /* Флаг наличия данных после фетча */

    

  /* Курсор для прохода по диапазонам пропусков телетрека */

  DECLARE CursorLostRanges CURSOR FOR

    SELECT Begin_LogID, End_LogID, Begin_SrvPacketID, End_SrvPacketID 

    FROM datagpslost_on

    WHERE Mobitel_ID = MobitelID;    



  /* Курсор для прохода по новым LogID */

  DECLARE CursorNewLogID CURSOR FOR

    SELECT LogID, SrvPacketID 

    FROM datagpslost_ontmp

    ORDER BY SrvPacketID;    

    

  /* Обработчик отсутствующей записи при FETCH следующей записи */

  DECLARE CONTINUE HANDLER FOR NOT FOUND SET DataExists = 0;

  

  /********** END DECLARE **********/



  SET NeedOptimize = 0;

  

  TRUNCATE TABLE datagpslost_ontmp;

  

  /* Перебираем диапазоны и сокращаем разрывы если это возможно */

  SET DataExists = 1;

  OPEN CursorLostRanges;

  FETCH CursorLostRanges INTO BeginLogID, EndLogID, BeginSrvPacketID, EndSrvPacketID;

  WHILE DataExists = 1 DO

    /* Заполнение временной таблицы дублирующими данными телетрека

       для анализа разрывов */

    INSERT INTO datagpslost_ontmp  (LogID, SrvPacketID)

      SELECT DISTINCT LogID, SrvPacketID

      FROM datagpsbuffer_ontmp

      WHERE (Mobitel_ID = MobitelID) AND (SrvPacketID > BeginSrvPacketID)

        AND (SrvPacketID < EndSrvPacketID)

      ORDER BY SrvPacketID;

      

    /* Если есть данные модифицируем диапазон */  

    SELECT COUNT(1) INTO RowCountForAnalyze

    FROM datagpslost_ontmp;  

    

    IF RowCountForAnalyze > 0 THEN  

      /* Добавляем первую и последнюю записи для анализа */  

      INSERT INTO datagpslost_ontmp (LogID, SrvPacketID)

      VALUES (BeginLogID, BeginSrvPacketID), (EndLogID, EndSrvPacketID);

      

      /* Удаляем старый диапазон */

      DELETE FROM datagpslost_on

      WHERE (Mobitel_ID = MobitelID) AND (Begin_LogID = BeginLogID);

       

      /**********  INSERT ROWS **********/             

      BEGIN

        DECLARE NewLogID INT; /* Значение LogID в курсоре CursorNewLogID */

        DECLARE NewSrvPacketID BIGINT; /* Значение SrvPacketID в курсоре CursorNewLogID */

        DECLARE FirstLogID INT DEFAULT -9999999; /* Первое значение LogID для анализа */

        DECLARE SecondLogID INT; /* Второе значение LogID для анализа */

        DECLARE FirstSrvPacketID BIGINT; /* Первое значение SrvPacketID */

        DECLARE SecondSrvPacketID BIGINT; /* Второе значение SrvPacketID */

        

        /* Обработчик отсутствующей записи при FETCH следующей записи */

        DECLARE CONTINUE HANDLER FOR NOT FOUND SET DataExists = 0;

        

        /* Формирование команды-вставки в таблицу пропущенных диапазонов */

        SET DataExists = 1;

        OPEN CursorNewLogID;

        FETCH CursorNewLogID INTO NewLogID, NewSrvPacketID;

        WHILE DataExists = 1 DO

          IF FirstLogID = -9999999 THEN

            /* Первое значение в списке */

            SET FirstLogID = NewLogID;

            SET FirstSrvPacketID = NewSrvPacketID;

          ELSE

            /* Основная ветка расчета*/

            SET SecondLogID = NewLogID;

            SET SecondSrvPacketID = NewSrvPacketID;

            

            IF (SecondLogID - FirstLogID) > 1 THEN

          /* Найден разрыв */

          /* Из-за всяких комбинаций состояний LogId и SrvPacketId из-за особенностей работы телематического сервера

          и ТДМ вводим дополнительный анализ вставляемых записей, если запись не соответсвует указаным правилам, она 

          отбрасывается */

          IF (SecondSrvPacketID > FirstSrvPacketID) THEN

            IF EXISTS(SELECT NULL FROM datagps d WHERE (d.Mobitel_ID = MobitelID) AND ((d.LogID = FirstLogID) AND (d.SrvPacketID = FirstSrvPacketID))) THEN 

              IF EXISTS(SELECT NULL FROM datagps d WHERE (d.Mobitel_ID = MobitelID) AND ((d.LogID = SecondLogID) AND (d.SrvPacketID = SecondSrvPacketID))) THEN 



                CALL OnInsertDatagpsLost(MobitelID, FirstLogID, SecondLogID, FirstSrvPacketID, SecondSrvPacketID);

                IF NeedOptimize = 0 THEN SET NeedOptimize = 1; END IF;

                

              END IF;

            END IF;

          END IF;

        END IF;

            /* Переместим текущее второе значение на первую позицию

               для участия в следующей итерации в качестве начального значения */

            SET FirstLogID = SecondLogID;

            SET FirstSrvPacketID = SecondSrvPacketID;

          END IF;  

          FETCH CursorNewLogID INTO NewLogID, NewSrvPacketID;

        END WHILE;

        CLOSE CursorNewLogID;

      END;

      /********** END INSERT ROWS **********/  



      TRUNCATE TABLE datagpslost_ontmp;

    END IF;

      

    FETCH CursorLostRanges INTO BeginLogID, EndLogID, BeginSrvPacketID, EndSrvPacketID;

  END WHILE;

  CLOSE CursorLostRanges;

  

  /********** UPDATE MOBITELS **********/

    

  /* Если пропущенных записей у данного телетрека нет - 

     тогда ConfirmedID будет равен максимальному LogID 

     данного телетрека. Иначе - минимальный Begin_LogID

     из таблицы пропусков */

  SELECT MIN(Begin_LogID) INTO NewConfirmedID

  FROM datagpslost_on

  WHERE Mobitel_ID = MobitelID;

       

  IF NewConfirmedID IS NULL THEN

    SELECT MAX(LogID) INTO NewConfirmedID

    FROM datagps

    WHERE Mobitel_ID = MobitelID;

  END IF;  

    

  /* Обновим ConfirmedID если надо */

  UPDATE mobitels

  SET ConfirmedID = NewConfirmedID

  WHERE (Mobitel_ID = MobitelID) AND (ConfirmedID < NewConfirmedID);

    

  /********** END UPDATE MOBITELS **********/

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `OnLostDataGPS264` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `OnLostDataGPS264`(IN MobitelID integer(11), OUT NeedOptimize tinyint)
    SQL SECURITY INVOKER
    COMMENT 'РњРѕРґРёС„РёРєР°С†РёСЏ РґРёР°РїР°Р·РѕРЅРѕРІ РїСЂРѕРїСѓСЃРєРѕРІ. РђРЅР°Р»РёР· РґСѓР±Р»РёСЂСѓСЋС‰РёС… РґР°РЅРЅС‹С… Р·Р°РґР°РЅРЅРѕРіРѕ С‚РµР»РµС‚СЂРµРєР°.'
BEGIN

  /********** DECLARE **********/



  DECLARE NewConfirmedID int DEFAULT 0; /* РќРѕРІРѕРµ Р·РЅР°С‡РµРЅРёРµ ConfirmedID */

  DECLARE BeginLogID int; /* Begin_LogID РІ РєСѓСЂСЃРѕСЂРµ CursorLostRanges */

  DECLARE EndLogID int; /* End_LogID РІ РєСѓСЂСЃРѕСЂРµ CursorLostRanges */

  DECLARE BeginSrvPacketID bigint; /* Begin_SrvPacketID РІ РєСѓСЂСЃРѕСЂРµ CursorLostRanges */

  DECLARE EndSrvPacketID bigint; /* End_SrvPacketID РІ РєСѓСЂСЃРѕСЂРµ CursorLostRanges */

  DECLARE RowCountForAnalyze int DEFAULT 0; /* РљРѕР»РёС‡РµСЃС‚РІРѕ Р·Р°РїРёСЃРµР№ РґР»СЏ Р°РЅР°Р»РёР·Р° */

  DECLARE DataExists tinyint DEFAULT 1; /* Р¤Р»Р°Рі РЅР°Р»РёС‡РёСЏ РґР°РЅРЅС‹С… РїРѕСЃР»Рµ С„РµС‚С‡Р° */



  /* РљСѓСЂСЃРѕСЂ РґР»СЏ РїСЂРѕС…РѕРґР° РїРѕ РґРёР°РїР°Р·РѕРЅР°Рј РїСЂРѕРїСѓСЃРєРѕРІ С‚РµР»РµС‚СЂРµРєР° */

  DECLARE CursorLostRanges CURSOR FOR

  SELECT

    Begin_LogID,

    End_LogID,

    Begin_SrvPacketID,

    End_SrvPacketID

  FROM datagpslost_on

  WHERE Mobitel_ID = MobitelID;



  /* РљСѓСЂСЃРѕСЂ РґР»СЏ РїСЂРѕС…РѕРґР° РїРѕ РЅРѕРІС‹Рј LogID */

  DECLARE CursorNewLogID CURSOR FOR

  SELECT

    LogID,

    SrvPacketID

  FROM datagpslost_ontmp

  ORDER BY SrvPacketID;



  /* РћР±СЂР°Р±РѕС‚С‡РёРє РѕС‚СЃСѓС‚СЃС‚РІСѓСЋС‰РµР№ Р·Р°РїРёСЃРё РїСЂРё FETCH СЃР»РµРґСѓСЋС‰РµР№ Р·Р°РїРёСЃРё */

  DECLARE CONTINUE HANDLER FOR NOT FOUND SET DataExists = 0;



  /********** END DECLARE **********/



  SET NeedOptimize = 0;



  TRUNCATE TABLE datagpslost_ontmp;



  /* РџРµСЂРµР±РёСЂР°РµРј РґРёР°РїР°Р·РѕРЅС‹ Рё СЃРѕРєСЂР°С‰Р°РµРј СЂР°Р·СЂС‹РІС‹ РµСЃР»Рё СЌС‚Рѕ РІРѕР·РјРѕР¶РЅРѕ */

  SET DataExists = 1;

  OPEN CursorLostRanges;

  FETCH CursorLostRanges INTO BeginLogID, EndLogID, BeginSrvPacketID, EndSrvPacketID;

  WHILE DataExists = 1 DO

    /* Р—Р°РїРѕР»РЅРµРЅРёРµ РІСЂРµРјРµРЅРЅРѕР№ С‚Р°Р±Р»РёС†С‹ РґСѓР±Р»РёСЂСѓСЋС‰РёРјРё РґР°РЅРЅС‹РјРё С‚РµР»РµС‚СЂРµРєР°

       РґР»СЏ Р°РЅР°Р»РёР·Р° СЂР°Р·СЂС‹РІРѕРІ */

    INSERT INTO datagpslost_ontmp (LogID, SrvPacketID)

      SELECT DISTINCT

        LogID,

        SrvPacketID

      FROM datagpsbuffer_ontmp64

      WHERE (Mobitel_ID = MobitelID) AND (SrvPacketID > BeginSrvPacketID)

      AND (SrvPacketID < EndSrvPacketID)

      ORDER BY SrvPacketID;



    /* Р•СЃР»Рё РµСЃС‚СЊ РґР°РЅРЅС‹Рµ РјРѕРґРёС„РёС†РёСЂСѓРµРј РґРёР°РїР°Р·РѕРЅ */

    SELECT

      COUNT(1) INTO RowCountForAnalyze

    FROM datagpslost_ontmp;



    IF RowCountForAnalyze > 0 THEN

      /* Р”РѕР±Р°РІР»СЏРµРј РїРµСЂРІСѓСЋ Рё РїРѕСЃР»РµРґРЅСЋСЋ Р·Р°РїРёСЃРё РґР»СЏ Р°РЅР°Р»РёР·Р° */

      INSERT INTO datagpslost_ontmp (LogID, SrvPacketID)

        VALUES (BeginLogID, BeginSrvPacketID), (EndLogID, EndSrvPacketID);



      /* РЈРґР°Р»СЏРµРј СЃС‚Р°СЂС‹Р№ РґРёР°РїР°Р·РѕРЅ */

      DELETE

        FROM datagpslost_on

      WHERE (Mobitel_ID = MobitelID) AND (Begin_LogID = BeginLogID);



      /**********  INSERT ROWS **********/

      BEGIN

        DECLARE NewLogID int; /* Р—РЅР°С‡РµРЅРёРµ LogID РІ РєСѓСЂСЃРѕСЂРµ CursorNewLogID */

        DECLARE NewSrvPacketID bigint; /* Р—РЅР°С‡РµРЅРёРµ SrvPacketID РІ РєСѓСЂСЃРѕСЂРµ CursorNewLogID */

        DECLARE FirstLogID int DEFAULT -9999999; /* РџРµСЂРІРѕРµ Р·РЅР°С‡РµРЅРёРµ LogID РґР»СЏ Р°РЅР°Р»РёР·Р° */

        DECLARE SecondLogID int; /* Р’С‚РѕСЂРѕРµ Р·РЅР°С‡РµРЅРёРµ LogID РґР»СЏ Р°РЅР°Р»РёР·Р° */

        DECLARE FirstSrvPacketID bigint; /* РџРµСЂРІРѕРµ Р·РЅР°С‡РµРЅРёРµ SrvPacketID */

        DECLARE SecondSrvPacketID bigint; /* Р’С‚РѕСЂРѕРµ Р·РЅР°С‡РµРЅРёРµ SrvPacketID */



        /* РћР±СЂР°Р±РѕС‚С‡РёРє РѕС‚СЃСѓС‚СЃС‚РІСѓСЋС‰РµР№ Р·Р°РїРёСЃРё РїСЂРё FETCH СЃР»РµРґСѓСЋС‰РµР№ Р·Р°РїРёСЃРё */

        DECLARE CONTINUE HANDLER FOR NOT FOUND SET DataExists = 0;



        /* Р¤РѕСЂРјРёСЂРѕРІР°РЅРёРµ РєРѕРјР°РЅРґС‹-РІСЃС‚Р°РІРєРё РІ С‚Р°Р±Р»РёС†Сѓ РїСЂРѕРїСѓС‰РµРЅРЅС‹С… РґРёР°РїР°Р·РѕРЅРѕРІ */

        SET DataExists = 1;

        OPEN CursorNewLogID;

        FETCH CursorNewLogID INTO NewLogID, NewSrvPacketID;

        WHILE DataExists = 1 DO

          IF FirstLogID = -9999999 THEN

            /* РџРµСЂРІРѕРµ Р·РЅР°С‡РµРЅРёРµ РІ СЃРїРёСЃРєРµ */

            SET FirstLogID = NewLogID;

            SET FirstSrvPacketID = NewSrvPacketID;

          ELSE

            /* РћСЃРЅРѕРІРЅР°СЏ РІРµС‚РєР° СЂР°СЃС‡РµС‚Р°*/

            SET SecondLogID = NewLogID;

            SET SecondSrvPacketID = NewSrvPacketID;



            IF (SecondLogID - FirstLogID) > 1 THEN

          /* РќР°Р№РґРµРЅ СЂР°Р·СЂС‹РІ */

          /* РР·-Р·Р° РІСЃСЏРєРёС… РєРѕРјР±РёРЅР°С†РёР№ СЃРѕСЃС‚РѕСЏРЅРёР№ LogId Рё SrvPacketId РёР·-Р·Р° РѕСЃРѕР±РµРЅРЅРѕСЃС‚РµР№ СЂР°Р±РѕС‚С‹ С‚РµР»РµРјР°С‚РёС‡РµСЃРєРѕРіРѕ СЃРµСЂРІРµСЂР°

          Рё РўР”Рњ РІРІРѕРґРёРј РґРѕРїРѕР»РЅРёС‚РµР»СЊРЅС‹Р№ Р°РЅР°Р»РёР· РІСЃС‚Р°РІР»СЏРµРјС‹С… Р·Р°РїРёСЃРµР№, РµСЃР»Рё Р·Р°РїРёСЃСЊ РЅРµ СЃРѕРѕС‚РІРµС‚СЃРІСѓРµС‚ СѓРєР°Р·Р°РЅС‹Рј РїСЂР°РІРёР»Р°Рј, РѕРЅР° 

          РѕС‚Р±СЂР°СЃС‹РІР°РµС‚СЃСЏ */

          IF (SecondSrvPacketID > FirstSrvPacketID) THEN

            IF EXISTS(SELECT NULL FROM datagps64 d WHERE (d.Mobitel_ID = MobitelID) AND ((d.LogID = FirstLogID) AND (d.SrvPacketID = FirstSrvPacketID))) THEN 

              IF EXISTS(SELECT NULL FROM datagps64 d WHERE (d.Mobitel_ID = MobitelID) AND ((d.LogID = SecondLogID) AND (d.SrvPacketID = SecondSrvPacketID))) THEN 



                CALL OnInsertDatagpsLost(MobitelID, FirstLogID, SecondLogID, FirstSrvPacketID, SecondSrvPacketID);

                IF NeedOptimize = 0 THEN SET NeedOptimize = 1; END IF;

                

              END IF;

            END IF;

          END IF;

        END IF;

            /* РџРµСЂРµРјРµСЃС‚РёРј С‚РµРєСѓС‰РµРµ РІС‚РѕСЂРѕРµ Р·РЅР°С‡РµРЅРёРµ РЅР° РїРµСЂРІСѓСЋ РїРѕР·РёС†РёСЋ

               РґР»СЏ СѓС‡Р°СЃС‚РёСЏ РІ СЃР»РµРґСѓСЋС‰РµР№ РёС‚РµСЂР°С†РёРё РІ РєР°С‡РµСЃС‚РІРµ РЅР°С‡Р°Р»СЊРЅРѕРіРѕ Р·РЅР°С‡РµРЅРёСЏ */

            SET FirstLogID = SecondLogID;

            SET FirstSrvPacketID = SecondSrvPacketID;

          END IF;

          FETCH CursorNewLogID INTO NewLogID, NewSrvPacketID;

        END WHILE;

        CLOSE CursorNewLogID;

      END;

      /********** END INSERT ROWS **********/



      TRUNCATE TABLE datagpslost_ontmp;

    END IF;



    FETCH CursorLostRanges INTO BeginLogID, EndLogID, BeginSrvPacketID, EndSrvPacketID;

  END WHILE;

  CLOSE CursorLostRanges;



  /********** UPDATE MOBITELS **********/



  /* Р•СЃР»Рё РїСЂРѕРїСѓС‰РµРЅРЅС‹С… Р·Р°РїРёСЃРµР№ Сѓ РґР°РЅРЅРѕРіРѕ С‚РµР»РµС‚СЂРµРєР° РЅРµС‚ - 

     С‚РѕРіРґР° ConfirmedID Р±СѓРґРµС‚ СЂР°РІРµРЅ РјР°РєСЃРёРјР°Р»СЊРЅРѕРјСѓ LogID 

     РґР°РЅРЅРѕРіРѕ С‚РµР»РµС‚СЂРµРєР°. РРЅР°С‡Рµ - РјРёРЅРёРјР°Р»СЊРЅС‹Р№ Begin_LogID

     РёР· С‚Р°Р±Р»РёС†С‹ РїСЂРѕРїСѓСЃРєРѕРІ */

  SELECT

    MIN(Begin_LogID) INTO NewConfirmedID

  FROM datagpslost_on

  WHERE Mobitel_ID = MobitelID;



  IF NewConfirmedID IS NULL THEN

    SELECT

      MAX(LogID) INTO NewConfirmedID

    FROM datagps64

    WHERE Mobitel_ID = MobitelID;

  END IF;



  /* РћР±РЅРѕРІРёРј ConfirmedID РµСЃР»Рё РЅР°РґРѕ */

  UPDATE mobitels

  SET ConfirmedID = NewConfirmedID

  WHERE (Mobitel_ID = MobitelID) AND (ConfirmedID < NewConfirmedID);



/********** END UPDATE MOBITELS **********/

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `OnLostDataGPS64` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `OnLostDataGPS64`(IN MobitelID integer(11), OUT NeedOptimize tinyint)
    SQL SECURITY INVOKER
    COMMENT 'РџРѕРёСЃРє РїСЂРѕРїСѓСЃРєРѕРІ РІ online РґР°РЅРЅС‹С… Р·Р°РґР°РЅРЅРѕРіРѕ С‚РµР»РµС‚СЂРµРєР° Рё Р·Р°РїРѕР»РЅРµРЅРёРµ С‚Р°Р±Р»РёС†.'
BEGIN



  /********** DECLARE **********/



  DECLARE CurrentConfirmedID int DEFAULT 0; /* РўРµРєСѓС‰РµРµ Р·РЅР°С‡РµРЅРёРµ ConfirmedID */

  DECLARE NewConfirmedID int DEFAULT 0; /* РќРѕРІРѕРµ Р·РЅР°С‡РµРЅРёРµ ConfirmedID */

  DECLARE StartLogIDSelect int DEFAULT 0; /* min LogID РґР»СЏ РІС‹Р±РѕСЂРєРё */

  DECLARE FinishLogIDSelect int DEFAULT 0; /* max LogID РґР»СЏ РІС‹Р±РѕСЂРєРё */

  DECLARE MaxEndLogID int DEFAULT 0; /* max End_LogID РІ РїСЂРѕРїСѓС‰РµРЅРЅС‹С… РґРёР°РїР°Р·РѕРЅР°С… РґР°РЅРЅРѕРіРѕ С‚РµР»РµС‚СЂРµРєР° */



  DECLARE MinLogID_n int DEFAULT 0; /* РњРёРЅРёРјР°Р»СЊРЅС‹Р№ LogID РїРѕСЃР»Рµ ConfirmedID РІ РјРЅРѕР¶РµСЃС‚РІРµ РЅРѕРІС‹С… РґР°РЅРЅС‹С… */

  DECLARE MaxLogID_n int DEFAULT 0; /* РњР°РєСЃРёРјР°Р»СЊРЅС‹Р№ LogID РІ РјРЅРѕР¶РµСЃС‚РІРµ РЅРѕРІС‹С… РґР°РЅРЅС‹С… */



  DECLARE DataExists tinyint DEFAULT 1; /* Р¤Р»Р°Рі РЅР°Р»РёС‡РёСЏ РґР°РЅРЅС‹С… РїРѕСЃР»Рµ С„РµС‚С‡Р° */



  DECLARE NewLogID int; /* Р—РЅР°С‡РµРЅРёРµ LogID РІ РєСѓСЂСЃРѕСЂРµ CursorNewLogID */

  DECLARE NewSrvPacketID bigint; /* Р—РЅР°С‡РµРЅРёРµ SrvPacketID РІ РєСѓСЂСЃРѕСЂРµ CursorNewLogID */

  DECLARE FirstLogID int DEFAULT -9999999; /* РџРµСЂРІРѕРµ Р·РЅР°С‡РµРЅРёРµ LogID РґР»СЏ Р°РЅР°Р»РёР·Р° */

  DECLARE SecondLogID int; /* Р’С‚РѕСЂРѕРµ Р·РЅР°С‡РµРЅРёРµ LogID РґР»СЏ Р°РЅР°Р»РёР·Р° */

  DECLARE FirstSrvPacketID bigint; /* РџРµСЂРІРѕРµ Р·РЅР°С‡РµРЅРёРµ SrvPacketID */

  DECLARE SecondSrvPacketID bigint; /* Р’С‚РѕСЂРѕРµ Р·РЅР°С‡РµРЅРёРµ SrvPacketID */



  DECLARE tmpSrvPacketID bigint DEFAULT 0; /* Р—РЅР°С‡РµРЅРёРµ SrvPacketID РґР»СЏ РїРµСЂРІРѕР№ РёСЃРєСѓСЃСЃС‚РІРµРЅРЅРѕР№ Р·Р°РїРёСЃРё РІ Р°РЅР°Р»РёР·Рµ РЅРѕРІС‹С… РґР°РЅРЅС‹С…, РЅРµ РїРµСЂРµСЃРµРєР°СЋС‰РёС…СЃСЏ СЃ СЃСѓС‰РµСЃС‚РІСѓСЋС‰РёРјРё */



  /* РљСѓСЂСЃРѕСЂ РґР»СЏ РїСЂРѕС…РѕРґР° РїРѕ РЅРѕРІС‹Рј LogID */

  DECLARE CursorNewLogID CURSOR FOR

  SELECT

    LogID,

    SrvPacketID

  FROM datagpslost_ontmp;



  /* РћР±СЂР°Р±РѕС‚С‡РёРє РѕС‚СЃСѓС‚СЃС‚РІСѓСЋС‰РµР№ Р·Р°РїРёСЃРё РїСЂРё FETCH СЃР»РµРґСѓСЋС‰РµР№ Р·Р°РїРёСЃРё */

  DECLARE CONTINUE HANDLER FOR NOT FOUND SET DataExists = 0;



  /********** END DECLARE **********/



  SET NeedOptimize = 0;



  SELECT

    COALESCE(ConfirmedID, 0) INTO CurrentConfirmedID

  FROM mobitels

  WHERE Mobitel_ID = MobitelID;



  /* РњРёРЅРёРјР°Р»СЊРЅС‹Р№ LogID РІ РЅРѕРІРѕРј РЅР°Р±РѕСЂРµ РґР°РЅРЅС‹С… c РєРѕС‚РѕСЂС‹Рј Р±СѓРґРµРј СЂР°Р±РѕС‚Р°С‚СЊ */

  SELECT

    MIN(LogID) INTO MinLogID_n

  FROM datagpsbuffer_on64

  WHERE (Mobitel_ID = MobitelID) AND (LogID > CurrentConfirmedID);



  /* РњР°РєСЃРёРјР°Р»СЊРЅС‹Р№ LogID РІ РЅРѕРІРѕРј РЅР°Р±РѕСЂРµ РґР°РЅРЅС‹С… c РєРѕС‚РѕСЂС‹Рј Р±СѓРґРµРј СЂР°Р±РѕС‚Р°С‚СЊ */

  SELECT

    MAX(LogID) INTO MaxLogID_n

  FROM datagpsbuffer_on64

  WHERE Mobitel_ID = MobitelID;



  /* РњР°РєСЃРёРјР°Р»СЊРЅС‹Р№ End_LogID РІ РїСЂРѕРїСѓС‰РµРЅРЅС‹С… РґРёР°РїР°Р·РѕРЅР°С… РґР°РЅРЅРѕРіРѕ С‚РµР»РµС‚СЂРµРєР° */

  SELECT

    COALESCE(MAX(End_LogID), 0) INTO MaxEndLogID

  FROM datagpslost_on

  WHERE Mobitel_ID = MobitelID;



  /* РџСЂРѕРІРµСЂРёРј РµСЃС‚СЊ Р»Рё РґР°РЅРЅС‹Рµ РґР»СЏ Р°РЅР°Р»РёР·Р° */

  IF MinLogID_n IS NOT NULL THEN



    /********** PREPARE **********/



    TRUNCATE TABLE datagpslost_ontmp;



    IF MinLogID_n < MaxEndLogID THEN

      /* Р•СЃР»Рё  MinLogID_n < MaxEndLogID Р·РЅР°С‡РёС‚ РїСЂРёС€Р»Рё РґР°РЅРЅС‹Рµ, 

       РєРѕС‚РѕСЂС‹Рµ РІРѕР·РјРѕР¶РЅРѕ Р·Р°РєСЂРѕСЋС‚ С‡Р°СЃС‚СЊ РїСЂРѕРїСѓСЃРєРѕРІ. */



      /* РќР°С…РѕРґРёРј СЃС‚Р°СЂС‚РѕРІС‹Р№ LogID РґР»СЏ РїРµСЂРµСЃС‡РµС‚Р°. */

      SELECT

        COALESCE(Begin_LogID, MinLogID_n) INTO StartLogIDSelect

      FROM datagpslost_on

      WHERE (Mobitel_ID = MobitelID) AND (MinLogID_n > Begin_LogID)

      AND (MinLogID_n < End_LogID);



      /* РќР°С…РѕРґРёРј РїРѕСЃР»РµРґРЅРёР№ LogID РґР»СЏ РїРµСЂРµСЃС‡РµС‚Р°. */

      SELECT

        COALESCE(End_LogID, MaxLogID_n) INTO FinishLogIDSelect

      FROM datagpslost_on

      WHERE (Mobitel_ID = MobitelID) AND (MaxLogID_n > Begin_LogID)

      AND (MaxLogID_n < End_LogID);



      /* РЈРґР°Р»РёРј СЃС‚Р°СЂС‹Рµ Р·Р°РїРёСЃРё РёР· СЂРµРµСЃС‚СЂР° РїСЂРѕРїСѓС‰РµРЅРЅС‹С… Р·Р°РїРёСЃРµР№ 

         (СЃС‚Р°Р»Рё РЅРµР°РєС‚СѓР°Р»СЊРЅС‹РјРё, РЅР°РґРѕ РїРµСЂРµСЃС‡РёС‚Р°С‚СЊ) */

      DELETE

        FROM datagpslost_on

      WHERE (Mobitel_ID = MobitelID) AND (Begin_LogID >= StartLogIDSelect)

        AND (Begin_LogID <= FinishLogIDSelect);



      /* Р•СЃР»Рё РїРµСЂРІР°СЏ Р·Р°РїРёСЃСЊ LogID = 0 Рё СЌС‚РѕР№ Р·Р°РїРёСЃРё РЅРµС‚ РІ DataGps, С‚РѕРіРґР°

         РЅР°РґРѕ РґРѕР±Р°РІРёС‚СЊ РїРµСЂРІСѓСЋ С„РёРєС‚РёРІРЅСѓСЋ Р·Р°РїРёСЃСЊ РґР»СЏ Р°РЅР°Р»РёР·Р°. */

      IF (StartLogIDSelect = 0) AND (NOT EXISTS (SELECT

            1

          FROM datagps64

          WHERE (Mobitel_ID = MobitelID) AND (LogID = StartLogIDSelect))) THEN



        INSERT INTO datagpslost_ontmp (LogID, SrvPacketID)

          VALUES (0, 0);

      END IF;

    ELSE

      /* РџСЂРёС€Р»Рё РЅРѕРІС‹Рµ РґР°РЅРЅС‹Рµ. РќР°РґРѕ РґРѕР±Р°РІРёС‚СЊ РґР»СЏ Р°РЅР°Р»РёР·Р° РёСЃРєСѓСЃСЃС‚РІРµРЅРЅСѓСЋ Р·Р°РїРёСЃСЊ - 

         РЅРёР¶РЅСЋСЋ РіСЂР°РЅРёС†Сѓ */



      /* РќР°С…РѕРґРёРј СЃС‚Р°СЂС‚РѕРІС‹Р№ LogID РґР»СЏ РїРµСЂРµСЃС‡РµС‚Р°. */

      SELECT

        COALESCE(MAX(End_LogID), CurrentConfirmedID) INTO StartLogIDSelect

      FROM datagpslost_on

      WHERE Mobitel_ID = MobitelID;



      /* РќР°С…РѕРґРёРј РїРѕСЃР»РµРґРЅРёР№ LogID РґР»СЏ РїРµСЂРµСЃС‡РµС‚Р°. */

      SELECT

        MAX(LogID) INTO FinishLogIDSelect

      FROM datagpsbuffer_on64

      WHERE Mobitel_ID = MobitelID;



      /* Р’С‹Р±РёСЂР°РµРј РёР· datagps СЃРѕРѕС‚РІРµС‚СЃС‚РІСѓСЋС‰РµРµ Р·РЅР°С‡РµРЅРёРµ SrvPacketID  РґР»СЏ РїРµСЂРІРѕР№

         РёСЃРєСѓСЃСЃС‚РІРµРЅРЅРѕР№ Р·Р°РїРёСЃРё */

      SELECT

        COALESCE(SrvPacketID, 0) INTO tmpSrvPacketID

      FROM datagps64

      WHERE (Mobitel_ID = MobitelID) AND (LogID = StartLogIDSelect);



      /* РџРѕРјРµС‰Р°РµРј РІ С‚Р°Р±Р»РёС†Сѓ datagpslost_ontmp64 РґР»СЏ Р°РЅР°Р»РёР·Р° РїСЂРѕРїСѓСЃРєРѕРІ 

         РґРѕРїРѕР»РЅРёС‚РµР»СЊРЅСѓСЋ РїРµСЂРІСѓСЋ Р·Р°РїРёСЃСЊ */

      INSERT INTO datagpslost_ontmp (LogID, SrvPacketID)

        VALUES (StartLogIDSelect, tmpSrvPacketID);

    END IF; -- IF MinLogID_n < MaxEndLogID   



    /********** END PREPARE **********/



    /**********  INSERT ROWS **********/



    /* Р—Р°РїРѕР»РЅРµРЅРёРµ РІСЂРµРјРµРЅРЅРѕР№ С‚Р°Р±Р»РёС†С‹ РїРѕСЃР»РµРґРЅРёРјРё РґР°РЅРЅС‹РјРё С‚РµР»РµС‚СЂРµРєР°

       РґР»СЏ Р°РЅР°Р»РёР·Р° СЂР°Р·СЂС‹РІРѕРІ */

    INSERT INTO datagpslost_ontmp (LogID, SrvPacketID)

      SELECT

        LogID,

        SrvPacketID

      FROM datagps64

      WHERE (Mobitel_ID = MobitelID) AND (LogID >= StartLogIDSelect)

      AND (LogID <= FinishLogIDSelect)

      ORDER BY LogID;



    /* Р¤РѕСЂРјРёСЂРѕРІР°РЅРёРµ РєРѕРјР°РЅРґС‹-РІСЃС‚Р°РІРєРё РІ С‚Р°Р±Р»РёС†Сѓ РїСЂРѕРїСѓС‰РµРЅРЅС‹С… РґРёР°РїР°Р·РѕРЅРѕРІ */

    SET DataExists = 1;

    OPEN CursorNewLogID;

    FETCH CursorNewLogID INTO NewLogID, NewSrvPacketID;

    WHILE DataExists = 1 DO

      IF FirstLogID = -9999999 THEN

        /* РџРµСЂРІРѕРµ Р·РЅР°С‡РµРЅРёРµ РІ СЃРїРёСЃРєРµ */

        SET FirstLogID = NewLogID;

        SET FirstSrvPacketID = NewSrvPacketID;

      ELSE

        /* РћСЃРЅРѕРІРЅР°СЏ РІРµС‚РєР° СЂР°СЃС‡РµС‚Р°*/

        SET SecondLogID = NewLogID;

        SET SecondSrvPacketID = NewSrvPacketID;



        IF (SecondLogID - FirstLogID) > 1 THEN

          /* РќР°Р№РґРµРЅ СЂР°Р·СЂС‹РІ */

          /* РР·-Р·Р° РІСЃСЏРєРёС… РєРѕРјР±РёРЅР°С†РёР№ СЃРѕСЃС‚РѕСЏРЅРёР№ LogId Рё SrvPacketId РёР·-Р·Р° РѕСЃРѕР±РµРЅРЅРѕСЃС‚РµР№ СЂР°Р±РѕС‚С‹ С‚РµР»РµРјР°С‚РёС‡РµСЃРєРѕРіРѕ СЃРµСЂРІРµСЂР°

          Рё РўР”Рњ РІРІРѕРґРёРј РґРѕРїРѕР»РЅРёС‚РµР»СЊРЅС‹Р№ Р°РЅР°Р»РёР· РІСЃС‚Р°РІР»СЏРµРјС‹С… Р·Р°РїРёСЃРµР№, РµСЃР»Рё Р·Р°РїРёСЃСЊ РЅРµ СЃРѕРѕС‚РІРµС‚СЃРІСѓРµС‚ СѓРєР°Р·Р°РЅС‹Рј РїСЂР°РІРёР»Р°Рј, РѕРЅР° 

          РѕС‚Р±СЂР°СЃС‹РІР°РµС‚СЃСЏ */

          IF (SecondSrvPacketID > FirstSrvPacketID) THEN

            IF EXISTS(SELECT NULL FROM datagps64 d WHERE (d.Mobitel_ID = MobitelID) AND ((d.LogID = FirstLogID) AND (d.SrvPacketID = FirstSrvPacketID))) THEN 

              IF EXISTS(SELECT NULL FROM datagps64 d WHERE (d.Mobitel_ID = MobitelID) AND ((d.LogID = SecondLogID) AND (d.SrvPacketID = SecondSrvPacketID))) THEN 



                CALL OnInsertDatagpsLost(MobitelID, FirstLogID, SecondLogID, FirstSrvPacketID, SecondSrvPacketID);

                IF NeedOptimize = 0 THEN SET NeedOptimize = 1; END IF;

                

              END IF;

            END IF;

          END IF;

        END IF;

        /* РџРµСЂРµРјРµСЃС‚РёРј С‚РµРєСѓС‰РµРµ РІС‚РѕСЂРѕРµ Р·РЅР°С‡РµРЅРёРµ РЅР° РїРµСЂРІСѓСЋ РїРѕР·РёС†РёСЋ

           РґР»СЏ СѓС‡Р°СЃС‚РёСЏ РІ СЃР»РµРґСѓСЋС‰РµР№ РёС‚РµСЂР°С†РёРё РІ РєР°С‡РµСЃС‚РІРµ РЅР°С‡Р°Р»СЊРЅРѕРіРѕ Р·РЅР°С‡РµРЅРёСЏ */

        SET FirstLogID = SecondLogID;

        SET FirstSrvPacketID = SecondSrvPacketID;

      END IF;

      FETCH CursorNewLogID INTO NewLogID, NewSrvPacketID;

    END WHILE;

    CLOSE CursorNewLogID;



    /********** END INSERT ROWS **********/



    /********** UPDATE MOBITELS **********/



    /* Р•СЃР»Рё РїСЂРѕРїСѓС‰РµРЅРЅС‹С… Р·Р°РїРёСЃРµР№ Сѓ РґР°РЅРЅРѕРіРѕ С‚РµР»РµС‚СЂРµРєР° РЅРµС‚ - 

       С‚РѕРіРґР° ConfirmedID Р±СѓРґРµС‚ СЂР°РІРµРЅ РјР°РєСЃРёРјР°Р»СЊРЅРѕРјСѓ LogID 

       РґР°РЅРЅРѕРіРѕ С‚РµР»РµС‚СЂРµРєР°. РРЅР°С‡Рµ - РјРёРЅРёРјР°Р»СЊРЅС‹Р№ Begin_LogID

       РёР· С‚Р°Р±Р»РёС†С‹ РїСЂРѕРїСѓСЃРєРѕРІ */

    SELECT

      MIN(Begin_LogID) INTO NewConfirmedID

    FROM datagpslost_on

    WHERE Mobitel_ID = MobitelID;



    IF NewConfirmedID IS NULL THEN

      SELECT

        MAX(LogID) INTO NewConfirmedID

      FROM datagps64

      WHERE Mobitel_ID = MobitelID;

    END IF;



    /* РћР±РЅРѕРІРёРј ConfirmedID РµСЃР»Рё РЅР°РґРѕ */

    UPDATE mobitels

    SET ConfirmedID = NewConfirmedID

    WHERE (Mobitel_ID = MobitelID) AND (ConfirmedID < NewConfirmedID);



    /********** END UPDATE MOBITELS **********/



    TRUNCATE TABLE datagpslost_ontmp;

  END IF; -- IF MaxEndLogID IS NOT NULL  

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `OnTransferBuffer` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `OnTransferBuffer`()
    SQL SECURITY INVOKER
    COMMENT 'Переносит GPS данные из буферной таблицы в datagps'
BEGIN

  DECLARE MobitelIDInCursor INT; /* Текущее значение MobitelID */

  DECLARE DataExists TINYINT DEFAULT 1; /* Флаг наличия данных после фетча */

  DECLARE NeedOptimize TINYINT DEFAULT 0; /* Нужна оптимизация или нет */

  DECLARE NeedOptimizeParam TINYINT;

  

  DECLARE TmpMaxUnixTime INT; /* Временная переменная для хранения Max UnixTime из таблицы online */



  /* Курсор по телетрекам в множестве новых данных */

  DECLARE CursorMobitelsInsertSet CURSOR FOR

    SELECT DISTINCT(Mobitel_ID) FROM datagpsbuffer_on;

  /* Курсор по телетрекам в множестве повторных данных */

  DECLARE CursorMobitelsUpdateSet CURSOR FOR

    SELECT DISTINCT(Mobitel_ID) FROM datagpsbuffer_ontmp;  



  /* Обработчик отсутствующей записи при FETCH следующей записи */

  DECLARE CONTINUE HANDLER FOR NOT FOUND SET DataExists = 0;



  CALL OnDeleteDuplicates();

  CALL OnCorrectInfotrackLogId();

  

  /* Сохраняем записи, которые уже есть в БД, для второго этапа анализа пропусков 

     Используется процедурой OnLostDataGPS2. */

  INSERT INTO datagpsbuffer_ontmp (Mobitel_ID, LogID, SrvPacketID)

    SELECT b.Mobitel_ID, b.LogID, b.SrvPacketID

    FROM datagpsbuffer_on b LEFT JOIN datagps d ON

      (d.Mobitel_ID = b.Mobitel_ID) AND (d.LogID = b.LogID)

    WHERE d.LogID IS NOT NULL;

       

  /* -------------------- Заполнение таблицы Online ---------------------- */  

  /* Удаление из таблицы online дублирующих строк таблицы datagpsbuffer_on */

  /* по полям Mobitel_ID и LogID */

  DELETE o

  FROM `online` o, datagpsbuffer_on dgb

  WHERE (o.Mobitel_ID = dgb.Mobitel_ID) AND (o.LogID = dgb.LogID);

  

  SET DataExists = 1;

  OPEN CursorMobitelsInsertSet;

  FETCH CursorMobitelsInsertSet INTO MobitelIDInCursor;

  WHILE DataExists = 1 DO

    /* Нахождение Max значения UnixTime в таблице online для заданного

       телетрека. p.s. UnixTime в таблице online только валидный */

    SELECT COALESCE(MAX(UnixTime), 0) INTO TmpMaxUnixTime

    FROM online FORCE INDEX (IDX_Mobitelid)

    WHERE Mobitel_ID = MobitelIDInCursor;



    /* Вставка новых записей (максимум 100)каждого телетрека в online */

    INSERT INTO `online` (

      Mobitel_ID, LogID, UnixTime, Latitude, Longitude, Altitude,

      Direction, Speed, Valid, `Events`,

      Sensor1, Sensor2, Sensor3, Sensor4, Sensor5, Sensor6, Sensor7, Sensor8,

      Counter1, Counter2, Counter3, Counter4, whatIs)

    SELECT

      Mobitel_ID, LogID, UnixTime, Latitude, Longitude, Altitude,

      Direction, Speed, Valid, `Events`,

      Sensor1, Sensor2, Sensor3, Sensor4, Sensor5, Sensor6, Sensor7, Sensor8,

      Counter1, Counter2, Counter3, Counter4, whatIs

    FROM (

      SELECT *

      FROM datagpsbuffer_on

      WHERE (Mobitel_ID = MobitelIDInCursor)  AND 

        (UnixTime > TmpMaxUnixTime) AND (Valid = 1)

      GROUP BY Mobitel_ID, LogID

      ORDER BY UnixTime DESC

      LIMIT 100) AS T

    ORDER BY UnixTime ASC;



    /* Удаление строк из таблицы оперативных данных не удовлетворяющие

       условиям хранения - не являются последними 100 строками */

    DELETE FROM `online`

    WHERE (Mobitel_ID = MobitelIDInCursor) AND (UnixTime < 

      (SELECT COALESCE(MIN(UnixTime), 0) 

       FROM (

         SELECT UnixTime

         FROM `online`

         WHERE Mobitel_ID = MobitelIDInCursor 

         ORDER BY UnixTime DESC

         LIMIT 100) T1)); 

  

    FETCH CursorMobitelsInsertSet INTO MobitelIDInCursor;

  END WHILE;

  CLOSE CursorMobitelsInsertSet;

  /* ---------------- Online ---------------- */ 

  

  /* Зачем-то нужен апдейт ... */

  UPDATE datagps d, datagpsbuffer_on b SET

    d.Latitude = b.Latitude,

    d.Longitude = b.Longitude,

    d.Altitude = b.Altitude,

    d.UnixTime = b.UnixTime,

    d.Speed = b.Speed,

    d.Direction = b.Direction,

    d.Valid = b.Valid,

    d.InMobitelID = b.LogID,

    d.Events = b.Events,

    d.Sensor1 = b.Sensor1,

    d.Sensor2 = b.Sensor2,

    d.Sensor3 = b.Sensor3,

    d.Sensor4 = b.Sensor4,

    d.Sensor5 = b.Sensor5,

    d.Sensor6 = b.Sensor6,

    d.Sensor7 = b.Sensor7,

    d.Sensor8 = b.Sensor8,

    d.whatIs = b.whatIs,

    d.Counter1 = b.Counter1,

    d.Counter2 = b.Counter2,

    d.Counter3 = b.Counter3,

    d.Counter4 = b.Counter4,

    d.SrvPacketID = b.SrvPacketID

  WHERE (d.Mobitel_ID = b.Mobitel_ID) AND (d.LogID = b.LogID)

    AND (d.SrvPacketID < b.SrvPacketID);



  /* Удалим записи которые участвовали в апдейте */

  DELETE b

  FROM datagps d, datagpsbuffer_on b

  WHERE (d.Mobitel_ID = b.Mobitel_ID) AND (d.LogID = b.LogID);



  /* Вставка новых записей*/

  INSERT INTO datagps (

    Mobitel_ID, LogID, UnixTime, Latitude, Longitude, Altitude,

    Direction, Speed, Valid, `Events`, InMobitelID,

    Sensor1, Sensor2, Sensor3, Sensor4, Sensor5, Sensor6, Sensor7, Sensor8,

    Counter1, Counter2, Counter3, Counter4, whatIs, SrvPacketID)

  SELECT

    Mobitel_ID, LogID, UnixTime, Latitude, Longitude, Altitude,

    Direction, Speed, Valid, `Events`, LogID,

    Sensor1, Sensor2, Sensor3, Sensor4, Sensor5, Sensor6, Sensor7, Sensor8,

    Counter1, Counter2, Counter3, Counter4, whatIs, SrvPacketID

  FROM datagpsbuffer_on

  GROUP BY Mobitel_ID, LogID;



  /* ------------------- FETCH Mobitels (INSERT SET) ----------------------- */

  SET DataExists = 1;

  OPEN CursorMobitelsInsertSet;

  FETCH CursorMobitelsInsertSet INTO MobitelIDInCursor;

  WHILE DataExists = 1 DO

    /* ------ Обновление времени последней вставки записей ------- */

    UPDATE mobitels SET LastInsertTime = UNIX_TIMESTAMP(NOW())

    WHERE Mobitel_ID = MobitelIDInCursor;

       

    /* ------ Обновление списка пропущенных записей -------------- */

    CALL OnLostDataGPS(MobitelIDInCursor, NeedOptimizeParam);

    SET NeedOptimize = GREATEST(NeedOptimize, NeedOptimizeParam);

    FETCH CursorMobitelsInsertSet INTO MobitelIDInCursor;

  END WHILE;

  CLOSE CursorMobitelsInsertSet;



  /* Очистка буфера */

  TRUNCATE TABLE datagpsbuffer_on;

    

  /* ------------------- FETCH Mobitels (UPDATE SET) ---------------------- */

  SET DataExists = 1;

  OPEN CursorMobitelsUpdateSet;

  FETCH CursorMobitelsUpdateSet INTO MobitelIDInCursor;

  WHILE DataExists = 1 DO

    /* ---- Обновление списка пропущенных записей по второму алгоритму --- */

    CALL OnLostDataGPS2(MobitelIDInCursor, NeedOptimizeParam);

    SET NeedOptimize = GREATEST(NeedOptimize, NeedOptimizeParam);

    FETCH CursorMobitelsUpdateSet INTO MobitelIDInCursor;

  END WHILE;

  CLOSE CursorMobitelsUpdateSet;

  

  /* Очистка вспомогательного буфера */

  TRUNCATE TABLE datagpsbuffer_ontmp;



  /* Были изменения - сделаем оптимизацию */

  /*IF NeedOptimize = 1 THEN

    OPTIMIZE TABLE datagpslost_on;

  END IF; */           

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `OnTransferBuffer64` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `OnTransferBuffer64`()
    SQL SECURITY INVOKER
BEGIN

  DECLARE MobitelIDInCursor int; /* пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ MobitelID */

  DECLARE DataExists tinyint DEFAULT 1; /* пїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅ */

  DECLARE NeedOptimize tinyint DEFAULT 0; /* пїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅ пїЅпїЅпїЅ */

  DECLARE NeedOptimizeParam tinyint;



  DECLARE TmpMaxUnixTime int; /* пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ Max UnixTime пїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ online */



  /* пїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ */

  DECLARE CursorMobitelsInsertSet CURSOR FOR

  SELECT DISTINCT

    (Mobitel_ID)

  FROM datagpsbuffer_on64;

  /* пїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ */

  DECLARE CursorMobitelsUpdateSet CURSOR FOR

  SELECT DISTINCT

    (Mobitel_ID)

  FROM datagpsbuffer_ontmp64;



  /* пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅ FETCH пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ */

  DECLARE CONTINUE HANDLER FOR NOT FOUND SET DataExists = 0;

  /*DECLARE EXIT HANDLER FOR SQLEXCEPTION 

  BEGIN

    ROLLBACK;

    SELECT 'An error has occurred, operation rollbacked and the stored procedure was terminated';

  end;*/



  CALL delDupSrvPacket();

  CALL OnDeleteDuplicates64();

  /*CALL OnCorrectInfotrackLogId64();*/



  /* пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ, пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅ пїЅпїЅпїЅпїЅ пїЅ пїЅпїЅ, пїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ 

     пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ OnLostDataGPS264. */

  /*INSERT INTO datagpsbuffer_ontmp64 (Mobitel_ID, LogID, SrvPacketID)

    SELECT

      b.Mobitel_ID,

      b.LogID,

      b.SrvPacketID

    FROM datagpsbuffer_on64 b

      LEFT JOIN datagps64 d

        ON (d.Mobitel_ID = b.Mobitel_ID) AND (d.LogID = b.LogID)

    WHERE d.LogID IS NOT NULL GROUP BY d.SrvPacketID;*/

 DROP TEMPORARY TABLE IF EXISTS temp1;

  DROP TABLE IF EXISTS temp1;

  CREATE TEMPORARY TABLE temp1  SELECT

      b.Mobitel_ID,

      b.LogID,

      b.SrvPacketID

    FROM datagpsbuffer_on64 b

      LEFT JOIN datagps64 d

        ON (d.Mobitel_ID = b.Mobitel_ID) AND (d.LogID = b.LogID)

    WHERE d.LogID IS NOT NULL GROUP BY d.SrvPacketID;



INSERT INTO datagpsbuffer_ontmp64 (Mobitel_ID, LogID, SrvPacketID) SELECT * FROM temp1 GROUP BY SrvPacketID;



DROP TEMPORARY TABLE IF EXISTS temp1;


  /* -------------------- пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ Online ---------------------- */

  /* пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ online пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ datagpsbuffer_on64 */

  /* пїЅпїЅ пїЅпїЅпїЅпїЅпїЅ Mobitel_ID пїЅ LogID */

  DELETE o

    FROM online64 o, datagpsbuffer_on64 dgb

  WHERE (o.Mobitel_ID = dgb.Mobitel_ID) AND (o.LogID = dgb.LogID);



  SET DataExists = 1;

  OPEN CursorMobitelsInsertSet;

  FETCH CursorMobitelsInsertSet INTO MobitelIDInCursor;

  WHILE DataExists = 1 DO

    /* пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ Max пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ UnixTime пїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ online пїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ

       пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ. p.s. UnixTime пїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ online пїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ */

    SELECT

      COALESCE(MAX(UnixTime), 0) INTO TmpMaxUnixTime

    FROM online64 FORCE INDEX (IDX_Mobitelid64)

    WHERE Mobitel_ID = MobitelIDInCursor;



    /* пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ (пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ 100)пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅ online */

    INSERT INTO online64 (Mobitel_ID, LogID, UnixTime, Latitude, Longitude, Acceleration,

    Direction, Speed, Valid, `Events`,

    Satellites, RssiGsm, SensorsSet, Sensors, Voltage, DGPS)

      SELECT

        Mobitel_ID,

        LogID,

        UnixTime,

        Latitude,

        Longitude,

        Acceleration,

        Direction,

        Speed,

        Valid,

        `Events`,

        Satellites,

        RssiGsm,

        SensorsSet,

        Sensors,

        Voltage,

        DGPS

      FROM (SELECT

          *

        FROM datagpsbuffer_on64

        WHERE (Mobitel_ID = MobitelIDInCursor) AND

        (UnixTime > TmpMaxUnixTime) AND (Valid = 1)

        GROUP BY Mobitel_ID,

                 LogID

        ORDER BY UnixTime DESC

        LIMIT 100) AS T

      ORDER BY UnixTime ASC;



    /* пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅ пїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ

       пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ - пїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ 100 пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ */

    DELETE

      FROM online64

    WHERE (Mobitel_ID = MobitelIDInCursor) AND (UnixTime < (SELECT

          COALESCE(MIN(UnixTime), 0)

        FROM (SELECT

            UnixTime

          FROM online64

          WHERE Mobitel_ID = MobitelIDInCursor

          ORDER BY UnixTime DESC

          LIMIT 100) T1));



    FETCH CursorMobitelsInsertSet INTO MobitelIDInCursor;

  END WHILE;

  CLOSE CursorMobitelsInsertSet;

  /* ---------------- Online ---------------- */

  /* пїЅпїЅпїЅпїЅпїЅ-пїЅпїЅ пїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ ... */

  UPDATE datagps64 d, datagpsbuffer_on64 b

  SET d.Latitude = b.Latitude,

      d.Longitude = b.Longitude,

      d.Acceleration = b.Acceleration,

      d.UnixTime = b.UnixTime,

      d.Speed = b.Speed,

      d.Direction = b.Direction,

      d.Valid = b.Valid,

      d.LogID = b.LogID,

      d.`Events` = b.`Events`,

      d.Satellites = b.Satellites,

      d.RssiGsm = b.RssiGsm,

      d.SensorsSet = b.SensorsSet,

      d.Sensors = b.Sensors,

      d.Voltage = b.Voltage,

      d.DGPS = b.DGPS,

      d.SrvPacketID = b.SrvPacketID

  WHERE (d.Mobitel_ID = b.Mobitel_ID) AND (d.LogID = b.LogID)

  AND (d.SrvPacketID < b.SrvPacketID);



  /* пїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ */

  DELETE b

    FROM datagps64 d, datagpsbuffer_on64 b

  WHERE (d.Mobitel_ID = b.Mobitel_ID) AND (d.LogID = b.LogID);



    /* пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ */ 

  INSERT INTO datagps64 (Mobitel_ID, LogID, UnixTime, Latitude, Longitude, Acceleration,

  Direction, Speed, Valid, `Events`,

  Satellites, RssiGsm, SensorsSet, Sensors, Voltage, DGPS, SrvPacketID)

    SELECT

      Mobitel_ID,

      LogID,

      UnixTime,

      Latitude,

      Longitude,

      Acceleration,

      Direction,

      Speed,

      Valid,

      `Events`,

      Satellites,

      RssiGsm,

      SensorsSet,

      Sensors,

      Voltage,

      DGPS,

      SrvPacketID

    FROM datagpsbuffer_on64

    GROUP BY Mobitel_ID,

             LogID;



  /* ------------------- FETCH Mobitels (INSERT SET) ----------------------- */

  SET DataExists = 1;

  OPEN CursorMobitelsInsertSet;

  FETCH CursorMobitelsInsertSet INTO MobitelIDInCursor;

  WHILE DataExists = 1 DO

    /* ------ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ ------- */

    UPDATE mobitels

    SET LastInsertTime = UNIX_TIMESTAMP(NOW())

    WHERE Mobitel_ID = MobitelIDInCursor;



    /* ------ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ -------------- */

    CALL OnLostDataGPS64(MobitelIDInCursor, NeedOptimizeParam);

    SET NeedOptimize = GREATEST(NeedOptimize, NeedOptimizeParam);

    FETCH CursorMobitelsInsertSet INTO MobitelIDInCursor;

  END WHILE;

  CLOSE CursorMobitelsInsertSet;



  /* пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ */

  TRUNCATE TABLE datagpsbuffer_on64;



  /* ------------------- FETCH Mobitels (UPDATE SET) ---------------------- */

  SET DataExists = 1;

  OPEN CursorMobitelsUpdateSet;

  FETCH CursorMobitelsUpdateSet INTO MobitelIDInCursor;

  WHILE DataExists = 1 DO

    /* ---- пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ --- */

    CALL OnLostDataGPS264(MobitelIDInCursor, NeedOptimizeParam);

    SET NeedOptimize = GREATEST(NeedOptimize, NeedOptimizeParam);

    FETCH CursorMobitelsUpdateSet INTO MobitelIDInCursor;

  END WHILE;

  CLOSE CursorMobitelsUpdateSet;



  /* пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ */

  TRUNCATE TABLE datagpsbuffer_ontmp64;



  /* пїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ - пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ */

  /*IF NeedOptimize = 1 THEN

    OPTIMIZE TABLE datagpslost_on;

  END IF;*/

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `PopListMobitelConfig` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `PopListMobitelConfig`()
    SQL SECURITY INVOKER
    COMMENT 'Выборка настроек телетреков для работы в режиме POP3'
BEGIN
  SELECT m.Mobitel_ID AS MobitelID, c.devIdShort AS DevIdShort,
    COALESCE(
      (SELECT s.EmailMobitel 
       FROM Mobitels m2 JOIN ServiceSend s ON s.ID = m2.ServiceSend_ID 
       WHERE m2.Mobitel_ID = m.Mobitel_ID
       ORDER BY s.ServiceSend_ID DESC
       LIMIT 1), "") AS Email
  FROM mobitels m JOIN internalmobitelconfig c ON c.ID = m.InternalMobitelConfig_ID
  WHERE (c.InternalMobitelConfig_ID = (
    SELECT intConf.InternalMobitelConfig_ID
    FROM internalmobitelconfig intConf
    WHERE (intConf.ID = c.ID)
    ORDER BY intConf.InternalMobitelConfig_ID DESC
    LIMIT 1)) AND (c.devIdShort IS NOT NULL) AND (c.devIdShort <> _cp1251 '')
  ORDER BY m.Mobitel_ID;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `PopTransferBuffer` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `PopTransferBuffer`()
    SQL SECURITY INVOKER
    COMMENT 'Переносит GPS данные из буферной таблицы в datagps'
BEGIN
  DECLARE MobitelIDInCursor INT; 
  DECLARE DataExists TINYINT DEFAULT 1; 
  
  DECLARE TmpMaxUnixTime INT; 

  DECLARE CursorMobitels CURSOR FOR
    SELECT DISTINCT(Mobitel_ID) FROM datagpsbuffer_pop;

  
  DECLARE CONTINUE HANDLER FOR NOT FOUND SET DataExists = 0;

    
  
  
  DELETE o
  FROM online o, datagpsbuffer_pop dgb
  WHERE (o.Mobitel_ID = dgb.Mobitel_ID) AND (o.LogID = dgb.LogID);
  
  SET DataExists = 1;
  OPEN CursorMobitels;
  FETCH CursorMobitels INTO MobitelIDInCursor;
  WHILE DataExists = 1 DO
    
    SELECT COALESCE(MAX(UnixTime), 0) INTO TmpMaxUnixTime
    FROM online FORCE INDEX (IDX_Mobitelid)
    WHERE Mobitel_ID = MobitelIDInCursor;

    
    INSERT INTO online (
      Mobitel_ID, LogID, UnixTime, Latitude, Longitude, Altitude,
      Direction, Speed, Valid, `Events`,
      Sensor1, Sensor2, Sensor3, Sensor4, Sensor5, Sensor6, Sensor7, Sensor8,
      Counter1, Counter2, Counter3, Counter4, whatIs)
    SELECT
      Mobitel_ID, LogID, UnixTime, Latitude, Longitude, Altitude,
      Direction, Speed, Valid, `Events`,
      Sensor1, Sensor2, Sensor3, Sensor4, Sensor5, Sensor6, Sensor7, Sensor8,
      Counter1, Counter2, Counter3, Counter4, whatIs
    FROM (
      SELECT *
      FROM datagpsbuffer_pop
      WHERE (Mobitel_ID = MobitelIDInCursor)  AND 
        (UnixTime > TmpMaxUnixTime) AND (Valid = 1)
      GROUP BY Mobitel_ID, LogID
      ORDER BY UnixTime DESC
      LIMIT 100) AS T
    ORDER BY UnixTime ASC;

    
    DELETE FROM online
    WHERE (Mobitel_ID = MobitelIDInCursor) AND (UnixTime < 
      (SELECT COALESCE(MIN(UnixTime), 0) 
       FROM (
         SELECT UnixTime
         FROM online
         WHERE Mobitel_ID = MobitelIDInCursor 
         ORDER BY UnixTime DESC
         LIMIT 100) T1)); 
  
    FETCH CursorMobitels INTO MobitelIDInCursor;
  END WHILE;
  CLOSE CursorMobitels;
    

  
  UPDATE datagps d, datagpsbuffer_pop b SET
    d.Latitude = b.Latitude,
    d.Longitude = b.Longitude,
    d.Altitude = b.Altitude,
    d.UnixTime = b.UnixTime,
    d.Speed = b.Speed,
    d.Direction = b.Direction,
    d.Valid = b.Valid,
    d.InMobitelID = b.LogID,
    d.`Events` = b.`Events`,
    d.Sensor1 = b.Sensor1,
    d.Sensor2 = b.Sensor2,
    d.Sensor3 = b.Sensor3,
    d.Sensor4 = b.Sensor4,
    d.Sensor5 = b.Sensor5,
    d.Sensor6 = b.Sensor6,
    d.Sensor7 = b.Sensor7,
    d.Sensor8 = b.Sensor8,
    d.whatIs = b.whatIs,
    d.Counter1 = b.Counter1,
    d.Counter2 = b.Counter2,
    d.Counter3 = b.Counter3,
    d.Counter4 = b.Counter4
  WHERE (d.Mobitel_ID = b.Mobitel_ID) AND (d.LogID = b.LogID);

  
  DELETE b
  FROM datagps d, datagpsbuffer_pop b
  WHERE (d.Mobitel_ID = b.Mobitel_ID) AND (d.LogID = b.LogID);

  
  INSERT INTO datagps (
    Mobitel_ID, LogID, UnixTime, Latitude, Longitude, Altitude,
    Direction, Speed, Valid, `Events`, InMobitelID,
    Sensor1, Sensor2, Sensor3, Sensor4, Sensor5, Sensor6, Sensor7, Sensor8,
    Counter1, Counter2, Counter3, Counter4, whatIs)
  SELECT
    Mobitel_ID, LogID, UnixTime, Latitude, Longitude, Altitude,
    Direction, Speed, Valid, `Events`, LogID,
    Sensor1, Sensor2, Sensor3, Sensor4, Sensor5, Sensor6, Sensor7, Sensor8,
    Counter1, Counter2, Counter3, Counter4, whatIs
  FROM datagpsbuffer_pop
  GROUP BY Mobitel_ID, LogID;

  
  TRUNCATE TABLE datagpsbuffer_pop;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `RfFillLostDataGPS` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `RfFillLostDataGPS`()
    COMMENT 'Поиск пропусков в RF данных и заполнение таблицы datagpslost'
BEGIN
	DECLARE MobitelIDInCursor INT; 
	DECLARE DataExists TINYINT DEFAULT 1; 
	DECLARE NeedOptimize TINYINT DEFAULT 0; 
	DECLARE NeedOptimizeParam TINYINT;

	
	DECLARE CursorMobitels CURSOR FOR
		SELECT m.Mobitel_ID AS Mobitel_ID
		FROM mobitels m
			JOIN internalmobitelconfig c ON (c.ID = m.InternalMobitelConfig_ID)
		WHERE (c.InternalMobitelConfig_ID = (
			SELECT intConf.InternalMobitelConfig_ID
			FROM internalmobitelconfig intConf
			WHERE intConf.ID = c.ID 
			ORDER BY intConf.InternalMobitelConfig_ID DESC
			LIMIT 1)) AND
			(c.moduleIdRf IS NOT NULL) AND (c.moduleIdRf <> _cp1251'')
		ORDER BY m.Mobitel_ID;
	
	DECLARE CONTINUE HANDLER FOR NOT FOUND SET DataExists = 0;
  
	SET DataExists = 1;
	
	
	DELETE d
	FROM datagpslost d
	WHERE NOT EXISTS(
		SELECT 1
		FROM mobitels m
		WHERE m.Mobitel_ID = d.Mobitel_ID);
  
	
	OPEN CursorMobitels;
	FETCH CursorMobitels INTO MobitelIDInCursor;
	WHILE DataExists = 1 DO
		CALL RfLostDataGPS(MobitelIDInCursor, NeedOptimizeParam);
		SET NeedOptimize = GREATEST(NeedOptimize, NeedOptimizeParam);
		FETCH CursorMobitels INTO MobitelIDInCursor;
	END WHILE;
	CLOSE CursorMobitels;

	
	IF NeedOptimize = 1 THEN
		OPTIMIZE TABLE datagpslost;
	END IF;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `RfListMobitelConfig` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `RfListMobitelConfig`()
    COMMENT 'Выборка RF настроек телетреков'
BEGIN
SELECT
  m.Mobitel_ID AS Mobitel_ID,
  m.Name AS Name,
  m.Descr AS Descr,
  m.ConfirmedID AS ConfirmedID,
  FROM_UNIXTIME(m.LastInsertTime) AS LastInsertTime,
  c.moduleIdRf AS moduleIdRf,
  ( SELECT COALESCE(MAX(d.LogID), 0)
    FROM datagps d
    WHERE d.Mobitel_ID = m.Mobitel_ID
  ) AS LastLogID
FROM mobitels m
  JOIN internalmobitelconfig c ON (c.ID = m.InternalMobitelConfig_ID)
WHERE (c.InternalMobitelConfig_ID = (
  SELECT intConf.InternalMobitelConfig_ID
  FROM internalmobitelconfig intConf
  WHERE intConf.ID = c.ID 
  ORDER BY intConf.InternalMobitelConfig_ID DESC
  LIMIT 1)) AND
  (c.moduleIdRf IS NOT NULL) AND (c.moduleIdRf <> _cp1251'')
ORDER BY m.Mobitel_ID;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `RfLostDataGPS` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `RfLostDataGPS`(IN MobitelID INTEGER(11), OUT NeedOptimize TINYINT)
    COMMENT 'Поиск пропусков в RF данных заданного телетрека и заполнение таб'
BEGIN
	
	DECLARE MAX_RECORD_COUNT INT DEFAULT 33792;
	DECLARE FirstActualLogID INT; 

	DECLARE CurrentConfirmedID INT; 
	DECLARE NewConfirmedID INT DEFAULT 0; 
	DECLARE NewStartLogIDSelect INT DEFAULT 0; 
	DECLARE MaxMobitelLogID INT; 

	DECLARE BeginLogIDInCursor INT; 
	DECLARE EndLogIDInCursor INT; 
	DECLARE CountInLostRange INT; 
	DECLARE DataExists TINYINT DEFAULT 1; 
	DECLARE DataChanged TINYINT DEFAULT 0; 
	DECLARE NeedAnalyze TINYINT DEFAULT 0; 
  
	DECLARE NewRowCount INT DEFAULT 0; 
  
	DECLARE NewLogID INT; 
	DECLARE FirstLogID INT DEFAULT -9999999; 
	DECLARE SecondLogID INT; 
																																									  
  
  
	DECLARE CursorLostData CURSOR FOR
		SELECT Begin_LogID, End_LogID
		FROM datagpslost
		WHERE Mobitel_ID = MobitelID
		ORDER BY Begin_LogID;
    
	
	DECLARE CursorNewLogID CURSOR FOR
		SELECT LogID 
		FROM datagpslost_rftmp;
    
	
	DECLARE CONTINUE HANDLER FOR NOT FOUND SET DataExists = 0;

	SET DataExists = 1;
	SET NeedOptimize = 0;
 
	SELECT COALESCE(ConfirmedID, 0) INTO CurrentConfirmedID
	FROM mobitels
	WHERE Mobitel_ID = MobitelID;

	
	SELECT COALESCE(MAX(LogID), 0) INTO MaxMobitelLogID
	FROM datagps
	WHERE (Mobitel_ID = MobitelID);

	IF CurrentConfirmedID <> MaxMobitelLogID THEN
		
		SET FirstActualLogID = MaxMobitelLogID - MAX_RECORD_COUNT;
		IF FirstActualLogID < 0 THEN
			SET FirstActualLogID = 0;
		END IF;

		
		DELETE FROM datagpslost
		WHERE (Mobitel_ID = MobitelID) AND (Begin_LogID < FirstActualLogID);
		
		
		OPEN CursorLostData;
		FETCH CursorLostData INTO BeginLogIDInCursor, EndLogIDInCursor;
    
		
		IF DataExists = 0 THEN
			SET DataChanged = 0;
			SET NeedAnalyze = 1;
			
			SET NewStartLogIDSelect = GREATEST(CurrentConfirmedID, FirstActualLogID);
		END IF;

		
		WHILE DataExists = 1 DO
			
			SELECT COUNT(1) INTO CountInLostRange
			FROM datagps
			WHERE (Mobitel_ID = MobitelID) AND
				(LogID > BeginLogIDInCursor) AND (LogID < EndLogIDInCursor);

			
			IF (CountInLostRange > 0)  THEN
				
				DELETE FROM datagpslost
				WHERE (Mobitel_ID = MobitelID) AND (Begin_LogID >= BeginLogIDInCursor);

				SET DataChanged = 1;
				SET NeedAnalyze = 1;
				SET NewStartLogIDSelect = BeginLogIDInCursor;
        
				
				SET DataExists = 0;
			ELSE
				FETCH CursorLostData INTO BeginLogIDInCursor, EndLogIDInCursor;
			END IF;	
		END WHILE;
		CLOSE CursorLostData;
   
		
       
		IF (NeedAnalyze = 0) AND (EndLogIDInCursor < MaxMobitelLogID) THEN
			SET NewStartLogIDSelect = EndLogIDInCursor;
			SET NeedAnalyze = 1;
		END IF;
   
		

		IF NeedAnalyze = 1 THEN
			TRUNCATE TABLE datagpslost_rftmp;

			
			INSERT INTO datagpslost_rftmp	(LogID)
			SELECT DISTINCT(LogID)
			FROM datagps
			WHERE (Mobitel_ID = MobitelID) AND (LogID >= NewStartLogIDSelect)
			ORDER BY LogID;
			
			
			SET @InsertLostDataStatement = 
				"INSERT INTO datagpslost(Mobitel_ID, Begin_LogID, End_LogID) VALUES ";
      
			
			SET DataExists = 1;
			OPEN CursorNewLogID;
			FETCH CursorNewLogID INTO NewLogID;
			WHILE DataExists = 1 DO
				IF FirstLogID = -9999999 THEN
				  
				  SET FirstLogID = NewLogID;
				ELSE
					
					SET SecondLogID = NewLogID;
					IF (SecondLogID -	FirstLogID) > 1 THEN
						
						IF NewRowCount > 0 THEN
							SET @InsertLostDataStatement = 
								CONCAT(@InsertLostDataStatement, ",");
						END IF;
						SET @InsertLostDataStatement = 
							CONCAT(@InsertLostDataStatement, 
								" (", MobitelID, ", ", FirstLogID, ", ", SecondLogID, ")");
						
						SET NewRowCount = NewRowCount + 1;
					END IF;
					
					SET	FirstLogID = SecondLogID;
			  END IF;	
				FETCH CursorNewLogID INTO NewLogID;
			END WHILE;
			CLOSE CursorNewLogID;
      
        
			IF NewRowCount > 0 THEN
				
				PREPARE stmt FROM @InsertLostDataStatement;
				EXECUTE stmt;
				DEALLOCATE PREPARE stmt;
        
				SET DataChanged = 1;
			END IF; 
             
			
			
			SELECT COALESCE(MIN(Begin_LogID), -1) INTO NewConfirmedID
			FROM datagpslost
			WHERE Mobitel_ID = MobitelID;

			
			IF NewConfirmedID = -1 THEN
				SET NewConfirmedID = MaxMobitelLogID;
			END IF;

			
			IF NewConfirmedID > CurrentConfirmedID THEN
				UPDATE mobitels
				SET ConfirmedID = NewConfirmedID
				WHERE (Mobitel_ID = MobitelID) AND (ConfirmedID < NewConfirmedID);
			END IF;
      
			TRUNCATE TABLE datagpslost_rftmp;
		END IF;	 
    
		IF DataChanged = 1 THEN
			SET NeedOptimize = 1;
		END IF;
  
	END IF;	
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `RfMobitelConfig` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `RfMobitelConfig`(IN paramMobitelID INTEGER(11))
    COMMENT 'Выборка RF настроек заданного телетрека'
BEGIN
SELECT
  m.Mobitel_ID AS Mobitel_ID,
  m.Name AS Name,
  m.Descr AS Descr,
  m.ConfirmedID AS ConfirmedID,
  c.moduleIdRf AS moduleIdRf,
  FROM_UNIXTIME(m.LastInsertTime) AS LastInsertTime,
  ( SELECT COALESCE(d.LogID, 0)
    FROM datagps d
    WHERE d.Mobitel_ID = m.Mobitel_ID
    ORDER BY d.LogID DESC
    LIMIT 1 ) AS LastLogID
FROM mobitels m
  JOIN internalmobitelconfig c ON (c.ID = m.InternalMobitelConfig_ID)
WHERE (m.Mobitel_ID = paramMobitelID) AND
  (c.InternalMobitelConfig_ID = (
    SELECT intConf.InternalMobitelConfig_ID
    FROM internalmobitelconfig intConf
    WHERE intConf.ID = c.ID
    ORDER BY intConf.InternalMobitelConfig_ID DESC
    LIMIT 1)) AND
  (c.moduleIdRf IS NOT NULL) AND (c.moduleIdRf <> _cp1251'')
ORDER BY m.Mobitel_ID;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `RfTransferBuffer` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `RfTransferBuffer`()
    SQL SECURITY INVOKER
    COMMENT 'Переносит GPS данные из буферной таблицы в datagps.'
BEGIN

  DECLARE MobitelIDInCursor INT; 
  DECLARE DataExists TINYINT DEFAULT 1; 
  DECLARE NeedOptimize TINYINT DEFAULT 0; 
  DECLARE NeedOptimizeParam TINYINT;
  DECLARE TmpMaxUnixTime INT; 

  DECLARE CursorMobitels CURSOR FOR
    SELECT DISTINCT(Mobitel_ID) FROM datagpsbuffer;

  
  DECLARE CONTINUE HANDLER FOR NOT FOUND SET DataExists = 0;
  
    
  
  
  DELETE o
  FROM online o, datagpsbuffer_pop dgb
  WHERE (o.Mobitel_ID = dgb.Mobitel_ID) AND (o.LogID = dgb.LogID);
  
  SET DataExists = 1;
  OPEN CursorMobitels;
  FETCH CursorMobitels INTO MobitelIDInCursor;
  WHILE DataExists = 1 DO
    
    SELECT COALESCE(MAX(UnixTime), 0) INTO TmpMaxUnixTime
    FROM online FORCE INDEX (IDX_Mobitelid)
    WHERE Mobitel_ID = MobitelIDInCursor;

    
    INSERT INTO online (
      Mobitel_ID, LogID, UnixTime, Latitude, Longitude, Altitude,
      Direction, Speed, Valid, `Events`,
      Sensor1, Sensor2, Sensor3, Sensor4, Sensor5, Sensor6, Sensor7, Sensor8,
      Counter1, Counter2, Counter3, Counter4, whatIs)
    SELECT
      Mobitel_ID, LogID, UnixTime, Latitude, Longitude, Altitude,
      Direction, Speed, Valid, `Events`,
      Sensor1, Sensor2, Sensor3, Sensor4, Sensor5, Sensor6, Sensor7, Sensor8,
      Counter1, Counter2, Counter3, Counter4, whatIs
    FROM (
      SELECT * 
      FROM datagpsbuffer
      WHERE (Mobitel_ID = MobitelIDInCursor)  AND 
        (UnixTime > TmpMaxUnixTime) AND (Valid = 1)
      GROUP BY Mobitel_ID, LogID
      ORDER BY UnixTime DESC
      LIMIT 100) AS T
    ORDER BY UnixTime ASC; 

    
    DELETE FROM online
    WHERE (Mobitel_ID = MobitelIDInCursor) AND (UnixTime < 
      (SELECT COALESCE(MIN(UnixTime), 0) 
       FROM (
         SELECT UnixTime
         FROM online
         WHERE Mobitel_ID = MobitelIDInCursor 
         ORDER BY UnixTime DESC
         LIMIT 100) T1)); 
  
    FETCH CursorMobitels INTO MobitelIDInCursor;
  END WHILE;
  CLOSE CursorMobitels;
    


  
  UPDATE datagps d, datagpsbuffer b SET
    d.Message_ID = 0, d.Latitude = b.Latitude,
    d.Longitude = b.Longitude,
    d.Altitude = b.Altitude,
    d.UnixTime = b.UnixTime,
    d.Speed = b.Speed,
    d.Direction = b.Direction,
    d.Valid = b.Valid,
    d.InMobitelID = b.LogID,
    d.`Events` = b.`Events`,
    d.Sensor1 = b.Sensor1,
    d.Sensor2 = b.Sensor2,
    d.Sensor3 = b.Sensor3,
    d.Sensor4 = b.Sensor4,
    d.Sensor5 = b.Sensor5,
    d.Sensor6 = b.Sensor6,
    d.Sensor7 = b.Sensor7,
    d.Sensor8 = b.Sensor8,
    d.isShow = 0,
    d.whatIs = b.whatIs,
    d.Counter1 = b.Counter1,
    d.Counter2 = b.Counter2,
    d.Counter3 = b.Counter3,
    d.Counter4 = b.Counter4
  WHERE (d.Mobitel_ID = b.Mobitel_ID) AND (d.LogID = b.LogID);

  
  DELETE b
  FROM datagps d, datagpsbuffer b
  WHERE (d.Mobitel_ID = b.Mobitel_ID) AND (d.LogID = b.LogID);

  
  INSERT INTO datagps (
    Mobitel_ID, LogID, UnixTime, Latitude, Longitude, Altitude,
    Direction, Speed, Valid, `Events`, InMobitelID,
    Sensor1, Sensor2, Sensor3, Sensor4, Sensor5, Sensor6, Sensor7, Sensor8,
    Counter1, Counter2, Counter3, Counter4, whatIs)
  SELECT
    Mobitel_ID, LogID, UnixTime, Latitude, Longitude, Altitude,
    Direction, Speed, Valid, `Events`, LogID,
    Sensor1, Sensor2, Sensor3, Sensor4, Sensor5, Sensor6, Sensor7, Sensor8,
    Counter1, Counter2, Counter3, Counter4,
    whatIs
  FROM datagpsbuffer
  GROUP BY Mobitel_ID, LogID;

  
  SET DataExists = 1;
  OPEN CursorMobitels;
  FETCH CursorMobitels INTO MobitelIDInCursor;
  WHILE DataExists = 1 DO
    
    UPDATE mobitels SET LastInsertTime = UNIX_TIMESTAMP(NOW())
    WHERE Mobitel_ID = MobitelIDInCursor;
        
    
    CALL RfLostDataGPS(MobitelIDInCursor, NeedOptimizeParam);
    SET NeedOptimize = GREATEST(NeedOptimize, NeedOptimizeParam);
    
    FETCH CursorMobitels INTO MobitelIDInCursor;
  END WHILE;
  CLOSE CursorMobitels;

  
  TRUNCATE TABLE datagpsbuffer;

  
  IF NeedOptimize = 1 THEN
    OPTIMIZE TABLE datagpslost;
  END IF;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `SelectDataGpsPeriodAll` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `SelectDataGpsPeriodAll`(IN mobile int, IN beginperiod datetime, IN endperiod datetime,

IN timebegin varchar(9), IN timeend varchar(9), IN weekdays varchar(15), IN daymonth varchar(90))
BEGIN

  DECLARE time0 time DEFAULT '23:59:59';

  DECLARE time1 time DEFAULT '00:00:00'; 



  DROP TEMPORARY TABLE IF EXISTS tempperiod4;



  CREATE TEMPORARY TABLE tempperiod4 -- временная таблица выборок в указанном диапазоне

  SELECT

    DataGps_ID AS DataGps_ID,

    Mobitel_ID AS Mobitel_ID,

    ((Latitude * 1.0000) / 600000) AS Lat,

    ((Longitude * 1.0000) / 600000) AS Lon,

    Altitude AS Altitude,

    FROM_UNIXTIME(UnixTime) AS `time`,

    (Speed * 1.852) AS speed,

    Valid AS Valid,

    (Sensor8 + (Sensor7 << 8) + (Sensor6 << 16) + (Sensor5 << 24) + (Sensor4 << 32) + (Sensor3 << 40) + (Sensor2 << 48) + (Sensor1 << 56)) AS sensor,

    Events AS Events,

    LogID AS LogID

  FROM datagps

  WHERE Mobitel_ID = mobile AND

  (UnixTime BETWEEN UNIX_TIMESTAMP(beginperiod) AND UNIX_TIMESTAMP(endperiod)) AND

  (Valid = 1) AND NOT (Latitude = 0 AND Longitude = 0)

  ORDER BY UnixTime;



  DROP TEMPORARY TABLE IF EXISTS tempweeks;



  IF weekdays != '' THEN



    CREATE TEMPORARY TABLE tempweeks (

      shead varchar(2)

    );



    SET @saTail = weekdays;

    WHILE @saTail != '' DO

      SET @sHead = SUBSTRING_INDEX(@saTail, ';', 1);

      SET @saTail = SUBSTRING(@saTail, LENGTH(@sHead) + 2);

      INSERT INTO tempweeks (shead)

        VALUES (@sHead);

    END WHILE;

  END IF;



  DROP TEMPORARY TABLE IF EXISTS tempday0;



  IF daymonth != '' THEN



    CREATE TEMPORARY TABLE tempday0 (

      shead varchar(2)

    );



    SET @saTail = daymonth;

    WHILE @saTail != '' DO

      SET @sHead = SUBSTRING_INDEX(@saTail, ';', 1);

      SET @saTail = SUBSTRING(@saTail, LENGTH(@sHead) + 2);

      INSERT INTO tempday0 (shead)

        VALUES (@sHead);

    END WHILE;

  END IF;



  -- getting selecting data

  IF (daymonth != '') AND (weekdays != '') THEN

    IF TIME(timebegin) < TIME(timeend) then

    SELECT

      *

    FROM tempperiod4

    WHERE ((DAY(`time`) IN (SELECT

      *

    FROM tempday0)) AND -- чтение по дням месяца

    (WEEKDAY(`time`) IN (SELECT

      *

    FROM tempweeks)) AND -- чтение по дням недели

    (TIME(`time`) BETWEEN TIME(timebegin) AND TIME(timeend))); -- чтение дат

    END IF;



    IF TIME(timebegin) > TIME(timeend) then

    SELECT

      *

    FROM tempperiod4

    WHERE ((DAY(`time`) IN (SELECT

      *

    FROM tempday0)) AND -- чтение по дням месяца

    (WEEKDAY(`time`) IN (SELECT

      *

    FROM tempweeks)) AND -- чтение по дням недели

    ((time(`time`) > time(timebegin) and time(`time`) < time(time0))

    OR (time(`time`) > time(time1) AND time(`time`) < time(timeend)))); -- чтение дат

    END IF;

    END IF;



      IF (daymonth = '') AND (weekdays != '') THEN

        IF TIME(timebegin) < TIME(timeend) then

        SELECT

          *

        FROM tempperiod4

        WHERE ((WEEKDAY(`time`) IN (SELECT

          *

        FROM tempweeks)) AND -- чтение по дням недели

        (TIME(`time`) BETWEEN TIME(timebegin) AND TIME(timeend))); -- чтение дат

          end IF;



        IF TIME(timebegin) > TIME(timeend) then

        SELECT

          *

        FROM tempperiod4

        WHERE ((WEEKDAY(`time`) IN (SELECT

          *

        FROM tempweeks)) AND -- чтение по дням недели

        ((time(`time`) > time(timebegin) and time(`time`) < time(time0))

    OR (time(`time`) > time(time1) AND time(`time`) < time(timeend)))); -- чтение дат

          end IF;

        END IF;



          IF (daymonth != '') AND (weekdays = '') THEN

            IF TIME(timebegin) < TIME(timeend) then

            SELECT

              *

            FROM tempperiod4

            WHERE ((DAY(`time`) IN (SELECT

              *

            FROM tempday0)) AND -- чтение по дням месяца

            (TIME(`time`) BETWEEN TIME(timebegin) AND TIME(timeend))); -- чтение дат

              END IF;



            IF TIME(timebegin) > TIME(timeend) then

            SELECT

              *

            FROM tempperiod4

            WHERE ((DAY(`time`) IN (SELECT

              *

            FROM tempday0)) AND -- чтение по дням месяца

            ((time(`time`) > time(timebegin) and time(`time`) < time(time0))

              OR (time(`time`) > time(time1) AND time(`time`) < time(timeend)))); -- чтение дат

              END IF;

            END IF;



              IF (daymonth = '') AND (weekdays = '') THEN

                IF TIME(timebegin) < TIME(timeend) then

                SELECT

                  *

                FROM tempperiod4

                WHERE (TIME(`time`) BETWEEN TIME(timebegin) AND TIME(timeend)); -- чтение дат

                  end IF;



                IF TIME(timebegin) > TIME(timeend) then

                SELECT

                  *

                FROM tempperiod4

                WHERE ((time(`time`) > time(timebegin) and time(`time`) < time(time0))

                  OR (time(`time`) > time(time1) AND time(`time`) < time(timeend))); -- чтение дат

                  end IF;

              END IF;

            END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `SelectDataGpsPeriodMonth` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `SelectDataGpsPeriodMonth`(IN mobile int, IN beginperiod datetime, IN endperiod datetime,

IN daymonth varchar(82))
body:

BEGIN

  DROP TEMPORARY TABLE IF EXISTS tempperiod2;



  CREATE TEMPORARY TABLE tempperiod2 
  SELECT

    DataGps_ID AS DataGps_ID,

    Mobitel_ID AS Mobitel_ID,

    ((Latitude * 1.0000) / 600000) AS Lat,

    ((Longitude * 1.0000) / 600000) AS Lon,

    Altitude AS Altitude,

    FROM_UNIXTIME(UnixTime) AS `time`,

    (Speed * 1.852) AS speed,

    Valid AS Valid,

    (Sensor8 + (Sensor7 << 8) + (Sensor6 << 16) + (Sensor5 << 24) + (Sensor4 << 32) + (Sensor3 << 40) + (Sensor2 << 48) + (Sensor1 << 56)) AS sensor,

    Events AS Events,

    LogID AS LogID

  FROM datagps

  WHERE Mobitel_ID = mobile AND

  (UnixTime BETWEEN UNIX_TIMESTAMP(beginperiod) AND UNIX_TIMESTAMP(endperiod)) AND

  (Valid = 1) AND NOT (Latitude = 0 AND Longitude = 0)

  ORDER BY UnixTime;



  IF daymonth = '' THEN

    LEAVE body;

  END IF;



  DROP TEMPORARY TABLE IF EXISTS tempdays;



  CREATE TEMPORARY TABLE tempdays (

    shead varchar(2)

  );



  SET @saTail = daymonth;

  WHILE @saTail != '' DO

    SET @sHead = SUBSTRING_INDEX(@saTail, ';', 1);

    SET @saTail = SUBSTRING(@saTail, LENGTH(@sHead) + 2);

    INSERT INTO tempdays (shead)

      VALUES (@sHead);

  END WHILE;

  SELECT

    *

  FROM tempperiod2

  WHERE DAY(`time`) IN (SELECT

    *

  FROM tempdays);

  END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `SelectDataGpsPeriodTime` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `SelectDataGpsPeriodTime`(IN mobile int, IN beginperiod datetime, IN endperiod datetime,

IN timebegin varchar(9), IN timeend varchar(9))
BEGIN

  DROP TEMPORARY TABLE IF EXISTS tempperiod1;



  CREATE TEMPORARY TABLE tempperiod1 
  SELECT

    DataGps_ID AS DataGps_ID,

    Mobitel_ID AS Mobitel_ID,

    ((Latitude * 1.0000) / 600000) AS Lat,

    ((Longitude * 1.0000) / 600000) AS Lon,

    Altitude AS Altitude,

    FROM_UNIXTIME(UnixTime) AS `time`,

    (Speed * 1.852) AS speed,

    Valid AS Valid,

    (Sensor8 + (Sensor7 << 8) + (Sensor6 << 16) + (Sensor5 << 24) + (Sensor4 << 32) + (Sensor3 << 40) + (Sensor2 << 48) + (Sensor1 << 56)) AS sensor,

    Events AS Events,

    LogID AS LogID

  FROM datagps

  WHERE Mobitel_ID = mobile AND

  (UnixTime BETWEEN UNIX_TIMESTAMP(beginperiod) AND UNIX_TIMESTAMP(endperiod)) AND

  (Valid = 1) AND NOT (Latitude = 0 AND Longitude = 0)

  ORDER BY UnixTime;



  SELECT

    *

  FROM tempperiod1

  WHERE TIME(`time`) BETWEEN TIME(timebegin) AND TIME(timeend);



END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `SelectDataGpsPeriodWeek` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `SelectDataGpsPeriodWeek`(IN mobile int, IN beginperiod datetime, IN endperiod datetime,

IN weekdays varchar(15))
body:

BEGIN

  DROP TEMPORARY TABLE IF EXISTS tempperiod3;



  CREATE TEMPORARY TABLE tempperiod3 
  SELECT

    DataGps_ID AS DataGps_ID,

    Mobitel_ID AS Mobitel_ID,

    ((Latitude * 1.0000) / 600000) AS Lat,

    ((Longitude * 1.0000) / 600000) AS Lon,

    Altitude AS Altitude,

    FROM_UNIXTIME(UnixTime) AS `time`,

    (Speed * 1.852) AS speed,

    Valid AS Valid,

    (Sensor8 + (Sensor7 << 8) + (Sensor6 << 16) + (Sensor5 << 24) + (Sensor4 << 32) + (Sensor3 << 40) + (Sensor2 << 48) + (Sensor1 << 56)) AS sensor,

    Events AS Events,

    LogID AS LogID

  FROM datagps

  WHERE Mobitel_ID = mobile AND

  (UnixTime BETWEEN UNIX_TIMESTAMP(beginperiod) AND UNIX_TIMESTAMP(endperiod)) AND

  (Valid = 1) AND NOT (Latitude = 0 AND Longitude = 0)

  ORDER BY UnixTime;



  IF weekdays = '' THEN

    LEAVE body;

  END IF;



  DROP TEMPORARY TABLE IF EXISTS tempweek;



  CREATE TEMPORARY TABLE tempweek (

    shead varchar(2)

  );



  SET @saTail = weekdays;

  WHILE @saTail != '' DO

    SET @sHead = SUBSTRING_INDEX(@saTail, ';', 1);

    SET @saTail = SUBSTRING(@saTail, LENGTH(@sHead) + 2);

    INSERT INTO tempweek (shead)

      VALUES (@sHead);

  END WHILE;



  SELECT

    *

  FROM tempperiod3

  WHERE WEEKDAY(`time`) IN (SELECT

    *

  FROM tempweek);



  END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `TestP` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `TestP`()
BEGIN
  SELECT VERSION();
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `TransferBuffer` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `TransferBuffer`()
    SQL SECURITY INVOKER
    COMMENT 'Переносит GPS данные из буферной таблицы в datagps.'
BEGIN





CREATE TEMPORARY TABLE IF NOT EXISTS temp1 ENGINE=HEAP(
  SELECT DataGPS_ID FROM datagpsbuffer
  );



UPDATE datagps d, datagpsbuffer b, temp1 t SET
  d.Message_ID = 0, 
  d.Latitude = b.Latitude,
  d.Longitude = b.Longitude,
  d.Altitude = b.Altitude,
  d.UnixTime = b.UnixTime,
  d.Speed = b.Speed,
  d.Direction = b.Direction,
  d.Valid = b.Valid,
  d.InMobitelID = NULL, 
  d.`Events` = b.`Events`,
  d.Sensor1 = b.Sensor1,
  d.Sensor2 = b.Sensor2,
  d.Sensor3 = b.Sensor3,
  d.Sensor4 = b.Sensor4,
  d.Sensor5 = b.Sensor5,
  d.Sensor6 = b.Sensor6,
  d.Sensor7 = b.Sensor7,
  d.Sensor8 = b.Sensor8,
  d.isShow = 0, 
  d.whatIs = b.whatIs,
  d.Counter1 = b.Counter1,
  d.Counter2 = b.Counter2,
  d.Counter3 = b.Counter3,
  d.Counter4 = b.Counter4
WHERE b.DataGps_ID = t.DataGps_ID
  AND d.Mobitel_ID = b.Mobitel_ID
  AND d.LogID = b.LogID;


DELETE b
FROM datagps d, datagpsbuffer b, temp1 t
WHERE b.DataGps_ID = t.DataGps_ID
  AND d.Mobitel_ID = b.Mobitel_ID
  AND d.LogID = b.LogID;


INSERT INTO datagps
  (
  Mobitel_ID,
  LogID,
  UnixTime,
  Latitude,
	Longitude,
  Altitude,
  Direction,
  Speed,
  Valid,
  `Events`,
	Sensor1,
	Sensor2,
	Sensor3,
	Sensor4,
	Sensor5,
	Sensor6,
	Sensor7,
	Sensor8,
  Counter1,
  Counter2,
  Counter3,
  Counter4,
  whatIs
  )
SELECT
  b.Mobitel_ID,
  b.LogID,
  b.UnixTime,
  b.Latitude,
	b.Longitude,
  b.Altitude,
  b.Direction,
  b.Speed,
  b.Valid,
  b.`Events`,
	b.Sensor1,
	b.Sensor2,
	b.Sensor3,
	b.Sensor4,
	b.Sensor5,
	b.Sensor6,
	b.Sensor7,
	b.Sensor8,
  b.Counter1,
  b.Counter2,
  b.Counter3,
  b.Counter4,
  b.whatIs
FROM datagpsbuffer b, temp1 t
WHERE b.DataGps_ID = t.DataGps_ID
GROUP BY b.Mobitel_ID, b.LogID;


DELETE b
FROM datagpsbuffer b, temp1 t
WHERE b.DataGps_ID = t.DataGps_ID;


DROP TEMPORARY TABLE temp1;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `TransferLiteBuffer` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `TransferLiteBuffer`()
    SQL SECURITY INVOKER
    COMMENT 'Переносит GPS данные из буферной таблицы в datagps.'
BEGIN





CREATE TEMPORARY TABLE IF NOT EXISTS temp2 ENGINE=HEAP(
  SELECT DataGPS_ID FROM datagpsbufferlite
  );



UPDATE datagps d, datagpsbuffer b, temp2 t SET
  d.Message_ID = b.Message_ID,
  d.Latitude = b.Latitude,
  d.Longitude = b.Longitude,
  d.Altitude = b.Altitude,
  d.UnixTime = b.UnixTime,
  d.Speed = b.Speed,
  d.Direction = b.Direction,
  d.Valid = b.Valid,
  d.InMobitelID = NULL, 
  d.`Events` = b.`Events`,
  d.Sensor1 = b.Sensor1,
  d.Sensor2 = b.Sensor2,
  d.Sensor3 = b.Sensor3,
  d.Sensor4 = b.Sensor4,
  d.Sensor5 = b.Sensor5,
  d.Sensor6 = b.Sensor6,
  d.Sensor7 = b.Sensor7,
  d.Sensor8 = b.Sensor8,
  d.isShow = b.IsShow,
  d.whatIs = b.whatIs,
  d.Counter1 = b.Counter1,
  d.Counter2 = b.Counter2,
  d.Counter3 = b.Counter3,
  d.Counter4 = b.Counter4
WHERE b.DataGps_ID = t.DataGps_ID
  AND d.Mobitel_ID = b.Mobitel_ID
  AND d.Latitude = b.Latitude
  AND d.Longitude = b.Longitude
  AND d.Altitude = b.Altitude
  AND d.UnixTime = b.UnixTime;


DELETE b
FROM datagps d, datagpsbufferlite b, temp2 t
WHERE b.DataGps_ID = t.DataGps_ID
  AND d.Mobitel_ID = b.Mobitel_ID
  AND d.Latitude = b.Latitude
  AND d.Longitude = b.Longitude
  AND d.Altitude = b.Altitude
  AND d.UnixTime = b.UnixTime;


INSERT INTO datagps
  (
  Mobitel_ID,
  LogID,
  UnixTime,
  Latitude,
  Longitude,
  Altitude,
  Direction,
  Speed,
  Valid,
  `Events`,
  Sensor1,
  Sensor2,
  Sensor3,
  Sensor4,
  Sensor5,
  Sensor6,
  Sensor7,
  Sensor8,
  Counter1,
  Counter2,
  Counter3,
  Counter4,
  whatIs
  )
SELECT
  b.Mobitel_ID,
  b.LogID,
  b.UnixTime,
  b.Latitude,
	b.Longitude,
  b.Altitude,
  b.Direction,
  b.Speed,
  b.Valid,
  b.`Events`,
  b.Sensor1,
  b.Sensor2,
  b.Sensor3,
  b.Sensor4,
  b.Sensor5,
  b.Sensor6,
  b.Sensor7,
  b.Sensor8,
  b.Counter1,
  b.Counter2,
  b.Counter3,
  b.Counter4,
  b.whatIs
FROM datagpsbufferlite b, temp2 t
WHERE b.DataGps_ID = t.DataGps_ID
GROUP BY b.Mobitel_ID, b.LogID, b.Latitude, b.Longitude, b.Altitude, b.UnixTime;


DELETE b
FROM datagpsbufferlite b, temp2 t
WHERE b.DataGps_ID = t.DataGps_ID;


DROP TEMPORARY TABLE temp2;
END ;;
DELIMITER ;

--
-- Final view structure for view `datavalue1`
--

/*!50001 DROP VIEW IF EXISTS `datavalue1`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `datavalue1` AS select round((`datagps`.`Longitude` / 600000),6) AS `lon`,round((`datagps`.`Latitude` / 600000),6) AS `lat`,`datagps`.`Mobitel_ID` AS `Mobitel_ID`,`sensordata`.`Value` AS `Value`,(`datagps`.`Speed` * 1.852) AS `speed`,from_unixtime(`datagps`.`UnixTime`) AS `time`,`sensordata`.`sensor_id` AS `sensor_id`,`datagps`.`DataGps_ID` AS `datavalue_id` from (`sensordata` join `datagps` on((`sensordata`.`datagps_id` = `datagps`.`DataGps_ID`))) where (`datagps`.`Valid` = 1) order by `datagps`.`UnixTime`,`datagps`.`Mobitel_ID`,`sensordata`.`sensor_id` */;

--
-- Final view structure for view `dataview`
--

/*!50001 DROP VIEW IF EXISTS `dataview`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `dataview` AS select `datagps`.`DataGps_ID` AS `DataGps_ID`,`datagps`.`Mobitel_ID` AS `Mobitel_ID`,(`datagps`.`Latitude` / 600000.00000) AS `Lat`,(`datagps`.`Longitude` / 600000.00000) AS `Lon`,`datagps`.`Altitude` AS `Altitude`,from_unixtime(`datagps`.`UnixTime`) AS `time`,(`datagps`.`Speed` * 1.852) AS `speed`,((`datagps`.`Direction` * 360) / 255) AS `direction`,`datagps`.`Valid` AS `Valid`,(((((((`datagps`.`Sensor8` + (`datagps`.`Sensor7` << 8)) + (`datagps`.`Sensor6` << 16)) + (`datagps`.`Sensor5` << 24)) + (`datagps`.`Sensor4` << 32)) + (`datagps`.`Sensor3` << 40)) + (`datagps`.`Sensor2` << 48)) + (`datagps`.`Sensor1` << 56)) AS `sensor`,`datagps`.`Events` AS `Events`,`datagps`.`LogID` AS `LogID` from `datagps` order by `datagps`.`LogID` */;

--
-- Final view structure for view `deviceview`
--

/*!50001 DROP VIEW IF EXISTS `deviceview`*/;
/*!50001 CREATE ALGORITHM=MERGE */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `deviceview` AS (select `m`.`Mobitel_ID` AS `Mobitel_ID`,`m`.`Name` AS `Name`,`m`.`Descr` AS `Descr`,`c`.`devIdShort` AS `devIdShort`,`m`.`DeviceType` AS `DeviceType`,`m`.`ConfirmedID` AS `ConfirmedID`,`c`.`moduleIdRf` AS `moduleIdRf` from ((`mobitels` `m` join `internalmobitelconfig` `c`) join `internalmobitelconfigview` `v`) where ((`v`.`ID` = `m`.`InternalMobitelConfig_ID`) and (`v`.`LastRecord` = `c`.`InternalMobitelConfig_ID`)) order by `m`.`Name`) */;

--
-- Final view structure for view `internalmobitelconfigview`
--

/*!50001 DROP VIEW IF EXISTS `internalmobitelconfigview`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `internalmobitelconfigview` AS (select `c`.`ID` AS `ID`,max(`c`.`InternalMobitelConfig_ID`) AS `LastRecord` from `internalmobitelconfig` `c` where (`c`.`devIdShort` <> _cp1251'') group by `c`.`ID`) */;


